Use climate enums in hive (#70664)

pull/70780/head
epenet 2022-04-26 09:56:11 +02:00 committed by GitHub
parent c104383ab9
commit 9132262fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 28 deletions

View File

@ -4,16 +4,13 @@ import logging
import voluptuous as vol
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_AUTO,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
PRESET_BOOST,
PRESET_NONE,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
@ -31,26 +28,25 @@ from .const import (
)
HIVE_TO_HASS_STATE = {
"SCHEDULE": HVAC_MODE_AUTO,
"MANUAL": HVAC_MODE_HEAT,
"OFF": HVAC_MODE_OFF,
"SCHEDULE": HVACMode.AUTO,
"MANUAL": HVACMode.HEAT,
"OFF": HVACMode.OFF,
}
HASS_TO_HIVE_STATE = {
HVAC_MODE_AUTO: "SCHEDULE",
HVAC_MODE_HEAT: "MANUAL",
HVAC_MODE_OFF: "OFF",
HVACMode.AUTO: "SCHEDULE",
HVACMode.HEAT: "MANUAL",
HVACMode.OFF: "OFF",
}
HIVE_TO_HASS_HVAC_ACTION = {
"UNKNOWN": CURRENT_HVAC_OFF,
False: CURRENT_HVAC_IDLE,
True: CURRENT_HVAC_HEAT,
"UNKNOWN": HVACAction.OFF,
False: HVACAction.IDLE,
True: HVACAction.HEATING,
}
TEMP_UNIT = {"C": TEMP_CELSIUS, "F": TEMP_FAHRENHEIT}
SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF]
SUPPORT_PRESET = [PRESET_NONE, PRESET_BOOST]
PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15)
@ -108,6 +104,7 @@ async def async_setup_entry(
class HiveClimateEntity(HiveEntity, ClimateEntity):
"""Hive Climate Device."""
_attr_hvac_modes = [HVACMode.AUTO, HVACMode.HEAT, HVACMode.OFF]
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
@ -146,15 +143,7 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
return self.device["deviceData"]["online"]
@property
def hvac_modes(self):
"""Return the list of available hvac operation modes.
Need to be a subset of HVAC_MODES.
"""
return SUPPORT_HVAC
@property
def hvac_mode(self):
def hvac_mode(self) -> HVACMode:
"""Return hvac operation ie. heat, cool mode.
Need to be one of HVAC_MODE_*.
@ -162,7 +151,7 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
return HIVE_TO_HASS_STATE[self.device["status"]["mode"]]
@property
def hvac_action(self):
def hvac_action(self) -> HVACAction:
"""Return current HVAC action."""
return HIVE_TO_HASS_HVAC_ACTION[self.device["status"]["action"]]
@ -204,7 +193,7 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
return SUPPORT_PRESET
@refresh_system
async def async_set_hvac_mode(self, hvac_mode):
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode."""
new_mode = HASS_TO_HIVE_STATE[hvac_mode]
await self.hive.heating.setMode(self.device, new_mode)