Use climate enums in radiotherm (#70758)
parent
896b616687
commit
fcecc38294
|
@ -7,29 +7,21 @@ from socket import timeout
|
||||||
import radiotherm
|
import radiotherm
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
|
||||||
PLATFORM_SCHEMA,
|
|
||||||
ClimateEntity,
|
|
||||||
ClimateEntityFeature,
|
|
||||||
)
|
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
CURRENT_HVAC_COOL,
|
FAN_AUTO,
|
||||||
CURRENT_HVAC_HEAT,
|
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
FAN_OFF,
|
FAN_OFF,
|
||||||
FAN_ON,
|
FAN_ON,
|
||||||
HVAC_MODE_AUTO,
|
|
||||||
HVAC_MODE_COOL,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
PRESET_AWAY,
|
PRESET_AWAY,
|
||||||
PRESET_HOME,
|
PRESET_HOME,
|
||||||
|
ClimateEntityFeature,
|
||||||
|
HVACAction,
|
||||||
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
PRECISION_HALVES,
|
PRECISION_HALVES,
|
||||||
STATE_ON,
|
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -52,9 +44,9 @@ STATE_CIRCULATE = "circulate"
|
||||||
|
|
||||||
PRESET_MODES = [PRESET_HOME, PRESET_ALTERNATE, PRESET_AWAY, PRESET_HOLIDAY]
|
PRESET_MODES = [PRESET_HOME, PRESET_ALTERNATE, PRESET_AWAY, PRESET_HOLIDAY]
|
||||||
|
|
||||||
OPERATION_LIST = [HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF]
|
OPERATION_LIST = [HVACMode.AUTO, HVACMode.COOL, HVACMode.HEAT, HVACMode.OFF]
|
||||||
CT30_FAN_OPERATION_LIST = [STATE_ON, HVAC_MODE_AUTO]
|
CT30_FAN_OPERATION_LIST = [FAN_ON, FAN_AUTO]
|
||||||
CT80_FAN_OPERATION_LIST = [STATE_ON, STATE_CIRCULATE, HVAC_MODE_AUTO]
|
CT80_FAN_OPERATION_LIST = [FAN_ON, STATE_CIRCULATE, FAN_AUTO]
|
||||||
|
|
||||||
# Mappings from radiotherm json data codes to and from Home Assistant state
|
# Mappings from radiotherm json data codes to and from Home Assistant state
|
||||||
# flags. CODE is the thermostat integer code and these map to and
|
# flags. CODE is the thermostat integer code and these map to and
|
||||||
|
@ -62,21 +54,21 @@ CT80_FAN_OPERATION_LIST = [STATE_ON, STATE_CIRCULATE, HVAC_MODE_AUTO]
|
||||||
|
|
||||||
# Programmed temperature mode of the thermostat.
|
# Programmed temperature mode of the thermostat.
|
||||||
CODE_TO_TEMP_MODE = {
|
CODE_TO_TEMP_MODE = {
|
||||||
0: HVAC_MODE_OFF,
|
0: HVACMode.OFF,
|
||||||
1: HVAC_MODE_HEAT,
|
1: HVACMode.HEAT,
|
||||||
2: HVAC_MODE_COOL,
|
2: HVACMode.COOL,
|
||||||
3: HVAC_MODE_AUTO,
|
3: HVACMode.AUTO,
|
||||||
}
|
}
|
||||||
TEMP_MODE_TO_CODE = {v: k for k, v in CODE_TO_TEMP_MODE.items()}
|
TEMP_MODE_TO_CODE = {v: k for k, v in CODE_TO_TEMP_MODE.items()}
|
||||||
|
|
||||||
# Programmed fan mode (circulate is supported by CT80 models)
|
# Programmed fan mode (circulate is supported by CT80 models)
|
||||||
CODE_TO_FAN_MODE = {0: HVAC_MODE_AUTO, 1: STATE_CIRCULATE, 2: STATE_ON}
|
CODE_TO_FAN_MODE = {0: FAN_AUTO, 1: STATE_CIRCULATE, 2: FAN_ON}
|
||||||
|
|
||||||
FAN_MODE_TO_CODE = {v: k for k, v in CODE_TO_FAN_MODE.items()}
|
FAN_MODE_TO_CODE = {v: k for k, v in CODE_TO_FAN_MODE.items()}
|
||||||
|
|
||||||
# Active thermostat state (is it heating or cooling?). In the future
|
# Active thermostat state (is it heating or cooling?). In the future
|
||||||
# this should probably made into heat and cool binary sensors.
|
# this should probably made into heat and cool binary sensors.
|
||||||
CODE_TO_TEMP_STATE = {0: CURRENT_HVAC_IDLE, 1: CURRENT_HVAC_HEAT, 2: CURRENT_HVAC_COOL}
|
CODE_TO_TEMP_STATE = {0: HVACAction.IDLE, 1: HVACAction.HEATING, 2: HVACAction.COOLING}
|
||||||
|
|
||||||
# Active fan state. This is if the fan is actually on or not. In the
|
# Active fan state. This is if the fan is actually on or not. In the
|
||||||
# future this should probably made into a binary sensor for the fan.
|
# future this should probably made into a binary sensor for the fan.
|
||||||
|
@ -139,6 +131,7 @@ def setup_platform(
|
||||||
class RadioThermostat(ClimateEntity):
|
class RadioThermostat(ClimateEntity):
|
||||||
"""Representation of a Radio Thermostat."""
|
"""Representation of a Radio Thermostat."""
|
||||||
|
|
||||||
|
_attr_hvac_modes = OPERATION_LIST
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
ClimateEntityFeature.TARGET_TEMPERATURE
|
ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
| ClimateEntityFeature.FAN_MODE
|
| ClimateEntityFeature.FAN_MODE
|
||||||
|
@ -151,12 +144,12 @@ class RadioThermostat(ClimateEntity):
|
||||||
self._target_temperature = None
|
self._target_temperature = None
|
||||||
self._current_temperature = None
|
self._current_temperature = None
|
||||||
self._current_humidity = None
|
self._current_humidity = None
|
||||||
self._current_operation = HVAC_MODE_OFF
|
self._current_operation = HVACMode.OFF
|
||||||
self._name = None
|
self._name = None
|
||||||
self._fmode = None
|
self._fmode = None
|
||||||
self._fstate = None
|
self._fstate = None
|
||||||
self._tmode = None
|
self._tmode = None
|
||||||
self._tstate = None
|
self._tstate: HVACAction | None = None
|
||||||
self._hold_temp = hold_temp
|
self._hold_temp = hold_temp
|
||||||
self._hold_set = False
|
self._hold_set = False
|
||||||
self._prev_temp = None
|
self._prev_temp = None
|
||||||
|
@ -224,19 +217,14 @@ class RadioThermostat(ClimateEntity):
|
||||||
return self._current_humidity
|
return self._current_humidity
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self):
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""Return the current operation. head, cool idle."""
|
"""Return the current operation. head, cool idle."""
|
||||||
return self._current_operation
|
return self._current_operation
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_modes(self):
|
def hvac_action(self) -> HVACAction | None:
|
||||||
"""Return the operation modes list."""
|
|
||||||
return OPERATION_LIST
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_action(self):
|
|
||||||
"""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 self._tstate
|
return self._tstate
|
||||||
|
|
||||||
|
@ -313,20 +301,20 @@ class RadioThermostat(ClimateEntity):
|
||||||
self._hold_set = CODE_TO_HOLD_STATE[data["hold"]]
|
self._hold_set = CODE_TO_HOLD_STATE[data["hold"]]
|
||||||
|
|
||||||
self._current_operation = self._tmode
|
self._current_operation = self._tmode
|
||||||
if self._tmode == HVAC_MODE_COOL:
|
if self._tmode == HVACMode.COOL:
|
||||||
self._target_temperature = data["t_cool"]
|
self._target_temperature = data["t_cool"]
|
||||||
elif self._tmode == HVAC_MODE_HEAT:
|
elif self._tmode == HVACMode.HEAT:
|
||||||
self._target_temperature = data["t_heat"]
|
self._target_temperature = data["t_heat"]
|
||||||
elif self._tmode == HVAC_MODE_AUTO:
|
elif self._tmode == HVACMode.AUTO:
|
||||||
# This doesn't really work - tstate is only set if the HVAC is
|
# This doesn't really work - tstate is only set if the HVAC is
|
||||||
# active. If it's idle, we don't know what to do with the target
|
# active. If it's idle, we don't know what to do with the target
|
||||||
# temperature.
|
# temperature.
|
||||||
if self._tstate == CURRENT_HVAC_COOL:
|
if self._tstate == HVACAction.COOLING:
|
||||||
self._target_temperature = data["t_cool"]
|
self._target_temperature = data["t_cool"]
|
||||||
elif self._tstate == CURRENT_HVAC_HEAT:
|
elif self._tstate == HVACAction.HEATING:
|
||||||
self._target_temperature = data["t_heat"]
|
self._target_temperature = data["t_heat"]
|
||||||
else:
|
else:
|
||||||
self._current_operation = HVAC_MODE_OFF
|
self._current_operation = HVACMode.OFF
|
||||||
|
|
||||||
def set_temperature(self, **kwargs):
|
def set_temperature(self, **kwargs):
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
|
@ -335,14 +323,14 @@ class RadioThermostat(ClimateEntity):
|
||||||
|
|
||||||
temperature = round_temp(temperature)
|
temperature = round_temp(temperature)
|
||||||
|
|
||||||
if self._current_operation == HVAC_MODE_COOL:
|
if self._current_operation == HVACMode.COOL:
|
||||||
self.device.t_cool = temperature
|
self.device.t_cool = temperature
|
||||||
elif self._current_operation == HVAC_MODE_HEAT:
|
elif self._current_operation == HVACMode.HEAT:
|
||||||
self.device.t_heat = temperature
|
self.device.t_heat = temperature
|
||||||
elif self._current_operation == HVAC_MODE_AUTO:
|
elif self._current_operation == HVACMode.AUTO:
|
||||||
if self._tstate == CURRENT_HVAC_COOL:
|
if self._tstate == HVACAction.COOLING:
|
||||||
self.device.t_cool = temperature
|
self.device.t_cool = temperature
|
||||||
elif self._tstate == CURRENT_HVAC_HEAT:
|
elif self._tstate == HVACAction.HEATING:
|
||||||
self.device.t_heat = temperature
|
self.device.t_heat = temperature
|
||||||
|
|
||||||
# Only change the hold if requested or if hold mode was turned
|
# Only change the hold if requested or if hold mode was turned
|
||||||
|
@ -365,15 +353,15 @@ class RadioThermostat(ClimateEntity):
|
||||||
"minute": now.minute,
|
"minute": now.minute,
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_hvac_mode(self, hvac_mode):
|
def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Set operation mode (auto, cool, heat, off)."""
|
"""Set operation mode (auto, cool, heat, off)."""
|
||||||
if hvac_mode in (HVAC_MODE_OFF, HVAC_MODE_AUTO):
|
if hvac_mode in (HVACMode.OFF, HVACMode.AUTO):
|
||||||
self.device.tmode = TEMP_MODE_TO_CODE[hvac_mode]
|
self.device.tmode = TEMP_MODE_TO_CODE[hvac_mode]
|
||||||
|
|
||||||
# Setting t_cool or t_heat automatically changes tmode.
|
# Setting t_cool or t_heat automatically changes tmode.
|
||||||
elif hvac_mode == HVAC_MODE_COOL:
|
elif hvac_mode == HVACMode.COOL:
|
||||||
self.device.t_cool = self._target_temperature
|
self.device.t_cool = self._target_temperature
|
||||||
elif hvac_mode == HVAC_MODE_HEAT:
|
elif hvac_mode == HVACMode.HEAT:
|
||||||
self.device.t_heat = self._target_temperature
|
self.device.t_heat = self._target_temperature
|
||||||
|
|
||||||
def set_preset_mode(self, preset_mode):
|
def set_preset_mode(self, preset_mode):
|
||||||
|
|
Loading…
Reference in New Issue