openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.58k forks source link

[Chromecast] Channels for appName and appId are not steady OH3.0 #9397

Closed M1cN closed 1 year ago

M1cN commented 3 years ago

Expected Behavior

The binding in Openhab 3.0 should provide the currently running App and AppID in each channel. In Openhab 2 it works perfectly.

Current Behavior in Openhab 3

Currently, it is showing the name and instantly changes it back to AndroidNativeApp.

2020-12-16 11:41:30.503 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from AndroidNativeApp to Emby

2020-12-16 11:41:30.504 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from Emby to AndroidNativeApp

2020-12-16 11:41:40.596 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from AndroidNativeApp to Emby

2020-12-16 11:41:40.596 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from Emby to AndroidNativeApp

2020-12-16 11:41:50.166 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from AndroidNativeApp to Emby

2020-12-16 11:41:50.166 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from Emby to AndroidNativeApp

2020-12-16 11:41:50.728 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from AndroidNativeApp to Emby

2020-12-16 11:41:50.728 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from Emby to AndroidNativeApp

2020-12-16 11:41:57.969 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from AndroidNativeApp to UNDEF

2020-12-16 11:42:11.171 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from UNDEF to Disney+

2020-12-16 11:42:11.171 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from Disney+ to AndroidNativeApp

2020-12-16 11:42:20.913 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from AndroidNativeApp to Disney+

2020-12-16 11:42:20.913 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from Disney+ to AndroidNativeApp

2020-12-16 11:42:31.007 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from AndroidNativeApp to Disney+

2020-12-16 11:42:31.007 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from Disney+ to AndroidNativeApp

2020-12-16 11:42:41.097 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from AndroidNativeApp to Disney+

2020-12-16 11:42:41.098 [INFO ] [marthome.event.ItemStateChangedEvent] - Item '2F_Slaapkamer_Shield_App' changed from Disney+ to AndroidNativeApp

Possible Solution

Don't know I'm a user not a developer, I hope you guys can think of a solution.

Steps to Reproduce (for Bugs)

Start a video on a Chromecast device on Openhab3.0

Your Environment

Hardware: i7 with 64GB Ubuntu 20.04 x64 Running Docker(migrating from OH2 to OH3): Old prod: OH Version 2.5.10 Binding version: 2.5.10 New prod: OH Version 3.0.0 Build 2050 Binding version: 3.0.0.SNAPSHOT (I'm only running one instance of Chromecast at the same time)

lsiepel commented 1 year ago

@webnar Late response, but I just installed the binding and started an app. Did not see the behavior you described with openHAB 3.4.0. Can you confirm this is still an issue? If this is still an issue, can you let me know the model and firmware version of your Chromecast?

lsiepel commented 1 year ago

Played around with the binding the last days, also to solve some other issues. And have seen the behavior you described. The main cause seems to be that not every app uses the same framework/lib / SDK version. And/or not every app respects the API-specification.

The binding is receiving events from the chromecast device and reports them to the openHAB event bus. For example starting the Disney app; three events are received bij the binding. So the cycle is: UNDEF to Disney+ to AndroidNativeApp to Disney+.

I don't give up yet, but not sure if this is fixable.

Edit: I can confirm when starting an app, 2 events are received. Some times the first has a null value for running application, some times it has an intermediate value (like AndroidNativeApp) depending on the app started. I don't see a way of reliable determining if the event is an intermediate one. When closing the app, i can only see 1 event just as how it should be.

lsiepel commented 1 year ago

As the binding reflects the behavior from the depending library / API and there doesn't seem to be a reliable workaround. I think we can only close this issue as not fixable.

Possible workaround for some use cases, outside of the binding: If you start an apllication you can see the transition in event log, if you create rules you can filter out the intermediate states. Or even better, only trigger the rule when the app changes from intermedita to final. In case of @webnar example:

rule "Start scene when app started"
when
    Item 2F_Slaapkamer_Shield_App changed to "Disney+"
or Item 2F_Slaapkamer_Shield_App changed to "Emby"
then
    // do work
end

Please re-open if there is more to add or if someone has a better workaround.