Refactor async_set_temperature for mqtt climate (#94166)

This commit is contained in:
Jan Bouwhuis 2023-06-07 20:34:59 +02:00 committed by GitHub
parent 7d8e412314
commit 8e9eb400bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -604,15 +604,8 @@ class MqttTemperatureControlEntity(MqttEntity, ABC):
return changed
@abstractmethod
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set hvac mode."""
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperatures."""
operation_mode: HVACMode | None
if (operation_mode := kwargs.get(ATTR_HVAC_MODE)) is not None:
await self.async_set_hvac_mode(operation_mode)
changed = await self._set_climate_attribute(
kwargs.get(ATTR_TEMPERATURE),
CONF_TEMP_COMMAND_TOPIC,
@ -967,6 +960,13 @@ class MqttClimate(MqttTemperatureControlEntity, ClimateEntity):
self.prepare_subscribe_topics(topics)
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperatures."""
operation_mode: HVACMode | None
if (operation_mode := kwargs.get(ATTR_HVAC_MODE)) is not None:
await self.async_set_hvac_mode(operation_mode)
await super().async_set_temperature(**kwargs)
async def async_set_humidity(self, humidity: int) -> None:
"""Set new target humidity."""