Use climate enums in isy994 (#70678)

This commit is contained in:
epenet 2022-04-26 06:28:56 +02:00 committed by GitHub
parent 62c8687a86
commit d288c569fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 70 deletions

View File

@ -15,7 +15,7 @@ from pyisy.constants import (
) )
from pyisy.nodes import Node from pyisy.nodes import Node
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_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_LOW,
@ -23,9 +23,9 @@ from homeassistant.components.climate.const import (
FAN_AUTO, FAN_AUTO,
FAN_OFF, FAN_OFF,
FAN_ON, FAN_ON,
HVAC_MODE_COOL, ClimateEntityFeature,
HVAC_MODE_HEAT, HVACAction,
HVAC_MODE_OFF, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -74,6 +74,7 @@ async def async_setup_entry(
class ISYThermostatEntity(ISYNodeEntity, ClimateEntity): class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
"""Representation of an ISY994 thermostat entity.""" """Representation of an ISY994 thermostat entity."""
_attr_hvac_modes = ISY_HVAC_MODES
_attr_supported_features = ( _attr_supported_features = (
ClimateEntityFeature.FAN_MODE ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TARGET_TEMPERATURE
@ -118,10 +119,10 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
return int(humidity.value) return int(humidity.value)
@property @property
def hvac_mode(self) -> str: def hvac_mode(self) -> HVACMode:
"""Return hvac operation ie. heat, cool mode.""" """Return hvac operation ie. heat, cool mode."""
if not (hvac_mode := self._node.aux_properties.get(CMD_CLIMATE_MODE)): if not (hvac_mode := self._node.aux_properties.get(CMD_CLIMATE_MODE)):
return HVAC_MODE_OFF return HVACMode.OFF
# Which state values used depends on the mode property's UOM: # Which state values used depends on the mode property's UOM:
uom = hvac_mode.uom uom = hvac_mode.uom
@ -132,15 +133,10 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
if self._node.protocol == PROTO_INSTEON if self._node.protocol == PROTO_INSTEON
else UOM_HVAC_MODE_GENERIC else UOM_HVAC_MODE_GENERIC
) )
return UOM_TO_STATES[uom].get(hvac_mode.value, HVAC_MODE_OFF) return UOM_TO_STATES[uom].get(hvac_mode.value, HVACMode.OFF)
@property @property
def hvac_modes(self) -> list[str]: def hvac_action(self) -> HVACAction | None:
"""Return the list of available hvac operation modes."""
return ISY_HVAC_MODES
@property
def hvac_action(self) -> str | None:
"""Return the current running hvac operation if supported.""" """Return the current running hvac operation if supported."""
hvac_action = self._node.aux_properties.get(PROP_HEAT_COOL_STATE) hvac_action = self._node.aux_properties.get(PROP_HEAT_COOL_STATE)
if not hvac_action: if not hvac_action:
@ -162,9 +158,9 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
@property @property
def target_temperature(self) -> float | None: def target_temperature(self) -> float | None:
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""
if self.hvac_mode == HVAC_MODE_COOL: if self.hvac_mode == HVACMode.COOL:
return self.target_temperature_high return self.target_temperature_high
if self.hvac_mode == HVAC_MODE_HEAT: if self.hvac_mode == HVACMode.HEAT:
return self.target_temperature_low return self.target_temperature_low
return None return None
@ -203,9 +199,9 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW) target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
target_temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH) target_temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
if target_temp is not None: if target_temp is not None:
if self.hvac_mode == HVAC_MODE_COOL: if self.hvac_mode == HVACMode.COOL:
target_temp_high = target_temp target_temp_high = target_temp
if self.hvac_mode == HVAC_MODE_HEAT: if self.hvac_mode == HVACMode.HEAT:
target_temp_low = target_temp target_temp_low = target_temp
if target_temp_low is not None: if target_temp_low is not None:
await self._node.set_climate_setpoint_heat(int(target_temp_low)) await self._node.set_climate_setpoint_heat(int(target_temp_low))
@ -225,7 +221,7 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
self._fan_mode = fan_mode self._fan_mode = fan_mode
self.async_write_ha_state() self.async_write_ha_state()
async def async_set_hvac_mode(self, hvac_mode: str) -> None: async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode.""" """Set new target hvac mode."""
_LOGGER.debug("Requested operation mode %s", hvac_mode) _LOGGER.debug("Requested operation mode %s", hvac_mode)
await self._node.set_climate_mode(HA_HVAC_TO_ISY.get(hvac_mode)) await self._node.set_climate_mode(HA_HVAC_TO_ISY.get(hvac_mode))

View File

@ -3,23 +3,14 @@ import logging
from homeassistant.components.binary_sensor import BinarySensorDeviceClass from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
CURRENT_HVAC_COOL,
CURRENT_HVAC_FAN,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
FAN_AUTO, FAN_AUTO,
FAN_HIGH, FAN_HIGH,
FAN_MEDIUM, FAN_MEDIUM,
FAN_ON, FAN_ON,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
HVAC_MODE_OFF,
PRESET_AWAY, PRESET_AWAY,
PRESET_BOOST, PRESET_BOOST,
HVACAction,
HVACMode,
) )
from homeassistant.const import ( from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
@ -465,38 +456,38 @@ UOM_TO_STATES = {
27: "factory reset", 27: "factory reset",
}, },
UOM_HVAC_ACTIONS: { # Thermostat Heat/Cool State UOM_HVAC_ACTIONS: { # Thermostat Heat/Cool State
0: CURRENT_HVAC_IDLE, 0: HVACAction.IDLE.value,
1: CURRENT_HVAC_HEAT, 1: HVACAction.HEATING.value,
2: CURRENT_HVAC_COOL, 2: HVACAction.COOLING.value,
3: CURRENT_HVAC_FAN, 3: HVACAction.FAN.value,
4: CURRENT_HVAC_HEAT, # Pending Heat 4: HVACAction.HEATING.value, # Pending Heat
5: CURRENT_HVAC_COOL, # Pending Cool 5: HVACAction.COOLING.value, # Pending Cool
# >6 defined in ISY but not implemented, leaving for future expanision. # >6 defined in ISY but not implemented, leaving for future expanision.
6: CURRENT_HVAC_IDLE, 6: HVACAction.IDLE.value,
7: CURRENT_HVAC_HEAT, 7: HVACAction.HEATING.value,
8: CURRENT_HVAC_HEAT, 8: HVACAction.HEATING.value,
9: CURRENT_HVAC_COOL, 9: HVACAction.COOLING.value,
10: CURRENT_HVAC_HEAT, 10: HVACAction.HEATING.value,
11: CURRENT_HVAC_HEAT, 11: HVACAction.HEATING.value,
}, },
UOM_HVAC_MODE_GENERIC: { # Thermostat Mode UOM_HVAC_MODE_GENERIC: { # Thermostat Mode
0: HVAC_MODE_OFF, 0: HVACMode.OFF.value,
1: HVAC_MODE_HEAT, 1: HVACMode.HEAT.value,
2: HVAC_MODE_COOL, 2: HVACMode.COOL.value,
3: HVAC_MODE_AUTO, 3: HVACMode.AUTO.value,
4: PRESET_BOOST, 4: PRESET_BOOST,
5: "resume", 5: "resume",
6: HVAC_MODE_FAN_ONLY, 6: HVACMode.FAN_ONLY.value,
7: "furnace", 7: "furnace",
8: HVAC_MODE_DRY, 8: HVACMode.DRY.value,
9: "moist air", 9: "moist air",
10: "auto changeover", 10: "auto changeover",
11: "energy save heat", 11: "energy save heat",
12: "energy save cool", 12: "energy save cool",
13: PRESET_AWAY, 13: PRESET_AWAY,
14: HVAC_MODE_AUTO, 14: HVACMode.AUTO.value,
15: HVAC_MODE_AUTO, 15: HVACMode.AUTO.value,
16: HVAC_MODE_AUTO, 16: HVACMode.AUTO.value,
}, },
"68": { # Thermostat Fan Mode "68": { # Thermostat Fan Mode
0: FAN_AUTO, 0: FAN_AUTO,
@ -589,14 +580,14 @@ UOM_TO_STATES = {
}, # 1-99 are percentage open }, # 1-99 are percentage open
}, },
UOM_HVAC_MODE_INSTEON: { # Insteon Thermostat Mode UOM_HVAC_MODE_INSTEON: { # Insteon Thermostat Mode
0: HVAC_MODE_OFF, 0: HVACMode.OFF.value,
1: HVAC_MODE_HEAT, 1: HVACMode.HEAT.value,
2: HVAC_MODE_COOL, 2: HVACMode.COOL.value,
3: HVAC_MODE_HEAT_COOL, 3: HVACMode.HEAT_COOL.value,
4: HVAC_MODE_FAN_ONLY, 4: HVACMode.FAN_ONLY.value,
5: HVAC_MODE_AUTO, # Program Auto 5: HVACMode.AUTO.value, # Program Auto
6: HVAC_MODE_AUTO, # Program Heat-Set @ Local Device Only 6: HVACMode.AUTO.value, # Program Heat-Set @ Local Device Only
7: HVAC_MODE_AUTO, # Program Cool-Set @ Local Device Only 7: HVACMode.AUTO.value, # Program Cool-Set @ Local Device Only
}, },
UOM_FAN_MODES: {7: FAN_ON, 8: FAN_AUTO}, # Insteon Thermostat Fan Mode UOM_FAN_MODES: {7: FAN_ON, 8: FAN_AUTO}, # Insteon Thermostat Fan Mode
"115": { # Most recent On style action taken for lamp control "115": { # Most recent On style action taken for lamp control
@ -617,21 +608,21 @@ UOM_TO_STATES = {
} }
ISY_HVAC_MODES = [ ISY_HVAC_MODES = [
HVAC_MODE_OFF, HVACMode.OFF,
HVAC_MODE_HEAT, HVACMode.HEAT,
HVAC_MODE_COOL, HVACMode.COOL,
HVAC_MODE_HEAT_COOL, HVACMode.HEAT_COOL,
HVAC_MODE_AUTO, HVACMode.AUTO,
HVAC_MODE_FAN_ONLY, HVACMode.FAN_ONLY,
] ]
HA_HVAC_TO_ISY = { HA_HVAC_TO_ISY = {
HVAC_MODE_OFF: "off", HVACMode.OFF: "off",
HVAC_MODE_HEAT: "heat", HVACMode.HEAT: "heat",
HVAC_MODE_COOL: "cool", HVACMode.COOL: "cool",
HVAC_MODE_HEAT_COOL: "auto", HVACMode.HEAT_COOL: "auto",
HVAC_MODE_FAN_ONLY: "fan_only", HVACMode.FAN_ONLY: "fan_only",
HVAC_MODE_AUTO: "program_auto", HVACMode.AUTO: "program_auto",
} }
HA_FAN_TO_ISY = {FAN_ON: "on", FAN_AUTO: "auto"} HA_FAN_TO_ISY = {FAN_ON: "on", FAN_AUTO: "auto"}