Skip to content

Commit

Permalink
🐛 Fix update of frozen description
Browse files Browse the repository at this point in the history
Last patches froze the entity description objects so we can't update
them anymore at runtime.

Fix #174
  • Loading branch information
kamaradclimber committed Jan 6, 2024
1 parent 019d128 commit f4ebcc4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions custom_components/aquarea/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,9 @@ def guess_shift_or_direct_and_clamp_min_max_values(
"""
# FIXME: we assume entity is of type HeishMonNumberEntity. We should find a way to properly use the type system
if native_value in range1: # we always favor range1
entity.entity_description.native_min_value = min(range1)
entity.entity_description.native_max_value = max(range1)
entity.set_range(min(range1), max(range1))
elif native_value in range2:
entity.entity_description.native_min_value = min(range2)
entity.entity_description.native_max_value = max(range2)
entity.set_range(min(range2), max(range2))
else:
_LOGGER.warn(
f"Received value {native_value} for {entity.entity_description.name}. Impossible to know if we are using 'shift' mode or 'direct' mode, ignoring"
Expand Down
6 changes: 6 additions & 0 deletions custom_components/aquarea/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ def __init__(
self._attr_unique_id = (
f"{config_entry.entry_id}-{description.heishamon_topic_id}"
)
self._attr_native_min_value = description.native_min_value
self._attr_native_max_value = description.native_max_value

def set_range(self, min, max) -> None:
self._attr_native_min_value = min
self._attr_native_max_value = max

async def async_set_native_value(self, value: float) -> None:
_LOGGER.debug(
Expand Down

0 comments on commit f4ebcc4

Please sign in to comment.