Use climate enums in airtouch4 (#70622)

This commit is contained in:
epenet 2022-04-26 09:59:02 +02:00 committed by GitHub
parent c3353e4726
commit 59b7318db4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ from __future__ import annotations
import logging import logging
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 (
FAN_AUTO, FAN_AUTO,
FAN_DIFFUSE, FAN_DIFFUSE,
@ -11,12 +11,8 @@ from homeassistant.components.climate.const import (
FAN_HIGH, FAN_HIGH,
FAN_LOW, FAN_LOW,
FAN_MEDIUM, FAN_MEDIUM,
HVAC_MODE_AUTO, ClimateEntityFeature,
HVAC_MODE_COOL, HVACMode,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
@ -28,22 +24,22 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN from .const import DOMAIN
AT_TO_HA_STATE = { AT_TO_HA_STATE = {
"Heat": HVAC_MODE_HEAT, "Heat": HVACMode.HEAT,
"Cool": HVAC_MODE_COOL, "Cool": HVACMode.COOL,
"AutoHeat": HVAC_MODE_AUTO, # airtouch reports either autoheat or autocool "AutoHeat": HVACMode.AUTO, # airtouch reports either autoheat or autocool
"AutoCool": HVAC_MODE_AUTO, "AutoCool": HVACMode.AUTO,
"Auto": HVAC_MODE_AUTO, "Auto": HVACMode.AUTO,
"Dry": HVAC_MODE_DRY, "Dry": HVACMode.DRY,
"Fan": HVAC_MODE_FAN_ONLY, "Fan": HVACMode.FAN_ONLY,
} }
HA_STATE_TO_AT = { HA_STATE_TO_AT = {
HVAC_MODE_HEAT: "Heat", HVACMode.HEAT: "Heat",
HVAC_MODE_COOL: "Cool", HVACMode.COOL: "Cool",
HVAC_MODE_AUTO: "Auto", HVACMode.AUTO: "Auto",
HVAC_MODE_DRY: "Dry", HVACMode.DRY: "Dry",
HVAC_MODE_FAN_ONLY: "Fan", HVACMode.FAN_ONLY: "Fan",
HVAC_MODE_OFF: "Off", HVACMode.OFF: "Off",
} }
AT_TO_HA_FAN_SPEED = { AT_TO_HA_FAN_SPEED = {
@ -56,7 +52,7 @@ AT_TO_HA_FAN_SPEED = {
"Turbo": "turbo", "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()} 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.""" """Return hvac target hvac state."""
is_off = self._unit.PowerState == "Off" is_off = self._unit.PowerState == "Off"
if is_off: if is_off:
return HVAC_MODE_OFF return HVACMode.OFF
return AT_TO_HA_STATE[self._airtouch.acs[self._ac_number].AcMode] 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.""" """Return the list of available operation modes."""
airtouch_modes = self._airtouch.GetSupportedCoolingModesForAc(self._ac_number) airtouch_modes = self._airtouch.GetSupportedCoolingModesForAc(self._ac_number)
modes = [AT_TO_HA_STATE[mode] for mode in airtouch_modes] modes = [AT_TO_HA_STATE[mode] for mode in airtouch_modes]
modes.append(HVAC_MODE_OFF) modes.append(HVACMode.OFF)
return modes return modes
async def async_set_hvac_mode(self, hvac_mode): 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: if hvac_mode not in HA_STATE_TO_AT:
raise ValueError(f"Unsupported HVAC mode: {hvac_mode}") 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() return await self.async_turn_off()
await self._airtouch.SetCoolingModeForAc( await self._airtouch.SetCoolingModeForAc(
self._ac_number, HA_STATE_TO_AT[hvac_mode] 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') # there are other power states that aren't 'on' but still count as on (eg. 'Turbo')
is_off = self._unit.PowerState == "Off" is_off = self._unit.PowerState == "Off"
if is_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): async def async_set_hvac_mode(self, hvac_mode):
"""Set new operation mode.""" """Set new operation mode."""
if hvac_mode not in HA_STATE_TO_AT: if hvac_mode not in HA_STATE_TO_AT:
raise ValueError(f"Unsupported HVAC mode: {hvac_mode}") 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() return await self.async_turn_off()
if self.hvac_mode == HVAC_MODE_OFF: if self.hvac_mode == HVACMode.OFF:
await self.async_turn_on() await self.async_turn_on()
self._unit = self._airtouch.GetGroups()[self._group_number] self._unit = self._airtouch.GetGroups()[self._group_number]
_LOGGER.debug( _LOGGER.debug(