From b6cb123c4fb5bd36c318cef06efdc63e6d1077a3 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Fri, 28 May 2021 13:32:26 +0200 Subject: [PATCH] Only run philips_js notify service while TV is turned on (#51196) Co-authored-by: Martin Hjelmare Co-authored-by: Franck Nijhof --- .../components/philips_js/__init__.py | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/philips_js/__init__.py b/homeassistant/components/philips_js/__init__.py index ffa2109a6e5..b4e086ef391 100644 --- a/homeassistant/components/philips_js/__init__.py +++ b/homeassistant/components/philips_js/__init__.py @@ -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