From a3938deb24ba6b1f594d11c8dfdf99c0437025cc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 26 Apr 2022 09:14:31 +0200 Subject: [PATCH] Use climate enums in shelly (#70736) --- homeassistant/components/shelly/climate.py | 36 +++++++++------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/shelly/climate.py b/homeassistant/components/shelly/climate.py index e0a2562e9b5..ffd5e012ef7 100644 --- a/homeassistant/components/shelly/climate.py +++ b/homeassistant/components/shelly/climate.py @@ -8,18 +8,12 @@ from typing import Any, cast from aioshelly.block_device import Block import async_timeout -from homeassistant.components.climate import ( - DOMAIN as CLIMATE_DOMAIN, - ClimateEntity, - ClimateEntityFeature, -) +from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN, ClimateEntity from homeassistant.components.climate.const import ( - CURRENT_HVAC_HEAT, - CURRENT_HVAC_IDLE, - CURRENT_HVAC_OFF, - HVAC_MODE_HEAT, - HVAC_MODE_OFF, PRESET_NONE, + ClimateEntityFeature, + HVACAction, + HVACMode, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS @@ -116,7 +110,7 @@ class BlockSleepingClimate( ): """Representation of a Shelly climate device.""" - _attr_hvac_modes = [HVAC_MODE_OFF, HVAC_MODE_HEAT] + _attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT] _attr_icon = "mdi:thermostat" _attr_max_temp = SHTRV_01_TEMPERATURE_SETTINGS["max"] _attr_min_temp = SHTRV_01_TEMPERATURE_SETTINGS["min"] @@ -191,14 +185,14 @@ class BlockSleepingClimate( return self.wrapper.last_update_success @property - def hvac_mode(self) -> str: + def hvac_mode(self) -> HVACMode: """HVAC current mode.""" if self.device_block is None: - return self.last_state.state if self.last_state else HVAC_MODE_OFF + return HVACMode(self.last_state.state) if self.last_state else HVACMode.OFF if self.device_block.mode is None or self._check_is_off(): - return HVAC_MODE_OFF + return HVACMode.OFF - return HVAC_MODE_HEAT + return HVACMode.HEAT @property def preset_mode(self) -> str | None: @@ -210,18 +204,16 @@ class BlockSleepingClimate( return self._preset_modes[cast(int, self.device_block.mode)] @property - def hvac_action(self) -> str | None: + def hvac_action(self) -> HVACAction: """HVAC current action.""" if ( self.device_block is None or self.device_block.status is None or self._check_is_off() ): - return CURRENT_HVAC_OFF + return HVACAction.OFF - return ( - CURRENT_HVAC_HEAT if bool(self.device_block.status) else CURRENT_HVAC_IDLE - ) + return HVACAction.HEATING if bool(self.device_block.status) else HVACAction.IDLE @property def preset_modes(self) -> list[str]: @@ -266,9 +258,9 @@ class BlockSleepingClimate( return await self.set_state_full_path(target_t_enabled=1, target_t=f"{current_temp}") - async def async_set_hvac_mode(self, hvac_mode: str) -> None: + async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: """Set hvac mode.""" - if hvac_mode == HVAC_MODE_OFF: + if hvac_mode == HVACMode.OFF: await self.set_state_full_path( target_t_enabled=1, target_t=f"{self._attr_min_temp}" )