mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 05:47:10 +00:00
Use climate enums in honeywell (#70667)
This commit is contained in:
parent
65af9cb1a0
commit
c4eeeb9674
@ -6,25 +6,20 @@ from typing import Any
|
|||||||
|
|
||||||
import somecomfort
|
import somecomfort
|
||||||
|
|
||||||
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,
|
||||||
CURRENT_HVAC_COOL,
|
|
||||||
CURRENT_HVAC_FAN,
|
|
||||||
CURRENT_HVAC_HEAT,
|
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
DEFAULT_MAX_TEMP,
|
DEFAULT_MAX_TEMP,
|
||||||
DEFAULT_MIN_TEMP,
|
DEFAULT_MIN_TEMP,
|
||||||
FAN_AUTO,
|
FAN_AUTO,
|
||||||
FAN_DIFFUSE,
|
FAN_DIFFUSE,
|
||||||
FAN_ON,
|
FAN_ON,
|
||||||
HVAC_MODE_COOL,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_HEAT_COOL,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
PRESET_AWAY,
|
PRESET_AWAY,
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
|
ClimateEntityFeature,
|
||||||
|
HVACAction,
|
||||||
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
|
|
||||||
@ -42,23 +37,23 @@ ATTR_PERMANENT_HOLD = "permanent_hold"
|
|||||||
PRESET_HOLD = "Hold"
|
PRESET_HOLD = "Hold"
|
||||||
|
|
||||||
HVAC_MODE_TO_HW_MODE = {
|
HVAC_MODE_TO_HW_MODE = {
|
||||||
"SwitchOffAllowed": {HVAC_MODE_OFF: "off"},
|
"SwitchOffAllowed": {HVACMode.OFF: "off"},
|
||||||
"SwitchAutoAllowed": {HVAC_MODE_HEAT_COOL: "auto"},
|
"SwitchAutoAllowed": {HVACMode.HEAT_COOL: "auto"},
|
||||||
"SwitchCoolAllowed": {HVAC_MODE_COOL: "cool"},
|
"SwitchCoolAllowed": {HVACMode.COOL: "cool"},
|
||||||
"SwitchHeatAllowed": {HVAC_MODE_HEAT: "heat"},
|
"SwitchHeatAllowed": {HVACMode.HEAT: "heat"},
|
||||||
}
|
}
|
||||||
HW_MODE_TO_HVAC_MODE = {
|
HW_MODE_TO_HVAC_MODE = {
|
||||||
"off": HVAC_MODE_OFF,
|
"off": HVACMode.OFF,
|
||||||
"emheat": HVAC_MODE_HEAT,
|
"emheat": HVACMode.HEAT,
|
||||||
"heat": HVAC_MODE_HEAT,
|
"heat": HVACMode.HEAT,
|
||||||
"cool": HVAC_MODE_COOL,
|
"cool": HVACMode.COOL,
|
||||||
"auto": HVAC_MODE_HEAT_COOL,
|
"auto": HVACMode.HEAT_COOL,
|
||||||
}
|
}
|
||||||
HW_MODE_TO_HA_HVAC_ACTION = {
|
HW_MODE_TO_HA_HVAC_ACTION = {
|
||||||
"off": CURRENT_HVAC_IDLE,
|
"off": HVACAction.IDLE,
|
||||||
"fan": CURRENT_HVAC_FAN,
|
"fan": HVACAction.FAN,
|
||||||
"heat": CURRENT_HVAC_HEAT,
|
"heat": HVACAction.HEATING,
|
||||||
"cool": CURRENT_HVAC_COOL,
|
"cool": HVACAction.COOLING,
|
||||||
}
|
}
|
||||||
FAN_MODE_TO_HW = {
|
FAN_MODE_TO_HW = {
|
||||||
"fanModeOnAllowed": {FAN_ON: "on"},
|
"fanModeOnAllowed": {FAN_ON: "on"},
|
||||||
@ -150,18 +145,18 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||||||
@property
|
@property
|
||||||
def min_temp(self) -> float:
|
def min_temp(self) -> float:
|
||||||
"""Return the minimum temperature."""
|
"""Return the minimum temperature."""
|
||||||
if self.hvac_mode in [HVAC_MODE_COOL, HVAC_MODE_HEAT_COOL]:
|
if self.hvac_mode in [HVACMode.COOL, HVACMode.HEAT_COOL]:
|
||||||
return self._device.raw_ui_data["CoolLowerSetptLimit"]
|
return self._device.raw_ui_data["CoolLowerSetptLimit"]
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT:
|
if self.hvac_mode == HVACMode.HEAT:
|
||||||
return self._device.raw_ui_data["HeatLowerSetptLimit"]
|
return self._device.raw_ui_data["HeatLowerSetptLimit"]
|
||||||
return DEFAULT_MIN_TEMP
|
return DEFAULT_MIN_TEMP
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_temp(self) -> float:
|
def max_temp(self) -> float:
|
||||||
"""Return the maximum temperature."""
|
"""Return the maximum temperature."""
|
||||||
if self.hvac_mode == HVAC_MODE_COOL:
|
if self.hvac_mode == HVACMode.COOL:
|
||||||
return self._device.raw_ui_data["CoolUpperSetptLimit"]
|
return self._device.raw_ui_data["CoolUpperSetptLimit"]
|
||||||
if self.hvac_mode in [HVAC_MODE_HEAT, HVAC_MODE_HEAT_COOL]:
|
if self.hvac_mode in [HVACMode.HEAT, HVACMode.HEAT_COOL]:
|
||||||
return self._device.raw_ui_data["HeatUpperSetptLimit"]
|
return self._device.raw_ui_data["HeatUpperSetptLimit"]
|
||||||
return DEFAULT_MAX_TEMP
|
return DEFAULT_MAX_TEMP
|
||||||
|
|
||||||
@ -171,14 +166,14 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||||||
return self._device.current_humidity
|
return self._device.current_humidity
|
||||||
|
|
||||||
@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."""
|
||||||
return HW_MODE_TO_HVAC_MODE[self._device.system_mode]
|
return HW_MODE_TO_HVAC_MODE[self._device.system_mode]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_action(self) -> str | None:
|
def hvac_action(self) -> HVACAction | None:
|
||||||
"""Return the current running hvac operation if supported."""
|
"""Return the current running hvac operation if supported."""
|
||||||
if self.hvac_mode == HVAC_MODE_OFF:
|
if self.hvac_mode == HVACMode.OFF:
|
||||||
return None
|
return None
|
||||||
return HW_MODE_TO_HA_HVAC_ACTION[self._device.equipment_output_status]
|
return HW_MODE_TO_HA_HVAC_ACTION[self._device.equipment_output_status]
|
||||||
|
|
||||||
@ -190,23 +185,23 @@ class HoneywellUSThermostat(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._device.setpoint_cool
|
return self._device.setpoint_cool
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT:
|
if self.hvac_mode == HVACMode.HEAT:
|
||||||
return self._device.setpoint_heat
|
return self._device.setpoint_heat
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_high(self) -> float | None:
|
def target_temperature_high(self) -> float | None:
|
||||||
"""Return the highbound target temperature we try to reach."""
|
"""Return the highbound target temperature we try to reach."""
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
|
if self.hvac_mode == HVACMode.HEAT_COOL:
|
||||||
return self._device.setpoint_cool
|
return self._device.setpoint_cool
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_low(self) -> float | None:
|
def target_temperature_low(self) -> float | None:
|
||||||
"""Return the lowbound target temperature we try to reach."""
|
"""Return the lowbound target temperature we try to reach."""
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
|
if self.hvac_mode == HVACMode.HEAT_COOL:
|
||||||
return self._device.setpoint_heat
|
return self._device.setpoint_heat
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -254,11 +249,11 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||||||
|
|
||||||
def set_temperature(self, **kwargs) -> None:
|
def set_temperature(self, **kwargs) -> None:
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
if {HVAC_MODE_COOL, HVAC_MODE_HEAT} & set(self._hvac_mode_map):
|
if {HVACMode.COOL, HVACMode.HEAT} & set(self._hvac_mode_map):
|
||||||
self._set_temperature(**kwargs)
|
self._set_temperature(**kwargs)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if HVAC_MODE_HEAT_COOL in self._hvac_mode_map:
|
if HVACMode.HEAT_COOL in self._hvac_mode_map:
|
||||||
if temperature := kwargs.get(ATTR_TARGET_TEMP_HIGH):
|
if temperature := kwargs.get(ATTR_TARGET_TEMP_HIGH):
|
||||||
self._device.setpoint_cool = temperature
|
self._device.setpoint_cool = temperature
|
||||||
if temperature := kwargs.get(ATTR_TARGET_TEMP_LOW):
|
if temperature := kwargs.get(ATTR_TARGET_TEMP_LOW):
|
||||||
@ -270,7 +265,7 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||||||
"""Set new target fan mode."""
|
"""Set new target fan mode."""
|
||||||
self._device.fan_mode = self._fan_mode_map[fan_mode]
|
self._device.fan_mode = self._fan_mode_map[fan_mode]
|
||||||
|
|
||||||
def set_hvac_mode(self, hvac_mode: str) -> None:
|
def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Set new target hvac mode."""
|
"""Set new target hvac mode."""
|
||||||
self._device.system_mode = self._hvac_mode_map[hvac_mode]
|
self._device.system_mode = self._hvac_mode_map[hvac_mode]
|
||||||
|
|
||||||
@ -347,10 +342,10 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||||||
|
|
||||||
def turn_aux_heat_off(self) -> None:
|
def turn_aux_heat_off(self) -> None:
|
||||||
"""Turn auxiliary heater off."""
|
"""Turn auxiliary heater off."""
|
||||||
if HVAC_MODE_HEAT in self.hvac_modes:
|
if HVACMode.HEAT in self.hvac_modes:
|
||||||
self.set_hvac_mode(HVAC_MODE_HEAT)
|
self.set_hvac_mode(HVACMode.HEAT)
|
||||||
else:
|
else:
|
||||||
self.set_hvac_mode(HVAC_MODE_OFF)
|
self.set_hvac_mode(HVACMode.OFF)
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest state from the service."""
|
"""Get the latest state from the service."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user