Skip to content

Commit

Permalink
* Fix attr calculation last_thermal_desinfection
Browse files Browse the repository at this point in the history
  • Loading branch information
BenPru committed Oct 13, 2023
1 parent 6bb59c0 commit f9b802f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions custom_components/luxtronik/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,20 @@ def formatted_data(self, attr: LuxtronikEntityAttributeDescription) -> str:
>= float(self._attr_state) * float(self.entity_description.factor)
and (
attr.key not in self._attr_cache
or self._attr_cache[attr.key] is None
or self._attr_cache[attr.key] == ""
or (
isinstance(self._attr_cache[attr.key], date)
and self._attr_cache[attr.key] < datetime.now().date()
)
or self._is_past(self._attr_cache[attr.key])
)
):
self._attr_cache[attr.key] = datetime.now().date()
value = self._attr_cache[attr.key] if attr.key in self._attr_cache else ""

return str(value)
result = self._attr_cache[attr.key] if attr.key in self._attr_cache else ""

return str(result)

def _is_past(self, value: str | date) -> bool:
if value is None or value == "":
return True
if isinstance(value, str):
try:
value = datetime.strptime(value, "%Y-%m-%d").date()
except:
return True
return value < datetime.now().date()

0 comments on commit f9b802f

Please sign in to comment.