Use climate enums in ecobee (#70632)
This commit is contained in:
parent
2267e32114
commit
7b1d5fb10a
1 changed files with 42 additions and 47 deletions
|
@ -5,23 +5,17 @@ import collections
|
||||||
|
|
||||||
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 (
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
CURRENT_HVAC_COOL,
|
|
||||||
CURRENT_HVAC_DRY,
|
|
||||||
CURRENT_HVAC_FAN,
|
|
||||||
CURRENT_HVAC_HEAT,
|
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
FAN_AUTO,
|
FAN_AUTO,
|
||||||
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.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -29,6 +23,7 @@ from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
PRECISION_HALVES,
|
PRECISION_HALVES,
|
||||||
PRECISION_TENTHS,
|
PRECISION_TENTHS,
|
||||||
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
)
|
)
|
||||||
|
@ -74,29 +69,29 @@ HUMIDIFIER_MANUAL_MODE = "manual"
|
||||||
# Order matters, because for reverse mapping we don't want to map HEAT to AUX
|
# Order matters, because for reverse mapping we don't want to map HEAT to AUX
|
||||||
ECOBEE_HVAC_TO_HASS = collections.OrderedDict(
|
ECOBEE_HVAC_TO_HASS = collections.OrderedDict(
|
||||||
[
|
[
|
||||||
("heat", HVAC_MODE_HEAT),
|
("heat", HVACMode.HEAT),
|
||||||
("cool", HVAC_MODE_COOL),
|
("cool", HVACMode.COOL),
|
||||||
("auto", HVAC_MODE_HEAT_COOL),
|
("auto", HVACMode.HEAT_COOL),
|
||||||
("off", HVAC_MODE_OFF),
|
("off", HVACMode.OFF),
|
||||||
("auxHeatOnly", HVAC_MODE_HEAT),
|
("auxHeatOnly", HVACMode.HEAT),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
ECOBEE_HVAC_ACTION_TO_HASS = {
|
ECOBEE_HVAC_ACTION_TO_HASS = {
|
||||||
# Map to None if we do not know how to represent.
|
# Map to None if we do not know how to represent.
|
||||||
"heatPump": CURRENT_HVAC_HEAT,
|
"heatPump": HVACAction.HEATING,
|
||||||
"heatPump2": CURRENT_HVAC_HEAT,
|
"heatPump2": HVACAction.HEATING,
|
||||||
"heatPump3": CURRENT_HVAC_HEAT,
|
"heatPump3": HVACAction.HEATING,
|
||||||
"compCool1": CURRENT_HVAC_COOL,
|
"compCool1": HVACAction.COOLING,
|
||||||
"compCool2": CURRENT_HVAC_COOL,
|
"compCool2": HVACAction.COOLING,
|
||||||
"auxHeat1": CURRENT_HVAC_HEAT,
|
"auxHeat1": HVACAction.HEATING,
|
||||||
"auxHeat2": CURRENT_HVAC_HEAT,
|
"auxHeat2": HVACAction.HEATING,
|
||||||
"auxHeat3": CURRENT_HVAC_HEAT,
|
"auxHeat3": HVACAction.HEATING,
|
||||||
"fan": CURRENT_HVAC_FAN,
|
"fan": HVACAction.FAN,
|
||||||
"humidifier": None,
|
"humidifier": None,
|
||||||
"dehumidifier": CURRENT_HVAC_DRY,
|
"dehumidifier": HVACAction.DRYING,
|
||||||
"ventilator": CURRENT_HVAC_FAN,
|
"ventilator": HVACAction.FAN,
|
||||||
"economizer": CURRENT_HVAC_FAN,
|
"economizer": HVACAction.FAN,
|
||||||
"compHotWater": None,
|
"compHotWater": None,
|
||||||
"auxHotWater": None,
|
"auxHotWater": None,
|
||||||
}
|
}
|
||||||
|
@ -314,19 +309,19 @@ class Thermostat(ClimateEntity):
|
||||||
self.thermostat = thermostat
|
self.thermostat = thermostat
|
||||||
self._name = self.thermostat["name"]
|
self._name = self.thermostat["name"]
|
||||||
self.vacation = None
|
self.vacation = None
|
||||||
self._last_active_hvac_mode = HVAC_MODE_HEAT_COOL
|
self._last_active_hvac_mode = HVACMode.HEAT_COOL
|
||||||
|
|
||||||
self._operation_list = []
|
self._operation_list = []
|
||||||
if (
|
if (
|
||||||
self.thermostat["settings"]["heatStages"]
|
self.thermostat["settings"]["heatStages"]
|
||||||
or self.thermostat["settings"]["hasHeatPump"]
|
or self.thermostat["settings"]["hasHeatPump"]
|
||||||
):
|
):
|
||||||
self._operation_list.append(HVAC_MODE_HEAT)
|
self._operation_list.append(HVACMode.HEAT)
|
||||||
if self.thermostat["settings"]["coolStages"]:
|
if self.thermostat["settings"]["coolStages"]:
|
||||||
self._operation_list.append(HVAC_MODE_COOL)
|
self._operation_list.append(HVACMode.COOL)
|
||||||
if len(self._operation_list) == 2:
|
if len(self._operation_list) == 2:
|
||||||
self._operation_list.insert(0, HVAC_MODE_HEAT_COOL)
|
self._operation_list.insert(0, HVACMode.HEAT_COOL)
|
||||||
self._operation_list.append(HVAC_MODE_OFF)
|
self._operation_list.append(HVACMode.OFF)
|
||||||
|
|
||||||
self._preset_modes = {
|
self._preset_modes = {
|
||||||
comfort["climateRef"]: comfort["name"]
|
comfort["climateRef"]: comfort["name"]
|
||||||
|
@ -343,7 +338,7 @@ class Thermostat(ClimateEntity):
|
||||||
else:
|
else:
|
||||||
await self.data.update()
|
await self.data.update()
|
||||||
self.thermostat = self.data.ecobee.get_thermostat(self.thermostat_index)
|
self.thermostat = self.data.ecobee.get_thermostat(self.thermostat_index)
|
||||||
if self.hvac_mode != HVAC_MODE_OFF:
|
if self.hvac_mode != HVACMode.OFF:
|
||||||
self._last_active_hvac_mode = self.hvac_mode
|
self._last_active_hvac_mode = self.hvac_mode
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -403,14 +398,14 @@ class Thermostat(ClimateEntity):
|
||||||
@property
|
@property
|
||||||
def target_temperature_low(self) -> float | None:
|
def target_temperature_low(self) -> float | None:
|
||||||
"""Return the lower bound temperature we try to reach."""
|
"""Return the lower bound temperature we try to reach."""
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
|
if self.hvac_mode == HVACMode.HEAT_COOL:
|
||||||
return self.thermostat["runtime"]["desiredHeat"] / 10.0
|
return self.thermostat["runtime"]["desiredHeat"] / 10.0
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_high(self) -> float | None:
|
def target_temperature_high(self) -> float | None:
|
||||||
"""Return the upper bound temperature we try to reach."""
|
"""Return the upper bound temperature we try to reach."""
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
|
if self.hvac_mode == HVACMode.HEAT_COOL:
|
||||||
return self.thermostat["runtime"]["desiredCool"] / 10.0
|
return self.thermostat["runtime"]["desiredCool"] / 10.0
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -447,11 +442,11 @@ class Thermostat(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_HEAT_COOL:
|
if self.hvac_mode == HVACMode.HEAT_COOL:
|
||||||
return None
|
return None
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT:
|
if self.hvac_mode == HVACMode.HEAT:
|
||||||
return self.thermostat["runtime"]["desiredHeat"] / 10.0
|
return self.thermostat["runtime"]["desiredHeat"] / 10.0
|
||||||
if self.hvac_mode == HVAC_MODE_COOL:
|
if self.hvac_mode == HVACMode.COOL:
|
||||||
return self.thermostat["runtime"]["desiredCool"] / 10.0
|
return self.thermostat["runtime"]["desiredCool"] / 10.0
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -460,7 +455,7 @@ class Thermostat(ClimateEntity):
|
||||||
"""Return the current fan status."""
|
"""Return the current fan status."""
|
||||||
if "fan" in self.thermostat["equipmentStatus"]:
|
if "fan" in self.thermostat["equipmentStatus"]:
|
||||||
return STATE_ON
|
return STATE_ON
|
||||||
return HVAC_MODE_OFF
|
return STATE_OFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_mode(self):
|
def fan_mode(self):
|
||||||
|
@ -521,7 +516,7 @@ class Thermostat(ClimateEntity):
|
||||||
We are unable to map all actions to HA equivalents.
|
We are unable to map all actions to HA equivalents.
|
||||||
"""
|
"""
|
||||||
if self.thermostat["equipmentStatus"] == "":
|
if self.thermostat["equipmentStatus"] == "":
|
||||||
return CURRENT_HVAC_IDLE
|
return HVACAction.IDLE
|
||||||
|
|
||||||
actions = [
|
actions = [
|
||||||
ECOBEE_HVAC_ACTION_TO_HASS[status]
|
ECOBEE_HVAC_ACTION_TO_HASS[status]
|
||||||
|
@ -530,15 +525,15 @@ class Thermostat(ClimateEntity):
|
||||||
]
|
]
|
||||||
|
|
||||||
for action in (
|
for action in (
|
||||||
CURRENT_HVAC_HEAT,
|
HVACAction.HEATING,
|
||||||
CURRENT_HVAC_COOL,
|
HVACAction.COOLING,
|
||||||
CURRENT_HVAC_DRY,
|
HVACAction.DRYING,
|
||||||
CURRENT_HVAC_FAN,
|
HVACAction.FAN,
|
||||||
):
|
):
|
||||||
if action in actions:
|
if action in actions:
|
||||||
return action
|
return action
|
||||||
|
|
||||||
return CURRENT_HVAC_IDLE
|
return HVACAction.IDLE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
|
@ -685,7 +680,7 @@ class Thermostat(ClimateEntity):
|
||||||
heatCoolMinDelta property.
|
heatCoolMinDelta property.
|
||||||
https://www.ecobee.com/home/developer/api/examples/ex5.shtml
|
https://www.ecobee.com/home/developer/api/examples/ex5.shtml
|
||||||
"""
|
"""
|
||||||
if self.hvac_mode in (HVAC_MODE_HEAT, HVAC_MODE_COOL):
|
if self.hvac_mode in (HVACMode.HEAT, HVACMode.COOL):
|
||||||
heat_temp = temp
|
heat_temp = temp
|
||||||
cool_temp = temp
|
cool_temp = temp
|
||||||
else:
|
else:
|
||||||
|
@ -700,7 +695,7 @@ class Thermostat(ClimateEntity):
|
||||||
high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
||||||
temp = kwargs.get(ATTR_TEMPERATURE)
|
temp = kwargs.get(ATTR_TEMPERATURE)
|
||||||
|
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT_COOL and (
|
if self.hvac_mode == HVACMode.HEAT_COOL and (
|
||||||
low_temp is not None or high_temp is not None
|
low_temp is not None or high_temp is not None
|
||||||
):
|
):
|
||||||
self.set_auto_temp_hold(low_temp, high_temp)
|
self.set_auto_temp_hold(low_temp, high_temp)
|
||||||
|
|
Loading…
Add table
Reference in a new issue