Add humidity and aux heat support to ESPHome climate entities (#103807)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Stefan Rado 2023-11-29 05:57:30 +01:00 committed by GitHub
parent 3c25d95481
commit 017d05c03e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 168 additions and 1 deletions

View file

@ -164,11 +164,17 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
)
self._attr_min_temp = static_info.visual_min_temperature
self._attr_max_temp = static_info.visual_max_temperature
self._attr_min_humidity = round(static_info.visual_min_humidity)
self._attr_max_humidity = round(static_info.visual_max_humidity)
features = ClimateEntityFeature(0)
if self._static_info.supports_two_point_target_temperature:
features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
else:
features |= ClimateEntityFeature.TARGET_TEMPERATURE
if self._static_info.supports_target_humidity:
features |= ClimateEntityFeature.TARGET_HUMIDITY
if self._static_info.supports_aux_heat:
features |= ClimateEntityFeature.AUX_HEAT
if self.preset_modes:
features |= ClimateEntityFeature.PRESET_MODE
if self.fan_modes:
@ -234,6 +240,14 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
"""Return the current temperature."""
return self._state.current_temperature
@property
@esphome_state_property
def current_humidity(self) -> int | None:
"""Return the current humidity."""
if not self._static_info.supports_current_humidity:
return None
return round(self._state.current_humidity)
@property
@esphome_state_property
def target_temperature(self) -> float | None:
@ -252,6 +266,18 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
"""Return the highbound target temperature we try to reach."""
return self._state.target_temperature_high
@property
@esphome_state_property
def target_humidity(self) -> int:
"""Return the humidity we try to reach."""
return round(self._state.target_humidity)
@property
@esphome_state_property
def is_aux_heat(self) -> bool:
"""Return the auxiliary heater state."""
return self._state.aux_heat
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature (and operation mode if set)."""
data: dict[str, Any] = {"key": self._key}
@ -267,6 +293,10 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
data["target_temperature_high"] = kwargs[ATTR_TARGET_TEMP_HIGH]
await self._client.climate_command(**data)
async def async_set_humidity(self, humidity: int) -> None:
"""Set new target humidity."""
await self._client.climate_command(key=self._key, target_humidity=humidity)
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target operation mode."""
await self._client.climate_command(
@ -296,3 +326,11 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
await self._client.climate_command(
key=self._key, swing_mode=_SWING_MODES.from_hass(swing_mode)
)
async def async_turn_aux_heat_on(self) -> None:
"""Turn auxiliary heater on."""
await self._client.climate_command(key=self._key, aux_heat=True)
async def async_turn_aux_heat_off(self) -> None:
"""Turn auxiliary heater off."""
await self._client.climate_command(key=self._key, aux_heat=False)