Fix climate and humidifier platform for Comelit (#140611)

fix climate and humidifier platform for Comelit
This commit is contained in:
Simone Chemelli 2025-03-23 12:32:38 +01:00 committed by GitHub
parent 5c642ef626
commit 77f8ddd948
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 6 deletions

View File

@ -119,10 +119,10 @@ class ComelitClimateEntity(CoordinatorEntity[ComelitSerialBridge], ClimateEntity
# because no serial number or mac is available # because no serial number or mac is available
self._attr_unique_id = f"{config_entry_entry_id}-{device.index}" self._attr_unique_id = f"{config_entry_entry_id}-{device.index}"
self._attr_device_info = coordinator.platform_device_info(device, device.type) self._attr_device_info = coordinator.platform_device_info(device, device.type)
self._update_attributes()
@callback def _update_attributes(self) -> None:
def _handle_coordinator_update(self) -> None: """Update class attributes."""
"""Handle updated data from the coordinator."""
device = self.coordinator.data[CLIMATE][self._device.index] device = self.coordinator.data[CLIMATE][self._device.index]
if not isinstance(device.val, list): if not isinstance(device.val, list):
raise HomeAssistantError( raise HomeAssistantError(
@ -158,6 +158,12 @@ class ComelitClimateEntity(CoordinatorEntity[ComelitSerialBridge], ClimateEntity
self._attr_target_temperature = values[4] / 10 self._attr_target_temperature = values[4] / 10
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._update_attributes()
super()._handle_coordinator_update()
async def async_set_temperature(self, **kwargs: Any) -> None: async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
if ( if (
@ -171,6 +177,8 @@ class ComelitClimateEntity(CoordinatorEntity[ComelitSerialBridge], ClimateEntity
await self.coordinator.api.set_clima_status( await self.coordinator.api.set_clima_status(
self._device.index, ClimaComelitCommand.SET, target_temp self._device.index, ClimaComelitCommand.SET, target_temp
) )
self._attr_target_temperature = target_temp
self.async_write_ha_state()
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set hvac mode.""" """Set hvac mode."""
@ -182,3 +190,5 @@ class ComelitClimateEntity(CoordinatorEntity[ComelitSerialBridge], ClimateEntity
await self.coordinator.api.set_clima_status( await self.coordinator.api.set_clima_status(
self._device.index, MODE_TO_ACTION[hvac_mode] self._device.index, MODE_TO_ACTION[hvac_mode]
) )
self._attr_hvac_mode = hvac_mode
self.async_write_ha_state()

View File

@ -124,10 +124,10 @@ class ComelitHumidifierEntity(CoordinatorEntity[ComelitSerialBridge], Humidifier
self._active_mode = active_mode self._active_mode = active_mode
self._active_action = active_action self._active_action = active_action
self._set_command = set_command self._set_command = set_command
self._update_attributes()
@callback def _update_attributes(self) -> None:
def _handle_coordinator_update(self) -> None: """Update class attributes."""
"""Handle updated data from the coordinator."""
device = self.coordinator.data[CLIMATE][self._device.index] device = self.coordinator.data[CLIMATE][self._device.index]
if not isinstance(device.val, list): if not isinstance(device.val, list):
raise HomeAssistantError( raise HomeAssistantError(
@ -154,6 +154,12 @@ class ComelitHumidifierEntity(CoordinatorEntity[ComelitSerialBridge], Humidifier
self._attr_mode = MODE_AUTO if _automatic else MODE_NORMAL self._attr_mode = MODE_AUTO if _automatic else MODE_NORMAL
self._attr_target_humidity = values[4] / 10 self._attr_target_humidity = values[4] / 10
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._update_attributes()
super()._handle_coordinator_update()
async def async_set_humidity(self, humidity: int) -> None: async def async_set_humidity(self, humidity: int) -> None:
"""Set new target humidity.""" """Set new target humidity."""
if self.mode == HumidifierComelitMode.OFF: if self.mode == HumidifierComelitMode.OFF:
@ -168,12 +174,16 @@ class ComelitHumidifierEntity(CoordinatorEntity[ComelitSerialBridge], Humidifier
await self.coordinator.api.set_humidity_status( await self.coordinator.api.set_humidity_status(
self._device.index, HumidifierComelitCommand.SET, humidity self._device.index, HumidifierComelitCommand.SET, humidity
) )
self._attr_target_humidity = humidity
self.async_write_ha_state()
async def async_set_mode(self, mode: str) -> None: async def async_set_mode(self, mode: str) -> None:
"""Set humidifier mode.""" """Set humidifier mode."""
await self.coordinator.api.set_humidity_status( await self.coordinator.api.set_humidity_status(
self._device.index, MODE_TO_ACTION[mode] self._device.index, MODE_TO_ACTION[mode]
) )
self._attr_mode = mode
self.async_write_ha_state()
async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on.""" """Turn on."""