mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use climate enums in esphome (#70638)
This commit is contained in:
parent
035635dbaf
commit
c3353e4726
@ -13,17 +13,11 @@ from aioesphomeapi import (
|
|||||||
ClimateSwingMode,
|
ClimateSwingMode,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_HVAC_MODE,
|
ATTR_HVAC_MODE,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
CURRENT_HVAC_COOL,
|
|
||||||
CURRENT_HVAC_DRY,
|
|
||||||
CURRENT_HVAC_FAN,
|
|
||||||
CURRENT_HVAC_HEAT,
|
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
CURRENT_HVAC_OFF,
|
|
||||||
FAN_AUTO,
|
FAN_AUTO,
|
||||||
FAN_DIFFUSE,
|
FAN_DIFFUSE,
|
||||||
FAN_FOCUS,
|
FAN_FOCUS,
|
||||||
@ -33,13 +27,6 @@ from homeassistant.components.climate.const import (
|
|||||||
FAN_MIDDLE,
|
FAN_MIDDLE,
|
||||||
FAN_OFF,
|
FAN_OFF,
|
||||||
FAN_ON,
|
FAN_ON,
|
||||||
HVAC_MODE_AUTO,
|
|
||||||
HVAC_MODE_COOL,
|
|
||||||
HVAC_MODE_DRY,
|
|
||||||
HVAC_MODE_FAN_ONLY,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_HEAT_COOL,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
PRESET_ACTIVITY,
|
PRESET_ACTIVITY,
|
||||||
PRESET_AWAY,
|
PRESET_AWAY,
|
||||||
PRESET_BOOST,
|
PRESET_BOOST,
|
||||||
@ -52,6 +39,9 @@ from homeassistant.components.climate.const import (
|
|||||||
SWING_HORIZONTAL,
|
SWING_HORIZONTAL,
|
||||||
SWING_OFF,
|
SWING_OFF,
|
||||||
SWING_VERTICAL,
|
SWING_VERTICAL,
|
||||||
|
ClimateEntityFeature,
|
||||||
|
HVACAction,
|
||||||
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -87,25 +77,25 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
_CLIMATE_MODES: EsphomeEnumMapper[ClimateMode, str] = EsphomeEnumMapper(
|
_CLIMATE_MODES: EsphomeEnumMapper[ClimateMode, HVACMode] = EsphomeEnumMapper(
|
||||||
{
|
{
|
||||||
ClimateMode.OFF: HVAC_MODE_OFF,
|
ClimateMode.OFF: HVACMode.OFF,
|
||||||
ClimateMode.HEAT_COOL: HVAC_MODE_HEAT_COOL,
|
ClimateMode.HEAT_COOL: HVACMode.HEAT_COOL,
|
||||||
ClimateMode.COOL: HVAC_MODE_COOL,
|
ClimateMode.COOL: HVACMode.COOL,
|
||||||
ClimateMode.HEAT: HVAC_MODE_HEAT,
|
ClimateMode.HEAT: HVACMode.HEAT,
|
||||||
ClimateMode.FAN_ONLY: HVAC_MODE_FAN_ONLY,
|
ClimateMode.FAN_ONLY: HVACMode.FAN_ONLY,
|
||||||
ClimateMode.DRY: HVAC_MODE_DRY,
|
ClimateMode.DRY: HVACMode.DRY,
|
||||||
ClimateMode.AUTO: HVAC_MODE_AUTO,
|
ClimateMode.AUTO: HVACMode.AUTO,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
_CLIMATE_ACTIONS: EsphomeEnumMapper[ClimateAction, str] = EsphomeEnumMapper(
|
_CLIMATE_ACTIONS: EsphomeEnumMapper[ClimateAction, HVACAction] = EsphomeEnumMapper(
|
||||||
{
|
{
|
||||||
ClimateAction.OFF: CURRENT_HVAC_OFF,
|
ClimateAction.OFF: HVACAction.OFF,
|
||||||
ClimateAction.COOLING: CURRENT_HVAC_COOL,
|
ClimateAction.COOLING: HVACAction.COOLING,
|
||||||
ClimateAction.HEATING: CURRENT_HVAC_HEAT,
|
ClimateAction.HEATING: HVACAction.HEATING,
|
||||||
ClimateAction.IDLE: CURRENT_HVAC_IDLE,
|
ClimateAction.IDLE: HVACAction.IDLE,
|
||||||
ClimateAction.DRYING: CURRENT_HVAC_DRY,
|
ClimateAction.DRYING: HVACAction.DRYING,
|
||||||
ClimateAction.FAN: CURRENT_HVAC_FAN,
|
ClimateAction.FAN: HVACAction.FAN,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
_FAN_MODES: EsphomeEnumMapper[ClimateFanMode, str] = EsphomeEnumMapper(
|
_FAN_MODES: EsphomeEnumMapper[ClimateFanMode, str] = EsphomeEnumMapper(
|
||||||
@ -281,11 +271,13 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
|
|||||||
"""Return the highbound target temperature we try to reach."""
|
"""Return the highbound target temperature we try to reach."""
|
||||||
return self._state.target_temperature_high
|
return self._state.target_temperature_high
|
||||||
|
|
||||||
async def async_set_temperature(self, **kwargs: float | str) -> None:
|
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||||
"""Set new target temperature (and operation mode if set)."""
|
"""Set new target temperature (and operation mode if set)."""
|
||||||
data: dict[str, Any] = {"key": self._static_info.key}
|
data: dict[str, Any] = {"key": self._static_info.key}
|
||||||
if ATTR_HVAC_MODE in kwargs:
|
if ATTR_HVAC_MODE in kwargs:
|
||||||
data["mode"] = _CLIMATE_MODES.from_hass(cast(str, kwargs[ATTR_HVAC_MODE]))
|
data["mode"] = _CLIMATE_MODES.from_hass(
|
||||||
|
cast(HVACMode, kwargs[ATTR_HVAC_MODE])
|
||||||
|
)
|
||||||
if ATTR_TEMPERATURE in kwargs:
|
if ATTR_TEMPERATURE in kwargs:
|
||||||
data["target_temperature"] = kwargs[ATTR_TEMPERATURE]
|
data["target_temperature"] = kwargs[ATTR_TEMPERATURE]
|
||||||
if ATTR_TARGET_TEMP_LOW in kwargs:
|
if ATTR_TARGET_TEMP_LOW in kwargs:
|
||||||
@ -294,7 +286,7 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
|
|||||||
data["target_temperature_high"] = kwargs[ATTR_TARGET_TEMP_HIGH]
|
data["target_temperature_high"] = kwargs[ATTR_TARGET_TEMP_HIGH]
|
||||||
await self._client.climate_command(**data)
|
await self._client.climate_command(**data)
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Set new target operation mode."""
|
"""Set new target operation mode."""
|
||||||
await self._client.climate_command(
|
await self._client.climate_command(
|
||||||
key=self._static_info.key, mode=_CLIMATE_MODES.from_hass(hvac_mode)
|
key=self._static_info.key, mode=_CLIMATE_MODES.from_hass(hvac_mode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user