Skip to content

Commit

Permalink
changed new weekday attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Gifford47 committed Apr 11, 2024
2 parents 609a466 + 5a5f220 commit b679ded
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions custom_components/luxtronik/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

from datetime import date, datetime, time, timezone
import calendar
from decimal import Decimal
from typing import Any

Expand Down Expand Up @@ -182,12 +183,12 @@ class LuxtronikStatusSensorEntity(LuxtronikSensorEntity, SensorEntity):
_coordinator: LuxtronikCoordinator
_last_state: StateType | date | datetime | Decimal = None

_attr_cache: dict[SA, time] = {}
_attr_cache: dict[SA, object] = {}
_attr_cache[SA.EVU_FIRST_START_TIME] = time.min
_attr_cache[SA.EVU_FIRST_END_TIME] = time.min
_attr_cache[SA.EVU_SECOND_START_TIME] = time.min
_attr_cache[SA.EVU_SECOND_END_TIME] = time.min
_attr_cache[SA.EVU_DAYS] = []
_attr_cache[SA.EVU_DAYS] = list()

_unrecorded_attributes = frozenset(
LuxtronikSensorEntity._unrecorded_attributes
Expand Down Expand Up @@ -324,6 +325,9 @@ def _handle_coordinator_update(
attr[SA.EVU_SECOND_END_TIME] = self._tm_txt(
self._attr_cache[SA.EVU_SECOND_END_TIME]
)
attr[SA.EVU_DAYS] = self._wd_txt(
self._attr_cache[SA.EVU_DAYS]
)
self._enrich_extra_attributes()
self.async_write_ha_state()

Expand Down Expand Up @@ -432,6 +436,14 @@ def _get_next_evu_event_time(self) -> time:
def _tm_txt(self, value: time) -> str:
return "" if value == time.min else value.strftime("%H:%M")

def _wd_txt(self, value: list) -> str:
if not value:
return ""
days = []
for i in value:
days.append(calendar.day_name[i])
return ','.join(days)

def _restore_attr_value(self, value: Any | None) -> Any:
if value is None or ":" not in str(value):
return time.min
Expand Down

0 comments on commit b679ded

Please sign in to comment.