Skip to content

Commit

Permalink
Use async_update to set horizontal swing as supported
Browse files Browse the repository at this point in the history
Reimplement async_update in AtaDeviceClimate (from MelCloudClimate)
so that when the device information is obtained from the cloud, we
check if the device has horizontal vanes to mark SWING_HORIZONTAL_MODE
as a supported feature.

Note that we can't just check for self._device.vane_horizontal in
__init__ since vane_horizontal is only set (or not) after the device
data is fetched from the cloud.
  • Loading branch information
antlarr committed Jan 29, 2025
1 parent 9ef493f commit 5bc07e1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion homeassistant/components/melcloud/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ def __init__(self, device: MelCloudDevice, ata_device: AtaDevice) -> None:
self._attr_unique_id = f"{self.api.device.serial}-{self.api.device.mac}"
self._attr_device_info = self.api.device_info

async def async_update(self) -> None:

Check warning on line 153 in homeassistant/components/melcloud/climate.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/melcloud/climate.py#L153

Added line #L153 was not covered by tests
"""Update state from MELCloud."""
await super().async_update()

Check warning on line 155 in homeassistant/components/melcloud/climate.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/melcloud/climate.py#L155

Added line #L155 was not covered by tests

# We can only check for vane_horizontal once we fetch the device data from the cloud
if self._device.vane_horizontal:
self._attr_supported_features |= ClimateEntityFeature.SWING_HORIZONTAL_MODE

Check warning on line 159 in homeassistant/components/melcloud/climate.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/melcloud/climate.py#L158-L159

Added lines #L158 - L159 were not covered by tests

@property
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the optional state attributes with device specific additions."""
Expand All @@ -162,7 +170,6 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
ATTR_VANE_HORIZONTAL_POSITIONS: self._device.vane_horizontal_positions,
}
)
self._attr_supported_features |= ClimateEntityFeature.SWING_HORIZONTAL_MODE

if vane_vertical := self._device.vane_vertical:
attr.update(
Expand Down

0 comments on commit 5bc07e1

Please sign in to comment.