Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore evu date attribute correctly to solve the TypeError: 'datetime.time' #283

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
37 changes: 25 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,18 @@ 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 not isinstance(self._attr_cache[SA.EVU_DAYS], list):
Copy link

@Gifford47 Gifford47 Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a bug. it has to be checked if the attribute is a string. if yes, convert it to a list to append a new weekday. Please replace with the following:

        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()		# failsafe

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 +449,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
Loading