Fix evohome so it doesn't retrieve schedules unnecessarily (#118478)

This commit is contained in:
David Bonnes 2024-05-30 18:23:58 +01:00 committed by GitHub
parent f1465baada
commit a3fcd6b32f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,7 +7,7 @@ others.
from __future__ import annotations from __future__ import annotations
from collections.abc import Awaitable from collections.abc import Awaitable
from datetime import datetime, timedelta from datetime import datetime, timedelta, timezone
from http import HTTPStatus from http import HTTPStatus
import logging import logging
import re import re
@ -452,7 +452,7 @@ class EvoBroker:
self.config = client.installation_info[loc_idx][GWS][0][TCS][0] self.config = client.installation_info[loc_idx][GWS][0][TCS][0]
self.tcs: evo.ControlSystem = self._location._gateways[0]._control_systems[0] # noqa: SLF001 self.tcs: evo.ControlSystem = self._location._gateways[0]._control_systems[0] # noqa: SLF001
self.tcs_utc_offset = timedelta(minutes=self._location.timeZone[UTC_OFFSET]) self.loc_utc_offset = timedelta(minutes=self._location.timeZone[UTC_OFFSET])
self.temps: dict[str, float | None] = {} self.temps: dict[str, float | None] = {}
async def save_auth_tokens(self) -> None: async def save_auth_tokens(self) -> None:
@ -688,7 +688,8 @@ class EvoChild(EvoDevice):
if not (schedule := self._schedule.get("DailySchedules")): if not (schedule := self._schedule.get("DailySchedules")):
return {} # no scheduled setpoints when {'DailySchedules': []} return {} # no scheduled setpoints when {'DailySchedules': []}
day_time = dt_util.now() # get dt in the same TZ as the TCS location, so we can compare schedule times
day_time = dt_util.now().astimezone(timezone(self._evo_broker.loc_utc_offset))
day_of_week = day_time.weekday() # for evohome, 0 is Monday day_of_week = day_time.weekday() # for evohome, 0 is Monday
time_of_day = day_time.strftime("%H:%M:%S") time_of_day = day_time.strftime("%H:%M:%S")
@ -702,7 +703,7 @@ class EvoChild(EvoDevice):
else: else:
break break
# Did the current SP start yesterday? Does the next start SP tomorrow? # Did this setpoint start yesterday? Does the next setpoint start tomorrow?
this_sp_day = -1 if sp_idx == -1 else 0 this_sp_day = -1 if sp_idx == -1 else 0
next_sp_day = 1 if sp_idx + 1 == len(day["Switchpoints"]) else 0 next_sp_day = 1 if sp_idx + 1 == len(day["Switchpoints"]) else 0
@ -719,7 +720,7 @@ class EvoChild(EvoDevice):
) )
assert switchpoint_time_of_day is not None # mypy check assert switchpoint_time_of_day is not None # mypy check
dt_aware = _dt_evo_to_aware( dt_aware = _dt_evo_to_aware(
switchpoint_time_of_day, self._evo_broker.tcs_utc_offset switchpoint_time_of_day, self._evo_broker.loc_utc_offset
) )
self._setpoints[f"{key}_sp_from"] = dt_aware.isoformat() self._setpoints[f"{key}_sp_from"] = dt_aware.isoformat()