Only run philips_js notify service while TV is turned on (#51196)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Joakim Plate 2021-05-28 13:32:26 +02:00 committed by GitHub
parent 00507539c1
commit b6cb123c4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -116,8 +116,21 @@ class PhilipsTVDataUpdateCoordinator(DataUpdateCoordinator[None]):
),
)
@property
def _notify_wanted(self):
"""Return if the notify feature should be active.
We only run it when TV is considered fully on. When powerstate is in standby, the TV
will go in low power states and seemingly break the http server in odd ways.
"""
return (
self.api.on
and self.api.powerstate == "On"
and self.api.notify_change_supported
)
async def _notify_task(self):
while self.api.on and self.api.notify_change_supported:
while self._notify_wanted:
res = await self.api.notifyChange(130)
if res:
self.async_set_updated_data(None)
@ -133,11 +146,10 @@ class PhilipsTVDataUpdateCoordinator(DataUpdateCoordinator[None]):
@callback
def _async_notify_schedule(self):
if (
(self._notify_future is None or self._notify_future.done())
and self.api.on
and self.api.notify_change_supported
):
if self._notify_future and not self._notify_future.done():
return
if self._notify_wanted:
self._notify_future = asyncio.create_task(self._notify_task())
@callback