From d0e4a3cda38f23a0947294ba2630f7a38d68fc8d Mon Sep 17 00:00:00 2001 From: magnuselden Date: Thu, 12 Sep 2024 21:12:54 +0200 Subject: [PATCH] misc --- .../service/hvac/offset/offset_coordinator.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/custom_components/peaqhvac/service/hvac/offset/offset_coordinator.py b/custom_components/peaqhvac/service/hvac/offset/offset_coordinator.py index d31f876..5ba24e2 100644 --- a/custom_components/peaqhvac/service/hvac/offset/offset_coordinator.py +++ b/custom_components/peaqhvac/service/hvac/offset/offset_coordinator.py @@ -47,8 +47,21 @@ def min_price(self) -> float: @property def current_offset(self) -> int: - self._set_offset() - return self.model.raw_offsets[0].get(datetime.now().hour, 0) + ret = 0 + try: + # self._set_offset() + if len(self.model.raw_offsets): + latest_key = max((key for key in self.model.raw_offsets if key <= datetime.now()), default=None) + if latest_key is not None: + ret = self.model.raw_offsets[latest_key] + else: + ret = 0 + except KeyError as e: + _LOGGER.error( + f"Unable to get current offset: {e}. raw_offsets: {self.model.raw_offsets}" + ) + finally: + return ret #self.model.current_offset_dict_combined = ret.calculated_offsets