Use climate enums in stiebel_eltron (#70741)

pull/70764/head
epenet 2022-04-26 08:36:56 +02:00 committed by GitHub
parent f68eda97bc
commit 8429b23d65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 22 deletions

View File

@ -3,12 +3,11 @@ 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 (
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
PRESET_ECO, PRESET_ECO,
ClimateEntityFeature,
HVACMode,
) )
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -25,18 +24,18 @@ PRESET_DAY = "day"
PRESET_SETBACK = "setback" PRESET_SETBACK = "setback"
PRESET_EMERGENCY = "emergency" PRESET_EMERGENCY = "emergency"
SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF] SUPPORT_HVAC = [HVACMode.AUTO, HVACMode.HEAT, HVACMode.OFF]
SUPPORT_PRESET = [PRESET_ECO, PRESET_DAY, PRESET_EMERGENCY, PRESET_SETBACK] SUPPORT_PRESET = [PRESET_ECO, PRESET_DAY, PRESET_EMERGENCY, PRESET_SETBACK]
# Mapping STIEBEL ELTRON states to homeassistant states/preset. # Mapping STIEBEL ELTRON states to homeassistant states/preset.
STE_TO_HA_HVAC = { STE_TO_HA_HVAC = {
"AUTOMATIC": HVAC_MODE_AUTO, "AUTOMATIC": HVACMode.AUTO,
"MANUAL MODE": HVAC_MODE_HEAT, "MANUAL MODE": HVACMode.HEAT,
"STANDBY": HVAC_MODE_AUTO, "STANDBY": HVACMode.AUTO,
"DAY MODE": HVAC_MODE_AUTO, "DAY MODE": HVACMode.AUTO,
"SETBACK MODE": HVAC_MODE_AUTO, "SETBACK MODE": HVACMode.AUTO,
"DHW": HVAC_MODE_OFF, "DHW": HVACMode.OFF,
"EMERGENCY OPERATION": HVAC_MODE_AUTO, "EMERGENCY OPERATION": HVACMode.AUTO,
} }
STE_TO_HA_PRESET = { STE_TO_HA_PRESET = {
@ -47,9 +46,9 @@ STE_TO_HA_PRESET = {
} }
HA_TO_STE_HVAC = { HA_TO_STE_HVAC = {
HVAC_MODE_AUTO: "AUTOMATIC", HVACMode.AUTO: "AUTOMATIC",
HVAC_MODE_HEAT: "MANUAL MODE", HVACMode.HEAT: "MANUAL MODE",
HVAC_MODE_OFF: "DHW", HVACMode.OFF: "DHW",
} }
HA_TO_STE_PRESET = {k: i for i, k in STE_TO_HA_PRESET.items()} HA_TO_STE_PRESET = {k: i for i, k in STE_TO_HA_PRESET.items()}
@ -71,6 +70,7 @@ def setup_platform(
class StiebelEltron(ClimateEntity): class StiebelEltron(ClimateEntity):
"""Representation of a STIEBEL ELTRON heat pump.""" """Representation of a STIEBEL ELTRON heat pump."""
_attr_hvac_modes = SUPPORT_HVAC
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
) )
@ -148,12 +148,7 @@ class StiebelEltron(ClimateEntity):
return float(f"{self._current_humidity:.1f}") return float(f"{self._current_humidity:.1f}")
@property @property
def hvac_modes(self): def hvac_mode(self) -> HVACMode | None:
"""List of the operation modes."""
return SUPPORT_HVAC
@property
def hvac_mode(self):
"""Return current operation ie. heat, cool, idle.""" """Return current operation ie. heat, cool, idle."""
return STE_TO_HA_HVAC.get(self._operation) return STE_TO_HA_HVAC.get(self._operation)
@ -167,7 +162,7 @@ class StiebelEltron(ClimateEntity):
"""Return a list of available preset modes.""" """Return a list of available preset modes."""
return SUPPORT_PRESET return SUPPORT_PRESET
def set_hvac_mode(self, hvac_mode): def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new operation mode.""" """Set new operation mode."""
if self.preset_mode: if self.preset_mode:
return return