Use climate enums in geniushub (#70653)

This commit is contained in:
epenet 2022-04-25 10:46:52 +02:00 committed by GitHub
parent 2676f4df7a
commit 587505c85b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,15 +1,13 @@
"""Support for Genius Hub climate devices."""
from __future__ import annotations
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
CURRENT_HVAC_OFF,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
PRESET_ACTIVITY,
PRESET_BOOST,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -18,7 +16,7 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import DOMAIN, GeniusHeatingZone
# GeniusHub Zones support: Off, Timer, Override/Boost, Footprint & Linked modes
HA_HVAC_TO_GH = {HVAC_MODE_OFF: "off", HVAC_MODE_HEAT: "timer"}
HA_HVAC_TO_GH = {HVACMode.OFF: "off", HVACMode.HEAT: "timer"}
GH_HVAC_TO_HA = {v: k for k, v in HA_HVAC_TO_GH.items()}
HA_PRESET_TO_GH = {PRESET_ACTIVITY: "footprint", PRESET_BOOST: "override"}
@ -70,7 +68,7 @@ class GeniusClimateZone(GeniusHeatingZone, ClimateEntity):
@property
def hvac_mode(self) -> str:
"""Return hvac operation ie. heat, cool mode."""
return GH_HVAC_TO_HA.get(self._zone.data["mode"], HVAC_MODE_HEAT)
return GH_HVAC_TO_HA.get(self._zone.data["mode"], HVACMode.HEAT)
@property
def hvac_modes(self) -> list[str]:
@ -82,10 +80,10 @@ class GeniusClimateZone(GeniusHeatingZone, ClimateEntity):
"""Return the current running hvac operation if supported."""
if "_state" in self._zone.data: # only for v3 API
if not self._zone.data["_state"].get("bIsActive"):
return CURRENT_HVAC_OFF
return HVACAction.OFF
if self._zone.data["_state"].get("bOutRequestHeat"):
return CURRENT_HVAC_HEAT
return CURRENT_HVAC_IDLE
return HVACAction.HEATING
return HVACAction.IDLE
return None
@property
@ -100,7 +98,9 @@ class GeniusClimateZone(GeniusHeatingZone, ClimateEntity):
return [PRESET_ACTIVITY, PRESET_BOOST]
return [PRESET_BOOST]
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
async def async_set_hvac_mode( # type:ignore[override]
self, hvac_mode: HVACMode
) -> None:
"""Set a new hvac mode."""
await self._zone.set_mode(HA_HVAC_TO_GH.get(hvac_mode))