Skip to content

Commit d532e13

Browse files
committed
Add ThermoZone for Anna
1 parent ca34ffa commit d532e13

File tree

3 files changed

+21
-40
lines changed

3 files changed

+21
-40
lines changed

plugwise/data.py

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _all_entity_data(self) -> None:
3535
Collect data for each entity and add to self.gw_entities.
3636
"""
3737
self._update_gw_entities()
38-
if self.check_name(ADAM):
38+
if self._is_thermostat:
3939
self._update_zones()
4040
self.gw_entities.update(self._zones)
4141

@@ -48,6 +48,8 @@ def _update_zones(self) -> None:
4848
data = self._get_location_data(location_id)
4949
zone.update(data)
5050

51+
self._update_for_cooling(zone)
52+
5153
def _update_gw_entities(self) -> None:
5254
"""Helper-function for _all_entities_data() and async_update().
5355
@@ -76,8 +78,6 @@ def _update_gw_entities(self) -> None:
7678
if is_battery_low:
7779
entity["binary_sensors"]["low_battery"] = True
7880

79-
self._update_for_cooling(entity)
80-
8181
remove_empty_platform_dicts(entity)
8282

8383
def _detect_low_batteries(self) -> list[str]:
@@ -126,7 +126,7 @@ def _update_for_cooling(self, entity: GwEntityData) -> None:
126126
if (
127127
self.check_name(ANNA)
128128
and self._cooling_present
129-
and entity["dev_class"] == "thermostat"
129+
and entity["dev_class"] == "climate"
130130
):
131131
thermostat = entity["thermostat"]
132132
sensors = entity["sensors"]
@@ -142,11 +142,9 @@ def _update_for_cooling(self, entity: GwEntityData) -> None:
142142
thermostat.pop("setpoint")
143143
temp_dict.update(thermostat)
144144
entity["thermostat"] = temp_dict
145-
if "setpoint" in sensors:
146-
sensors.pop("setpoint")
147145
sensors["setpoint_low"] = temp_dict["setpoint_low"]
148146
sensors["setpoint_high"] = temp_dict["setpoint_high"]
149-
self._count += 2 # add 4, remove 2
147+
self._count += 3 # add 4, remove 1
150148

151149
def _get_location_data(self, loc_id: str) -> GwEntityData:
152150
"""Helper-function for _all_entity_data() and async_update().
@@ -197,11 +195,6 @@ def _get_entity_data(self, entity_id: str) -> GwEntityData:
197195
if self.check_name(ADAM):
198196
self._get_adam_data(entity, data)
199197

200-
# Thermostat data for Anna (presets, temperatures etc)
201-
if self.check_name(ANNA) and entity["dev_class"] == "thermostat":
202-
self._climate_data(entity_id, entity, data)
203-
self._get_anna_control_state(data)
204-
205198
return data
206199

207200
def _check_availability(
@@ -249,16 +242,12 @@ def _get_adam_data(self, entity: GwEntityData, data: GwEntityData) -> None:
249242
self._count += 1
250243

251244
def _climate_data(
252-
self, location_id: str, entity: GwEntityData, data: GwEntityData
245+
self, loc_id: str, entity: GwEntityData, data: GwEntityData
253246
) -> None:
254247
"""Helper-function for _get_entity_data().
255248
256249
Determine climate-control entity data.
257250
"""
258-
loc_id = location_id
259-
if entity.get("location") is not None:
260-
loc_id = entity["location"]
261-
262251
# Presets
263252
data["preset_modes"] = None
264253
data["active_preset"] = None
@@ -301,20 +290,6 @@ def check_reg_mode(self, mode: str) -> bool:
301290
"regulation_modes" in gateway and gateway["select_regulation_mode"] == mode
302291
)
303292

304-
def _get_anna_control_state(self, data: GwEntityData) -> None:
305-
"""Set the thermostat control_state based on the opentherm/onoff device state."""
306-
data["control_state"] = "idle"
307-
self._count += 1
308-
for entity in self.gw_entities.values():
309-
if entity["dev_class"] != "heater_central":
310-
continue
311-
312-
binary_sensors = entity["binary_sensors"]
313-
if binary_sensors["heating_state"]:
314-
data["control_state"] = "heating"
315-
if binary_sensors.get("cooling_state"):
316-
data["control_state"] = "cooling"
317-
318293
def _get_schedule_states_with_off(
319294
self, location: str, schedules: list[str], selected: str, data: GwEntityData
320295
) -> None:

plugwise/helper.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def _get_actuator_functionalities(
468468
item == "thermostat"
469469
and (
470470
entity["dev_class"] != "climate"
471-
if self.check_name(ADAM)
471+
if self._is_thermostat
472472
else entity["dev_class"] != "thermostat"
473473
)
474474
):
@@ -773,19 +773,19 @@ def _rank_thermostat(
773773
thermo_loc["secondary"].append(appliance_id)
774774

775775
def _control_state(self, data: GwEntityData, loc_id: str) -> str | bool:
776-
"""Helper-function for _get_adam_data().
776+
"""Helper-function for _get_location_data().
777777
778-
Adam: find the thermostat control_state of a location, from DOMAIN_OBJECTS.
778+
Adam & Anna: find the thermostat control_state of a location, from DOMAIN_OBJECTS.
779779
Represents the heating/cooling demand-state of the local primary thermostat.
780780
Note: heating or cooling can still be active when the setpoint has been reached.
781781
"""
782782
locator = f'location[@id="{loc_id}"]/actuator_functionalities/thermostat_functionality[type="thermostat"]/control_state'
783783
if (ctrl_state := self._domain_objects.find(locator)) is not None:
784784
return str(ctrl_state.text)
785785

786-
# Handle missing control_state in regulation_mode off for firmware >= 3.2.0 (issue #776)
786+
# Adam: handle missing control_state in regulation_mode off for firmware >= 3.2.0 (issue #776)
787787
# In newer firmware versions, default to "off" when control_state is not present
788-
if self.smile.version != version.Version("0.0.0"):
788+
if self.check_name(ADAM) and self.smile.version != version.Version("0.0.0"):
789789
if self.smile.version >= version.parse("3.2.0"):
790790
return "off"
791791

@@ -794,7 +794,15 @@ def _control_state(self, data: GwEntityData, loc_id: str) -> str | bool:
794794
setpoint = data["sensors"]["setpoint"]
795795
temperature = data["sensors"]["temperature"]
796796
# No cooling available in older firmware
797-
return "heating" if temperature < setpoint else "off"
797+
return "heating" if temperature < setpoint else "idle"
798+
799+
if self.check_name(ANNA):
800+
# Older Anna firmware does not have the control_state xml-key
801+
# Work around this by comparing the reported temperature and setpoint for a location
802+
setpoint = data["sensors"]["setpoint"]
803+
temperature = data["sensors"]["temperature"]
804+
# No cooling available in older firmware
805+
return "heating" if temperature < setpoint else "idle"
798806

799807
return False # pragma: no cover
800808

plugwise/smile.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import Any, cast
1111

1212
from plugwise.constants import (
13-
ADAM,
1413
ANNA,
1514
APPLIANCES,
1615
DOMAIN_OBJECTS,
@@ -113,8 +112,7 @@ def get_all_gateway_entities(self) -> None:
113112
self.therms_with_offset_func = (
114113
self._get_appliances_with_offset_functionality()
115114
)
116-
if self.check_name(ADAM):
117-
self._scan_thermostats()
115+
self._scan_thermostats()
118116

119117
if group_data := self._get_group_switches():
120118
self.gw_entities.update(group_data)

0 commit comments

Comments
 (0)