mirror of
https://github.com/home-assistant/core
synced 2024-10-04 07:58:43 +02:00
Use climate enums in screenlogic (#70732)
This commit is contained in:
parent
7fb8bb7769
commit
347d769ea5
@ -3,14 +3,12 @@ import logging
|
|||||||
|
|
||||||
from screenlogicpy.const import DATA as SL_DATA, EQUIPMENT, HEAT_MODE
|
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 (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_PRESET_MODE,
|
ATTR_PRESET_MODE,
|
||||||
CURRENT_HVAC_HEAT,
|
ClimateEntityFeature,
|
||||||
CURRENT_HVAC_IDLE,
|
HVACAction,
|
||||||
CURRENT_HVAC_OFF,
|
HVACMode,
|
||||||
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, TEMP_FAHRENHEIT
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
@ -25,7 +23,7 @@ from .const import DOMAIN
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
SUPPORTED_MODES = [HVAC_MODE_OFF, HVAC_MODE_HEAT]
|
SUPPORTED_MODES = [HVACMode.OFF, HVACMode.HEAT]
|
||||||
|
|
||||||
SUPPORTED_PRESETS = [
|
SUPPORTED_PRESETS = [
|
||||||
HEAT_MODE.SOLAR,
|
HEAT_MODE.SOLAR,
|
||||||
@ -52,6 +50,7 @@ async def async_setup_entry(
|
|||||||
class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
|
class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
|
||||||
"""Represents a ScreenLogic climate entity."""
|
"""Represents a ScreenLogic climate entity."""
|
||||||
|
|
||||||
|
_attr_hvac_modes = SUPPORTED_MODES
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
||||||
)
|
)
|
||||||
@ -102,30 +101,25 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
|
|||||||
return TEMP_FAHRENHEIT
|
return TEMP_FAHRENHEIT
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> str:
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""Return the current hvac mode."""
|
"""Return the current hvac mode."""
|
||||||
if self.body["heat_mode"]["value"] > 0:
|
if self.body["heat_mode"]["value"] > 0:
|
||||||
return HVAC_MODE_HEAT
|
return HVACMode.HEAT
|
||||||
return HVAC_MODE_OFF
|
return HVACMode.OFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_modes(self):
|
def hvac_action(self) -> HVACAction:
|
||||||
"""Return th supported hvac modes."""
|
|
||||||
return SUPPORTED_MODES
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_action(self) -> str:
|
|
||||||
"""Return the current action of the heater."""
|
"""Return the current action of the heater."""
|
||||||
if self.body["heat_status"]["value"] > 0:
|
if self.body["heat_status"]["value"] > 0:
|
||||||
return CURRENT_HVAC_HEAT
|
return HVACAction.HEATING
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT:
|
if self.hvac_mode == HVACMode.HEAT:
|
||||||
return CURRENT_HVAC_IDLE
|
return HVACAction.IDLE
|
||||||
return CURRENT_HVAC_OFF
|
return HVACAction.OFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preset_mode(self) -> str:
|
def preset_mode(self) -> str:
|
||||||
"""Return current/last preset mode."""
|
"""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._last_preset]
|
||||||
return HEAT_MODE.NAME_FOR_NUM[self.body["heat_mode"]["value"]]
|
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:
|
async def async_set_hvac_mode(self, hvac_mode) -> None:
|
||||||
"""Set the operation mode."""
|
"""Set the operation mode."""
|
||||||
if hvac_mode == HVAC_MODE_OFF:
|
if hvac_mode == HVACMode.OFF:
|
||||||
mode = HEAT_MODE.OFF
|
mode = HEAT_MODE.OFF
|
||||||
else:
|
else:
|
||||||
mode = HEAT_MODE.NUM_FOR_NAME[self.preset_mode]
|
mode = HEAT_MODE.NUM_FOR_NAME[self.preset_mode]
|
||||||
@ -168,7 +162,7 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
|
|||||||
"""Set the preset mode."""
|
"""Set the preset mode."""
|
||||||
_LOGGER.debug("Setting last_preset to %s", HEAT_MODE.NUM_FOR_NAME[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]
|
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
|
return
|
||||||
|
|
||||||
if await self.gateway.async_set_heat_mode(int(self._data_key), int(mode)):
|
if await self.gateway.async_set_heat_mode(int(self._data_key), int(mode)):
|
||||||
|
Loading…
Reference in New Issue
Block a user