Skip to content

Commit

Permalink
Fix thermostat entity fan mode (#45)
Browse files Browse the repository at this point in the history
* Mutate `_supported_flags` when calculating supported features

* Rename `_supported_flags` to `_supported_features`

* Move computation of `_supported_features` up into initializer
  • Loading branch information
puddly committed Apr 8, 2024
1 parent e2cdf1e commit 4a4ae78
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions zha/application/platforms/climate/__init__.py
Expand Up @@ -96,11 +96,7 @@ def __init__(
super().__init__(unique_id, cluster_handlers, endpoint, device, **kwargs)
self._preset = Preset.NONE
self._presets = []
self._supported_flags = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
)

self._thermostat_cluster_handler: ClusterHandler = self.cluster_handlers.get(
CLUSTER_HANDLER_THERMOSTAT
)
Expand All @@ -112,6 +108,16 @@ def __init__(
self.handle_cluster_handler_attribute_updated,
)

self._supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
)
if HVACMode.HEAT_COOL in self.hvac_modes:
self._supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
if self._fan_cluster_handler is not None:
self._supported_features |= ClimateEntityFeature.FAN_MODE

@functools.cached_property
def info_object(self) -> ThermostatEntityInfo:
"""Return a representation of the thermostat."""
Expand Down Expand Up @@ -287,12 +293,7 @@ def preset_modes(self) -> list[str] | None:
@functools.cached_property
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
features = self._supported_flags
if HVACMode.HEAT_COOL in self.hvac_modes:
features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
if self._fan_cluster_handler is not None:
self._supported_flags |= ClimateEntityFeature.FAN_MODE
return features
return self._supported_features

@property
def target_temperature(self):
Expand Down Expand Up @@ -509,7 +510,7 @@ def __init__(
"""Initialize ZHA Thermostat instance."""
super().__init__(unique_id, cluster_handlers, endpoint, device, **kwargs)
self._presets = [Preset.AWAY, Preset.NONE]
self._supported_flags |= ClimateEntityFeature.PRESET_MODE
self._supported_features |= ClimateEntityFeature.PRESET_MODE
self._manufacturer_ch = self.cluster_handlers["sinope_manufacturer_specific"]

self._tracked_tasks.append(
Expand Down Expand Up @@ -632,7 +633,7 @@ def __init__(
Preset.BOOST,
Preset.COMPLEX,
]
self._supported_flags |= ClimateEntityFeature.PRESET_MODE
self._supported_features |= ClimateEntityFeature.PRESET_MODE

@functools.cached_property
def hvac_modes(self) -> list[HVACMode]:
Expand Down Expand Up @@ -720,7 +721,7 @@ def __init__(
Preset.BOOST,
Preset.TEMP_MANUAL,
]
self._supported_flags |= ClimateEntityFeature.PRESET_MODE
self._supported_features |= ClimateEntityFeature.PRESET_MODE

@functools.cached_property
def hvac_modes(self) -> list[HVACMode]:
Expand Down Expand Up @@ -829,7 +830,7 @@ def __init__(
Preset.SCHEDULE,
self.PRESET_FROST,
]
self._supported_flags |= ClimateEntityFeature.PRESET_MODE
self._supported_features |= ClimateEntityFeature.PRESET_MODE

def handle_cluster_handler_attribute_updated(
self, event: ClusterAttributeUpdatedEvent
Expand Down

0 comments on commit 4a4ae78

Please sign in to comment.