Use climate enums in sensibo (#70734)

This commit is contained in:
epenet 2022-04-26 09:01:32 +02:00 committed by GitHub
parent 24b7d1f47b
commit ba7cff505e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,15 +4,7 @@ from __future__ import annotations
import voluptuous as vol import voluptuous as vol
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import ClimateEntityFeature, HVACMode
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
HVAC_MODE_OFF,
ClimateEntityFeature,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_STATE, ATTR_STATE,
@ -40,12 +32,12 @@ FIELD_TO_FLAG = {
} }
SENSIBO_TO_HA = { SENSIBO_TO_HA = {
"cool": HVAC_MODE_COOL, "cool": HVACMode.COOL,
"heat": HVAC_MODE_HEAT, "heat": HVACMode.HEAT,
"fan": HVAC_MODE_FAN_ONLY, "fan": HVACMode.FAN_ONLY,
"auto": HVAC_MODE_HEAT_COOL, "auto": HVACMode.HEAT_COOL,
"dry": HVAC_MODE_DRY, "dry": HVACMode.DRY,
"off": HVAC_MODE_OFF, "off": HVACMode.OFF,
} }
HA_TO_SENSIBO = {value: key for key, value in SENSIBO_TO_HA.items()} HA_TO_SENSIBO = {value: key for key, value in SENSIBO_TO_HA.items()}
@ -113,16 +105,14 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
return self.device_data.humidity return self.device_data.humidity
@property @property
def hvac_mode(self) -> str: def hvac_mode(self) -> HVACMode:
"""Return hvac operation.""" """Return hvac operation."""
return ( if self.device_data.device_on:
SENSIBO_TO_HA[self.device_data.hvac_mode] return SENSIBO_TO_HA[self.device_data.hvac_mode]
if self.device_data.device_on return HVACMode.OFF
else HVAC_MODE_OFF
)
@property @property
def hvac_modes(self) -> list[str]: def hvac_modes(self) -> list[HVACMode]:
"""Return the list of available hvac operation modes.""" """Return the list of available hvac operation modes."""
return [SENSIBO_TO_HA[mode] for mode in self.device_data.hvac_modes] return [SENSIBO_TO_HA[mode] for mode in self.device_data.hvac_modes]
@ -213,9 +203,9 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
await self._async_set_ac_state_property("fanLevel", fan_mode) await self._async_set_ac_state_property("fanLevel", fan_mode)
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."""
if hvac_mode == HVAC_MODE_OFF: if hvac_mode == HVACMode.OFF:
await self._async_set_ac_state_property("on", False) await self._async_set_ac_state_property("on", False)
return return
@ -265,5 +255,5 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity):
async def async_assume_state(self, state) -> None: async def async_assume_state(self, state) -> None:
"""Sync state with api.""" """Sync state with api."""
await self._async_set_ac_state_property("on", state != HVAC_MODE_OFF, True) await self._async_set_ac_state_property("on", state != HVACMode.OFF, True)
await self.coordinator.async_refresh() await self.coordinator.async_refresh()