Use climate enums in screenlogic (#70732)
This commit is contained in:
parent
7fb8bb7769
commit
347d769ea5
1 changed files with 17 additions and 23 deletions
|
@ -3,14 +3,12 @@ import logging
|
|||
|
||||
from screenlogicpy.const import DATA as SL_DATA, EQUIPMENT, HEAT_MODE
|
||||
|
||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
||||
from homeassistant.components.climate import ClimateEntity
|
||||
from homeassistant.components.climate.const import (
|
||||
ATTR_PRESET_MODE,
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
CURRENT_HVAC_OFF,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
ClimateEntityFeature,
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
|
@ -25,7 +23,7 @@ from .const import DOMAIN
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
SUPPORTED_MODES = [HVAC_MODE_OFF, HVAC_MODE_HEAT]
|
||||
SUPPORTED_MODES = [HVACMode.OFF, HVACMode.HEAT]
|
||||
|
||||
SUPPORTED_PRESETS = [
|
||||
HEAT_MODE.SOLAR,
|
||||
|
@ -52,6 +50,7 @@ async def async_setup_entry(
|
|||
class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
|
||||
"""Represents a ScreenLogic climate entity."""
|
||||
|
||||
_attr_hvac_modes = SUPPORTED_MODES
|
||||
_attr_supported_features = (
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
||||
)
|
||||
|
@ -102,30 +101,25 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
|
|||
return TEMP_FAHRENHEIT
|
||||
|
||||
@property
|
||||
def hvac_mode(self) -> str:
|
||||
def hvac_mode(self) -> HVACMode:
|
||||
"""Return the current hvac mode."""
|
||||
if self.body["heat_mode"]["value"] > 0:
|
||||
return HVAC_MODE_HEAT
|
||||
return HVAC_MODE_OFF
|
||||
return HVACMode.HEAT
|
||||
return HVACMode.OFF
|
||||
|
||||
@property
|
||||
def hvac_modes(self):
|
||||
"""Return th supported hvac modes."""
|
||||
return SUPPORTED_MODES
|
||||
|
||||
@property
|
||||
def hvac_action(self) -> str:
|
||||
def hvac_action(self) -> HVACAction:
|
||||
"""Return the current action of the heater."""
|
||||
if self.body["heat_status"]["value"] > 0:
|
||||
return CURRENT_HVAC_HEAT
|
||||
if self.hvac_mode == HVAC_MODE_HEAT:
|
||||
return CURRENT_HVAC_IDLE
|
||||
return CURRENT_HVAC_OFF
|
||||
return HVACAction.HEATING
|
||||
if self.hvac_mode == HVACMode.HEAT:
|
||||
return HVACAction.IDLE
|
||||
return HVACAction.OFF
|
||||
|
||||
@property
|
||||
def preset_mode(self) -> str:
|
||||
"""Return current/last preset mode."""
|
||||
if self.hvac_mode == HVAC_MODE_OFF:
|
||||
if self.hvac_mode == HVACMode.OFF:
|
||||
return HEAT_MODE.NAME_FOR_NUM[self._last_preset]
|
||||
return HEAT_MODE.NAME_FOR_NUM[self.body["heat_mode"]["value"]]
|
||||
|
||||
|
@ -152,7 +146,7 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
|
|||
|
||||
async def async_set_hvac_mode(self, hvac_mode) -> None:
|
||||
"""Set the operation mode."""
|
||||
if hvac_mode == HVAC_MODE_OFF:
|
||||
if hvac_mode == HVACMode.OFF:
|
||||
mode = HEAT_MODE.OFF
|
||||
else:
|
||||
mode = HEAT_MODE.NUM_FOR_NAME[self.preset_mode]
|
||||
|
@ -168,7 +162,7 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
|
|||
"""Set the preset mode."""
|
||||
_LOGGER.debug("Setting last_preset to %s", HEAT_MODE.NUM_FOR_NAME[preset_mode])
|
||||
self._last_preset = mode = HEAT_MODE.NUM_FOR_NAME[preset_mode]
|
||||
if self.hvac_mode == HVAC_MODE_OFF:
|
||||
if self.hvac_mode == HVACMode.OFF:
|
||||
return
|
||||
|
||||
if await self.gateway.async_set_heat_mode(int(self._data_key), int(mode)):
|
||||
|
|
Loading…
Add table
Reference in a new issue