Skip to content

Commit

Permalink
Merge pull request #298 from Gifford47/main
Browse files Browse the repository at this point in the history
fixed EVU_DAYS Attribute to bet set correctly [ref #249]
  • Loading branch information
BenPru authored Jan 7, 2025
2 parents 88665cd + 70aa499 commit a6ad7c0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions custom_components/luxtronik/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,17 @@ def _handle_coordinator_update(
super()._handle_coordinator_update(data)
time_now = time(datetime.now().hour, datetime.now().minute)
evu = LuxOperationMode.evu.value
weekday = datetime.today().weekday()
if not isinstance(self._attr_cache[SA.EVU_DAYS], list):
weekday = datetime.today().weekday()
if isinstance(self._attr_cache[SA.EVU_DAYS], str):
self._attr_cache[SA.EVU_DAYS] = self._attr_cache[SA.EVU_DAYS].split(',')
elif not isinstance(self._attr_cache[SA.EVU_DAYS], list):
self._attr_cache[SA.EVU_DAYS] = list()
if self._attr_native_value is None or self._last_state is None:
pass
elif self._attr_native_value == evu and str(self._last_state) != evu:
# evu start
if weekday not in self._attr_cache[SA.EVU_DAYS]:
self._attr_cache[SA.EVU_DAYS].append(weekday)
if (
self._attr_cache[SA.EVU_FIRST_START_TIME] == time.min
or (
Expand Down Expand Up @@ -407,13 +411,14 @@ def _calc_next_evu_event_minutes(self) -> int | None:
elif not isinstance(self._attr_cache[SA.EVU_DAYS], list):
self._attr_cache[SA.EVU_DAYS] = list()
evu_pause = 0
if not self._attr_cache[SA.EVU_DAYS] and weekday not in self._attr_cache[SA.EVU_DAYS]:
if self._attr_cache[SA.EVU_DAYS] and weekday not in self._attr_cache[SA.EVU_DAYS]:
evu_pause += (24 - datetime.now().hour)*60 - datetime.now().minute
evu_time = self._attr_cache[SA.EVU_FIRST_START_TIME]
for i in range(1, 7):
if weekday+i > 6:
i = -7+i
if weekday+i in self._attr_cache[SA.EVU_DAYS]:
return (evu_hours - time_now.hour) * 60 + evu_time.minute - time_now.minute + evu_pause
return evu_time.hour*60 + evu_time.minute + evu_pause
else:
evu_pause += 1440
else:
Expand Down

0 comments on commit a6ad7c0

Please sign in to comment.