sehaas / ha_hisense_tv

Hisense TV integration for Home Assistant
MIT License
101 stars 22 forks source link

Media Player takes a long time to detect off state #41

Closed TwoWheelDev closed 1 year ago

TwoWheelDev commented 1 year ago

I've noticed that it takes a number of minutes for the integration to detect the off state.

Looking at media player, I can see that it does subscribe to /remoteapp/mobile/broadcast/platform_service/actions/tvsleep and is processed by _message_received_turnoff at https://github.com/sehaas/ha_hisense_tv/blob/main/custom_components/hisense_tv/media_player.py#L403

Monitoring on the MQTT broker, it seems there is a significant delay in this above message being received. The TV however does seem to post the sleep state in /remoteapp/mobile/broadcast/ui_service/state. This is what I receive when the TV is off:

{
    "statetype":    "fake_sleep_0",
    "name": "",
    "totaltime":    0,
    "curtime":  0,
    "starttime":    0,
    "playstate":    "",
    "mediatype":    "",
    "resolving":    ""
}

This state is visible instantly. I have had a look at the processing of that state, but haven't been able to fully test making a change to the code there at this point.

If I get chance, I will try and test some changes. But open to suggestions!

sehaas commented 1 year ago

It sounds like a good idea to listen to more topics as different TV models tend to behave differently. Mine does not send the an update to /remoteapp/mobile/broadcast/ui_service/state but sends to /remoteapp/mobile/broadcast/platform_service/actions/tvsleep immediately during turn-off.

TwoWheelDev commented 1 year ago

I have added a PR for this issue. Currently this only affects the media_player component.

I looked at the switch, to try and implement similar but not sure how the switch handles state updates. Out of interest, what is the use of the switch? It seems this duplicates the functionality of the media_player?