Bugfix evohome (#26810)

* address issues #25984, #25985

* small tweak

* refactor - fix bugs, coding erros, consolidate

* some zones don't have schedules

* some zones don't have schedules 2

* some zones don't have schedules 3

* fix water_heater, add away mode

* readbility tweak

* bugfix: no refesh after state change

* bugfix: no refesh after state change 2

* temove dodgy wrappers (protected-access), fix until logic

* remove dodgy _set_zone_mode wrapper

* tweak

* tweak docstrings

* refactor as per PR review

* refactor as per PR review 3

* refactor to use dt_util

* small tweak

* tweak doc strings

* remove packet from _refresh

* set_temp() don't have until

* add unique_id

* add unique_id 2
This commit is contained in:
David Bonnes authored and Paulus Schoutsen committed 2019-09-30 21:35:10 -07:00
1 parent e2d7a01d65
commit a1997ee891
4 files changed
+315 -266

No files matched your search

+115 -125
View File
@@ -1,7 +1,6 @@
"""Support for Climate devices of (EMEA/EU-based) Honeywell TCC systems."""
from datetime import datetime
import logging
from typing import Any, Dict, Optional, List
from typing import Optional, List
from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate.const import (
@@ -22,7 +21,7 @@ from homeassistant.const import PRECISION_TENTHS
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from homeassistant.util.dt import parse_datetime
from . import CONF_LOCATION_IDX, EvoDevice
from . import CONF_LOCATION_IDX, EvoDevice, EvoChild
from .const import (
DOMAIN,
EVO_RESET,
@@ -61,6 +60,9 @@ EVO_PRESET_TO_HA = {
}
HA_PRESET_TO_EVO = {v: k for k, v in EVO_PRESET_TO_HA.items()}
STATE_ATTRS_TCS = ["systemId", "activeFaults", "systemModeStatus"]
STATE_ATTRS_ZONES = ["zoneId", "activeFaults", "setpointStatus", "temperatureStatus"]
async def async_setup_platform(
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
@@ -114,63 +116,20 @@ class EvoClimateDevice(EvoDevice, ClimateDevice):
"""Base for a Honeywell evohome Climate device."""
def __init__(self, evo_broker, evo_device) -> None:
"""Initialize the evohome Climate device."""
"""Initialize a Climate device."""
super().__init__(evo_broker, evo_device)
self._preset_modes = None
async def _set_temperature(
self, temperature: float, until: Optional[datetime] = None
) -> None:
"""Set a new target temperature for the Zone.
until == None means indefinitely (i.e. PermanentOverride)
"""
await self._call_client_api(
self._evo_device.set_temperature(temperature, until)
)
async def _set_zone_mode(self, op_mode: str) -> None:
"""Set a Zone to one of its native EVO_* operating modes.
Zones inherit their _effective_ operating mode from the Controller.
Usually, Zones are in 'FollowSchedule' mode, where their setpoints are
a function of their own schedule and the Controller's operating mode,
e.g. 'AutoWithEco' mode means their setpoint is (by default) 3C less
than scheduled.
However, Zones can _override_ these setpoints, either indefinitely,
'PermanentOverride' mode, or for a period of time, 'TemporaryOverride',
after which they will revert back to 'FollowSchedule'.
Finally, some of the Controller's operating modes are _forced_ upon the
Zones, regardless of any override mode, e.g. 'HeatingOff', Zones to
(by default) 5C, and 'Away', Zones to (by default) 12C.
"""
if op_mode == EVO_FOLLOW:
await self._call_client_api(self._evo_device.cancel_temp_override())
return
temperature = self._evo_device.setpointStatus["targetHeatTemperature"]
until = None # EVO_PERMOVER
if op_mode == EVO_TEMPOVER and self._schedule["DailySchedules"]:
await self._update_schedule()
if self._schedule["DailySchedules"]:
until = parse_datetime(self.setpoints["next"]["from"])
await self._set_temperature(temperature, until=until)
async def _set_tcs_mode(self, op_mode: str) -> None:
"""Set the Controller to any of its native EVO_* operating modes."""
"""Set a Controller to any of its native EVO_* operating modes."""
await self._call_client_api(
self._evo_tcs._set_status(op_mode) # pylint: disable=protected-access
)
@property
def hvac_modes(self) -> List[str]:
"""Return the list of available hvac operation modes."""
"""Return a list of available hvac operation modes."""
return list(HA_HVAC_TO_TCS)
@property
@@ -179,36 +138,24 @@ class EvoClimateDevice(EvoDevice, ClimateDevice):
return self._preset_modes
class EvoZone(EvoClimateDevice):
class EvoZone(EvoChild, EvoClimateDevice):
"""Base for a Honeywell evohome Zone."""
def __init__(self, evo_broker, evo_device) -> None:
"""Initialize the evohome Zone."""
"""Initialize a Zone."""
super().__init__(evo_broker, evo_device)
self._unique_id = evo_device.zoneId
self._name = evo_device.name
self._icon = "mdi:radiator"
self._precision = self._evo_device.setpointCapabilities["valueResolution"]
self._state_attributes = [
"zoneId",
"activeFaults",
"setpointStatus",
"temperatureStatus",
"setpoints",
]
self._supported_features = SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE
self._preset_modes = list(HA_PRESET_TO_EVO)
@property
def available(self) -> bool:
"""Return True if entity is available."""
return self._evo_device.temperatureStatus["isAvailable"]
@property
def hvac_mode(self) -> str:
"""Return the current operating mode of the evohome Zone."""
"""Return the current operating mode of a Zone."""
if self._evo_tcs.systemModeStatus["mode"] in [EVO_AWAY, EVO_HEATOFF]:
return HVAC_MODE_AUTO
is_off = self.target_temperature <= self.min_temp
@@ -221,24 +168,15 @@ class EvoZone(EvoClimateDevice):
return CURRENT_HVAC_OFF
if self.target_temperature <= self.min_temp:
return CURRENT_HVAC_OFF
if self.target_temperature < self.current_temperature:
if not self._evo_device.temperatureStatus["isAvailable"]:
return None
if self.target_temperature <= self.current_temperature:
return CURRENT_HVAC_IDLE
return CURRENT_HVAC_HEAT
@property
def current_temperature(self) -> Optional[float]:
"""Return the current temperature of the evohome Zone."""
return (
self._evo_device.temperatureStatus["temperature"]
if self._evo_device.temperatureStatus["isAvailable"]
else None
)
@property
def target_temperature(self) -> float:
"""Return the target temperature of the evohome Zone."""
if self._evo_tcs.systemModeStatus["mode"] == EVO_HEATOFF:
return self._evo_device.setpointCapabilities["minHeatSetpoint"]
"""Return the target temperature of a Zone."""
return self._evo_device.setpointStatus["targetHeatTemperature"]
@property
@@ -252,7 +190,7 @@ class EvoZone(EvoClimateDevice):
@property
def min_temp(self) -> float:
"""Return the minimum target temperature of a evohome Zone.
"""Return the minimum target temperature of a Zone.
The default is 5, but is user-configurable within 5-35 (in Celsius).
"""
@@ -260,7 +198,7 @@ class EvoZone(EvoClimateDevice):
@property
def max_temp(self) -> float:
"""Return the maximum target temperature of a evohome Zone.
"""Return the maximum target temperature of a Zone.
The default is 35, but is user-configurable within 5-35 (in Celsius).
"""
@@ -268,26 +206,70 @@ class EvoZone(EvoClimateDevice):
async def async_set_temperature(self, **kwargs) -> None:
"""Set a new target temperature."""
until = kwargs.get("until")
if until:
until = parse_datetime(until)
temperature = kwargs["temperature"]
await self._set_temperature(kwargs["temperature"], until)
if self._evo_device.setpointStatus["setpointMode"] == EVO_FOLLOW:
await self._update_schedule()
until = parse_datetime(str(self.setpoints.get("next_sp_from")))
elif self._evo_device.setpointStatus["setpointMode"] == EVO_TEMPOVER:
until = parse_datetime(self._evo_device.setpointStatus["until"])
else: # EVO_PERMOVER
until = None
await self._call_client_api(
self._evo_device.set_temperature(temperature, until)
)
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set an operating mode for the Zone."""
if hvac_mode == HVAC_MODE_OFF:
await self._set_temperature(self.min_temp, until=None)
"""Set a Zone to one of its native EVO_* operating modes.
Zones inherit their _effective_ operating mode from their Controller.
Usually, Zones are in 'FollowSchedule' mode, where their setpoints are a
function of their own schedule and the Controller's operating mode, e.g.
'AutoWithEco' mode means their setpoint is (by default) 3C less than scheduled.
However, Zones can _override_ these setpoints, either indefinitely,
'PermanentOverride' mode, or for a set period of time, 'TemporaryOverride' mode
(after which they will revert back to 'FollowSchedule' mode).
Finally, some of the Controller's operating modes are _forced_ upon the Zones,
regardless of any override mode, e.g. 'HeatingOff', Zones to (by default) 5C,
and 'Away', Zones to (by default) 12C.
"""
if hvac_mode == HVAC_MODE_OFF:
await self._call_client_api(
self._evo_device.set_temperature(self.min_temp, until=None)
)
else: # HVAC_MODE_HEAT
await self._set_zone_mode(EVO_FOLLOW)
await self._call_client_api(self._evo_device.cancel_temp_override())
async def async_set_preset_mode(self, preset_mode: Optional[str]) -> None:
"""Set a new preset mode.
"""Set the preset mode; if None, then revert to following the schedule."""
evo_preset_mode = HA_PRESET_TO_EVO.get(preset_mode, EVO_FOLLOW)
If preset_mode is None, then revert to following the schedule.
"""
await self._set_zone_mode(HA_PRESET_TO_EVO.get(preset_mode, EVO_FOLLOW))
if evo_preset_mode == EVO_FOLLOW:
await self._call_client_api(self._evo_device.cancel_temp_override())
return
temperature = self._evo_device.setpointStatus["targetHeatTemperature"]
if evo_preset_mode == EVO_TEMPOVER:
await self._update_schedule()
until = parse_datetime(str(self.setpoints.get("next_sp_from")))
else: # EVO_PERMOVER
until = None
await self._call_client_api(
self._evo_device.set_temperature(temperature, until)
)
async def async_update(self) -> None:
"""Get the latest state data for a Zone."""
await super().async_update()
for attr in STATE_ATTRS_ZONES:
self._device_state_attrs[attr] = getattr(self._evo_device, attr)
class EvoController(EvoClimateDevice):
@@ -298,21 +280,20 @@ class EvoController(EvoClimateDevice):
"""
def __init__(self, evo_broker, evo_device) -> None:
"""Initialize the evohome Controller (hub)."""
"""Initialize a evohome Controller (hub)."""
super().__init__(evo_broker, evo_device)
self._unique_id = evo_device.systemId
self._name = evo_device.location.name
self._icon = "mdi:thermostat"
self._precision = PRECISION_TENTHS
self._state_attributes = ["systemId", "activeFaults", "systemModeStatus"]
self._supported_features = SUPPORT_PRESET_MODE
self._preset_modes = list(HA_PRESET_TO_TCS)
@property
def hvac_mode(self) -> str:
"""Return the current operating mode of the evohome Controller."""
"""Return the current operating mode of a Controller."""
tcs_mode = self._evo_tcs.systemModeStatus["mode"]
return HVAC_MODE_OFF if tcs_mode == EVO_HEATOFF else HVAC_MODE_HEAT
@@ -334,52 +315,53 @@ class EvoController(EvoClimateDevice):
"""Return the current preset mode, e.g., home, away, temp."""
return TCS_PRESET_TO_HA.get(self._evo_tcs.systemModeStatus["mode"])
async def async_set_temperature(self, **kwargs) -> None:
"""Do nothing.
@property
def min_temp(self) -> float:
"""Return None as Controllers don't have a target temperature."""
return None
The evohome Controller doesn't have a target temperature.
"""
return
@property
def max_temp(self) -> float:
"""Return None as Controllers don't have a target temperature."""
return None
async def async_set_temperature(self, **kwargs) -> None:
"""Raise exception as Controllers don't have a target temperature."""
raise NotImplementedError("Evohome Controllers don't have target temperatures.")
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set an operating mode for the Controller."""
"""Set an operating mode for a Controller."""
await self._set_tcs_mode(HA_HVAC_TO_TCS.get(hvac_mode))
async def async_set_preset_mode(self, preset_mode: Optional[str]) -> None:
"""Set a new preset mode.
If preset_mode is None, then revert to 'Auto' mode.
"""
"""Set the preset mode; if None, then revert to 'Auto' mode."""
await self._set_tcs_mode(HA_PRESET_TO_TCS.get(preset_mode, EVO_AUTO))
async def async_update(self) -> None:
"""Get the latest state data."""
return
"""Get the latest state data for a Controller."""
self._device_state_attrs = {}
attrs = self._device_state_attrs
for attr in STATE_ATTRS_TCS:
if attr == "activeFaults":
attrs["activeSystemFaults"] = getattr(self._evo_tcs, attr)
else:
attrs[attr] = getattr(self._evo_tcs, attr)
class EvoThermostat(EvoZone):
"""Base for a Honeywell Round Thermostat.
Implemented as a combined Controller/Zone.
These are implemented as a combined Controller/Zone.
"""
def __init__(self, evo_broker, evo_device) -> None:
"""Initialize the Round Thermostat."""
"""Initialize the Thermostat."""
super().__init__(evo_broker, evo_device)
self._name = evo_broker.tcs.location.name
self._preset_modes = [PRESET_AWAY, PRESET_ECO]
@property
def device_state_attributes(self) -> Dict[str, Any]:
"""Return the device-specific state attributes."""
status = super().device_state_attributes["status"]
status["systemModeStatus"] = self._evo_tcs.systemModeStatus
status["activeFaults"] += self._evo_tcs.activeFaults
return {"status": status}
@property
def hvac_mode(self) -> str:
"""Return the current operating mode."""
@@ -404,11 +386,19 @@ class EvoThermostat(EvoZone):
await self._set_tcs_mode(HA_HVAC_TO_TCS.get(hvac_mode))
async def async_set_preset_mode(self, preset_mode: Optional[str]) -> None:
"""Set a new preset mode.
If preset_mode is None, then revert to following the schedule.
"""
"""Set the preset mode; if None, then revert to following the schedule."""
if preset_mode in list(HA_PRESET_TO_TCS):
await self._set_tcs_mode(HA_PRESET_TO_TCS.get(preset_mode))
else:
await self._set_zone_mode(HA_PRESET_TO_EVO.get(preset_mode, EVO_FOLLOW))
await super().async_set_hvac_mode(preset_mode)
async def async_update(self) -> None:
"""Get the latest state data for the Thermostat."""
await super().async_update()
attrs = self._device_state_attrs
for attr in STATE_ATTRS_TCS:
if attr == "activeFaults": # self._evo_device also has "activeFaults"
attrs["activeSystemFaults"] = getattr(self._evo_tcs, attr)
else:
attrs[attr] = getattr(self._evo_tcs, attr)