Skip to content

Commit

Permalink
Merge pull request #283 from s-kurz/main
Browse files Browse the repository at this point in the history
restore evu date attribute correctly to solve the TypeError: 'datetime.time'
  • Loading branch information
BenPru authored Nov 15, 2024
2 parents 3e46f7f + 7346b20 commit fde3dd2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
39 changes: 27 additions & 12 deletions custom_components/luxtronik/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def _handle_coordinator_update(
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):
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:
Expand Down Expand Up @@ -394,16 +396,20 @@ def _calc_next_evu_event_minutes(self) -> int | None:
return None
evu_hours = (24 if evu_time < time_now else 0) + evu_time.hour
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()
evu_pause = 0
if not 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
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
else:
evu_pause += 1440
evu_pause += (24 - datetime.now().hour)*60 - datetime.now().minute
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
else:
evu_pause += 1440
else:
return (evu_hours - time_now.hour) * 60 + evu_time.minute - time_now.minute

Expand Down Expand Up @@ -445,10 +451,19 @@ def _wd_txt(self, value: list) -> str:
return ','.join(days)

def _restore_attr_value(self, value: Any | None) -> Any:
if value is None or ":" not in str(value):
return time.min
vals = str(value).split(":")
return time(int(vals[0]), int(vals[1]))
if value is not None:
if ":" in str(value):
vals = str(value).split(":")
return time(int(vals[0]), int(vals[1]))
vals = list()
for day in str(value).split(","):
for idx, name in enumerate(calendar.day_name):
if day == name:
vals.append(idx)
break
if vals:
return vals
return time.min


class LuxtronikIndexSensor(LuxtronikSensorEntity, SensorEntity):
Expand Down
1 change: 1 addition & 0 deletions custom_components/luxtronik/sensor_entities_predefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@
native_unit_of_measurement=UnitOfPower.WATT,
entity_registry_enabled_default=False,
native_precision=0,
min_firmware_version_minor=FirmwareVersionMinor.minor_88,
),
# endregion Main heatpump
# region Heating
Expand Down

0 comments on commit fde3dd2

Please sign in to comment.