Skip to content

Commit

Permalink
Correct #250
Browse files Browse the repository at this point in the history
This issue comes from a simple cause but a bug in HA made it look very
weird.
Cause: accessing attributes before having them defined.
Fix: simply define the attribute in constructor

Fix #250
  • Loading branch information
kamaradclimber committed Sep 20, 2024
1 parent 7af92d0 commit 2a52f24
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion custom_components/aquarea/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ def __init__(
# we only display heater by default
self._attr_entity_registry_enabled_default = self.heater

# set default values so that attribute is always defined
self._attr_min_temp = self.UNDEFINED_VALUE
self._attr_max_temp = self.UNDEFINED_VALUE

UNDEFINED_VALUE = -42

async def async_turn_off(self) -> None:
await self.async_set_hvac_mode(HVACMode.OFF)

Expand Down Expand Up @@ -359,7 +365,7 @@ def target_temperature_message_received(message):
f"{self._climate_type()} Received target temperature for {self.zone_id}: {self._attr_target_temperature}"
)
if not self._mode_guessed:
if self._attr_min_temp != None and self._attr_max_temp != None:
if self._attr_min_temp != self.UNDEFINED_VALUE and self._attr_max_temp != self.UNDEFINED_VALUE:
if self._attr_target_temperature < self._attr_min_temp or self._attr_target_temperature > self._attr_max_temp:
# when reaching that point, maybe we should set a wider range to avoid blocking user?
_LOGGER.warn(f"{self._climate_type()} Target temperature is not within expected range, this is suspicious. {self._attr_target_temperature} should be within [{self._attr_min_temp},{self._attr_max_temp}]")
Expand Down

0 comments on commit 2a52f24

Please sign in to comment.