Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions tibber/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,12 @@ def rt_unsubscribe(self) -> None:
@property
def rt_subscription_running(self) -> bool:
"""Is real time subscription running."""
if not self._tibber_control.realtime.subscription_running:
return False
return not self._last_rt_data_received < dt.datetime.now(tz=dt.UTC) - dt.timedelta(seconds=60)
return self._tibber_control.realtime.subscription_running

@property
def rt_data_stale(self) -> bool:
"""Is real time data stale."""
return self._last_rt_data_received < dt.datetime.now(tz=dt.UTC) - dt.timedelta(seconds=60)

async def get_historic_data(
self,
Expand Down
26 changes: 3 additions & 23 deletions tibber/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ async def _watchdog(self) -> None:
assert isinstance(self.sub_manager.transport, TibberWebsocketsTransport)

await asyncio.sleep(60)

_retry_count = 0
next_test_all_homes_running = dt.datetime.now(tz=dt.UTC)
while self._watchdog_running:
await asyncio.sleep(5)
if (
Expand All @@ -122,28 +120,10 @@ async def _watchdog(self) -> None:
> dt.datetime.now(
tz=dt.UTC,
)
and dt.datetime.now(tz=dt.UTC) > next_test_all_homes_running
):
is_running = True
for home in self._homes:
_LOGGER.debug(
"Watchdog: Checking if home %s is alive, %s, %s",
home.home_id,
home.has_real_time_consumption,
home.rt_subscription_running,
)
if not home.rt_subscription_running:
is_running = False
next_test_all_homes_running = dt.datetime.now(tz=dt.UTC) + dt.timedelta(seconds=60)
break
_LOGGER.debug(
"Watchdog: Home %s is alive",
home.home_id,
)
if is_running:
_retry_count = 0
_LOGGER.debug("Watchdog: Connection is alive")
continue
_retry_count = 0
_LOGGER.debug("Watchdog: Connection is alive")
continue

self.sub_manager.transport.reconnect_at = dt.datetime.now(tz=dt.UTC) + dt.timedelta(seconds=self._timeout)
_LOGGER.error(
Expand Down