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