Use climate enums in airtouch4 (#70622)
This commit is contained in:
parent
c3353e4726
commit
59b7318db4
1 changed files with 24 additions and 28 deletions
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
||||
from homeassistant.components.climate import ClimateEntity
|
||||
from homeassistant.components.climate.const import (
|
||||
FAN_AUTO,
|
||||
FAN_DIFFUSE,
|
||||
|
@ -11,12 +11,8 @@ from homeassistant.components.climate.const import (
|
|||
FAN_HIGH,
|
||||
FAN_LOW,
|
||||
FAN_MEDIUM,
|
||||
HVAC_MODE_AUTO,
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_DRY,
|
||||
HVAC_MODE_FAN_ONLY,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
ClimateEntityFeature,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||
|
@ -28,22 +24,22 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|||
from .const import DOMAIN
|
||||
|
||||
AT_TO_HA_STATE = {
|
||||
"Heat": HVAC_MODE_HEAT,
|
||||
"Cool": HVAC_MODE_COOL,
|
||||
"AutoHeat": HVAC_MODE_AUTO, # airtouch reports either autoheat or autocool
|
||||
"AutoCool": HVAC_MODE_AUTO,
|
||||
"Auto": HVAC_MODE_AUTO,
|
||||
"Dry": HVAC_MODE_DRY,
|
||||
"Fan": HVAC_MODE_FAN_ONLY,
|
||||
"Heat": HVACMode.HEAT,
|
||||
"Cool": HVACMode.COOL,
|
||||
"AutoHeat": HVACMode.AUTO, # airtouch reports either autoheat or autocool
|
||||
"AutoCool": HVACMode.AUTO,
|
||||
"Auto": HVACMode.AUTO,
|
||||
"Dry": HVACMode.DRY,
|
||||
"Fan": HVACMode.FAN_ONLY,
|
||||
}
|
||||
|
||||
HA_STATE_TO_AT = {
|
||||
HVAC_MODE_HEAT: "Heat",
|
||||
HVAC_MODE_COOL: "Cool",
|
||||
HVAC_MODE_AUTO: "Auto",
|
||||
HVAC_MODE_DRY: "Dry",
|
||||
HVAC_MODE_FAN_ONLY: "Fan",
|
||||
HVAC_MODE_OFF: "Off",
|
||||
HVACMode.HEAT: "Heat",
|
||||
HVACMode.COOL: "Cool",
|
||||
HVACMode.AUTO: "Auto",
|
||||
HVACMode.DRY: "Dry",
|
||||
HVACMode.FAN_ONLY: "Fan",
|
||||
HVACMode.OFF: "Off",
|
||||
}
|
||||
|
||||
AT_TO_HA_FAN_SPEED = {
|
||||
|
@ -56,7 +52,7 @@ AT_TO_HA_FAN_SPEED = {
|
|||
"Turbo": "turbo",
|
||||
}
|
||||
|
||||
AT_GROUP_MODES = [HVAC_MODE_OFF, HVAC_MODE_FAN_ONLY]
|
||||
AT_GROUP_MODES = [HVACMode.OFF, HVACMode.FAN_ONLY]
|
||||
|
||||
HA_FAN_SPEED_TO_AT = {value: key for key, value in AT_TO_HA_FAN_SPEED.items()}
|
||||
|
||||
|
@ -146,7 +142,7 @@ class AirtouchAC(CoordinatorEntity, ClimateEntity):
|
|||
"""Return hvac target hvac state."""
|
||||
is_off = self._unit.PowerState == "Off"
|
||||
if is_off:
|
||||
return HVAC_MODE_OFF
|
||||
return HVACMode.OFF
|
||||
|
||||
return AT_TO_HA_STATE[self._airtouch.acs[self._ac_number].AcMode]
|
||||
|
||||
|
@ -155,7 +151,7 @@ class AirtouchAC(CoordinatorEntity, ClimateEntity):
|
|||
"""Return the list of available operation modes."""
|
||||
airtouch_modes = self._airtouch.GetSupportedCoolingModesForAc(self._ac_number)
|
||||
modes = [AT_TO_HA_STATE[mode] for mode in airtouch_modes]
|
||||
modes.append(HVAC_MODE_OFF)
|
||||
modes.append(HVACMode.OFF)
|
||||
return modes
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode):
|
||||
|
@ -163,7 +159,7 @@ class AirtouchAC(CoordinatorEntity, ClimateEntity):
|
|||
if hvac_mode not in HA_STATE_TO_AT:
|
||||
raise ValueError(f"Unsupported HVAC mode: {hvac_mode}")
|
||||
|
||||
if hvac_mode == HVAC_MODE_OFF:
|
||||
if hvac_mode == HVACMode.OFF:
|
||||
return await self.async_turn_off()
|
||||
await self._airtouch.SetCoolingModeForAc(
|
||||
self._ac_number, HA_STATE_TO_AT[hvac_mode]
|
||||
|
@ -266,18 +262,18 @@ class AirtouchGroup(CoordinatorEntity, ClimateEntity):
|
|||
# there are other power states that aren't 'on' but still count as on (eg. 'Turbo')
|
||||
is_off = self._unit.PowerState == "Off"
|
||||
if is_off:
|
||||
return HVAC_MODE_OFF
|
||||
return HVACMode.OFF
|
||||
|
||||
return HVAC_MODE_FAN_ONLY
|
||||
return HVACMode.FAN_ONLY
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode):
|
||||
"""Set new operation mode."""
|
||||
if hvac_mode not in HA_STATE_TO_AT:
|
||||
raise ValueError(f"Unsupported HVAC mode: {hvac_mode}")
|
||||
|
||||
if hvac_mode == HVAC_MODE_OFF:
|
||||
if hvac_mode == HVACMode.OFF:
|
||||
return await self.async_turn_off()
|
||||
if self.hvac_mode == HVAC_MODE_OFF:
|
||||
if self.hvac_mode == HVACMode.OFF:
|
||||
await self.async_turn_on()
|
||||
self._unit = self._airtouch.GetGroups()[self._group_number]
|
||||
_LOGGER.debug(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue