Skip to content

Commit c02f63e

Browse files
authored
Merge pull request #229 from plugwise/same-setpoint
Fix for plugwise/plugwise-beta#309
2 parents 2e67e54 + 45bd521 commit c02f63e

File tree

5 files changed

+104
-104
lines changed

5 files changed

+104
-104
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Changelog
22

3+
# v0.25.3: Bugfix for https://github.com/plugwise/plugwise-beta/issues/309
4+
35
# v0.25.2: Bugfix, code improvements
46
- Fix a set_temperature() and heat_cool related bug
57

plugwise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Plugwise module."""
22

3-
__version__ = "0.25.2"
3+
__version__ = "0.25.3"
44

55
from plugwise.smile import Smile
66
from plugwise.stick import Stick

plugwise/helper.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ def _get_actuator_functionalities(xml: etree) -> DeviceData:
118118

119119
def schedules_temps(
120120
schedules: dict[str, dict[str, list[float]]], name: str
121-
) -> list[float] | None:
121+
) -> list[float]:
122122
"""Helper-function for schedules().
123123
Obtain the schedule temperature of the schedule.
124124
"""
125125
if name == NONE:
126-
return None # pragma: no cover
126+
return [] # pragma: no cover
127127

128128
schedule_list: list[tuple[int, dt.time, list[float]]] = []
129129
for period, temp in schedules[name].items():
@@ -153,7 +153,7 @@ def schedules_temps(
153153
if in_between(today, day_0, day_1, now, time_0, time_1):
154154
return schedule_list[i][2]
155155

156-
return None # pragma: no cover
156+
return [] # pragma: no cover
157157

158158

159159
def power_data_local_format(
@@ -329,7 +329,7 @@ def __init__(self) -> None:
329329
self._outdoor_temp: float
330330
self._reg_allowed_modes: list[str] = []
331331
self._schedule_old_states: dict[str, dict[str, str]] = {}
332-
self._sched_setpoints: list[float] | None = None
332+
self._sched_setpoints: list[float] = []
333333
self._smile_legacy = False
334334
self._status: etree
335335
self._stretch_v2 = False
@@ -738,7 +738,7 @@ def _match_locations(self) -> dict[str, ThermoLoc]:
738738

739739
self._all_appliances()
740740
for location_id, location_details in self._loc_data.items():
741-
for appliance_details in list(self._appl_data.values()):
741+
for appliance_details in self._appl_data.values():
742742
if appliance_details["location"] == location_id:
743743
location_details.update(
744744
{"master": None, "master_prio": 0, "slaves": set()}
@@ -1186,7 +1186,7 @@ def _preset(self, loc_id: str) -> str | None:
11861186

11871187
def _schedules_legacy(
11881188
self, avail: list[str], sel: str
1189-
) -> tuple[list[str], str, None, None]:
1189+
) -> tuple[list[str], str, list[float], None]:
11901190
"""Helper-function for _schedules().
11911191
Collect available schedules/schedules for the legacy thermostat.
11921192
"""
@@ -1209,19 +1209,19 @@ def _schedules_legacy(
12091209
if active:
12101210
sel = name
12111211

1212-
return avail, sel, None, None
1212+
return avail, sel, [], None
12131213

12141214
def _schedules(
12151215
self, location: str
1216-
) -> tuple[list[str], str, list[float] | None, str | None]:
1216+
) -> tuple[list[str], str, list[float], str | None]:
12171217
"""Helper-function for smile.py: _device_data_climate().
12181218
Obtain the available schedules/schedules. Adam: a schedule can be connected to more than one location.
12191219
NEW: when a location_id is present then the schedule is active. Valid for both Adam and non-legacy Anna.
12201220
"""
12211221
available: list[str] = [NONE]
12221222
last_used: str | None = None
12231223
rule_ids: dict[str, str] = {}
1224-
schedule_temperatures: list[float] | None = None
1224+
schedule_temperatures: list[float] = []
12251225
selected = NONE
12261226

12271227
# Legacy Anna schedule, only one schedule allowed

plugwise/smile.py

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -52,51 +52,50 @@
5252
class SmileData(SmileHelper):
5353
"""The Plugwise Smile main class."""
5454

55-
def update_for_cooling(self, devices: dict[str, DeviceData]) -> None:
55+
def update_for_cooling(self, device: DeviceData) -> None:
5656
"""Helper-function for adding/updating various cooling-related values."""
57-
for device in list(devices.values()):
58-
# For Adam + on/off cooling, modify heating_state and cooling_state
59-
# based on provided info by Plugwise
60-
if (
61-
self.smile_name == "Adam"
62-
and device["dev_class"] == "heater_central"
63-
and self._on_off_device
64-
and self._cooling_active
65-
and device["binary_sensors"]["heating_state"]
66-
):
67-
device["binary_sensors"]["cooling_state"] = True
68-
device["binary_sensors"]["heating_state"] = False
69-
70-
# Add setpoint_low and setpoint_high when cooling is enabled
71-
if device["dev_class"] not in ZONE_THERMOSTATS:
72-
continue
73-
74-
# For heating + cooling, replace setpoint with setpoint_high/_low
75-
if self._cooling_present:
76-
thermostat = device["thermostat"]
77-
sensors = device["sensors"]
78-
max_setpoint = MAX_SETPOINT
79-
min_setpoint = MIN_SETPOINT
80-
if self._sched_setpoints is not None:
81-
max_setpoint = self._sched_setpoints[1]
82-
min_setpoint = self._sched_setpoints[0]
83-
84-
temp_dict: ActuatorData = {
85-
"setpoint_low": thermostat["setpoint"],
86-
"setpoint_high": max_setpoint,
57+
# For Adam + on/off cooling, modify heating_state and cooling_state
58+
# based on provided info by Plugwise
59+
if (
60+
self.smile_name == "Adam"
61+
and device["dev_class"] == "heater_central"
62+
and self._on_off_device
63+
and self._cooling_active
64+
and device["binary_sensors"]["heating_state"]
65+
):
66+
device["binary_sensors"]["cooling_state"] = True
67+
device["binary_sensors"]["heating_state"] = False
68+
69+
# Add setpoint_low and setpoint_high when cooling is enabled
70+
if device["dev_class"] not in ZONE_THERMOSTATS:
71+
return
72+
73+
# For heating + cooling, replace setpoint with setpoint_high/_low
74+
if self._cooling_present:
75+
thermostat = device["thermostat"]
76+
sensors = device["sensors"]
77+
max_setpoint = MAX_SETPOINT
78+
min_setpoint = MIN_SETPOINT
79+
if device["selected_schedule"] != "None":
80+
max_setpoint = self._sched_setpoints[1]
81+
min_setpoint = self._sched_setpoints[0]
82+
83+
temp_dict: ActuatorData = {
84+
"setpoint_low": thermostat["setpoint"],
85+
"setpoint_high": max_setpoint,
86+
}
87+
if self._cooling_enabled:
88+
temp_dict = {
89+
"setpoint_low": min_setpoint,
90+
"setpoint_high": thermostat["setpoint"],
8791
}
88-
if self._cooling_active:
89-
temp_dict = {
90-
"setpoint_low": min_setpoint,
91-
"setpoint_high": thermostat["setpoint"],
92-
}
93-
if "setpoint" in sensors:
94-
sensors.pop("setpoint")
95-
sensors["setpoint_low"] = temp_dict["setpoint_low"]
96-
sensors["setpoint_high"] = temp_dict["setpoint_high"]
97-
thermostat.pop("setpoint")
98-
temp_dict.update(thermostat)
99-
device["thermostat"] = temp_dict
92+
thermostat.pop("setpoint")
93+
temp_dict.update(thermostat)
94+
device["thermostat"] = temp_dict
95+
if "setpoint" in sensors:
96+
sensors.pop("setpoint")
97+
sensors["setpoint_low"] = temp_dict["setpoint_low"]
98+
sensors["setpoint_high"] = temp_dict["setpoint_high"]
10099

101100
def _all_device_data(self) -> None:
102101
"""Helper-function for get_all_devices().
@@ -111,8 +110,8 @@ def _all_device_data(self) -> None:
111110
device_id, data, device, bs_dict, s_dict, sw_dict
112111
)
113112

114-
# After all device data has been determined, add/update for cooling
115-
self.update_for_cooling(self.gw_devices)
113+
# Update for cooling
114+
self.update_for_cooling(self.gw_devices[device_id])
116115

117116
self.gw_data.update(
118117
{"smile_name": self.smile_name, "gateway_id": self.gateway_id}
@@ -255,16 +254,16 @@ def _check_availability(
255254
# OpenTherm device
256255
if details["dev_class"] == "heater_central" and details["name"] != "OnOff":
257256
device_data["available"] = True
258-
for data in list(self._notifications.values()):
259-
for msg in list(data.values()):
257+
for data in self._notifications.values():
258+
for msg in data.values():
260259
if "no OpenTherm communication" in msg:
261260
device_data["available"] = False
262261

263262
# Smartmeter
264263
if details["dev_class"] == "smartmeter":
265264
device_data["available"] = True
266-
for data in list(self._notifications.values()):
267-
for msg in list(data.values()):
265+
for data in self._notifications.values():
266+
for msg in data.values():
268267
if "P1 does not seem to be connected to a smart meter" in msg:
269268
device_data["available"] = False
270269

@@ -551,7 +550,7 @@ async def async_update(self) -> list[GatewayData | dict[str, DeviceData]]:
551550

552551
for dev_id, dev_dict in self.gw_devices.items():
553552
data = self._get_device_data(dev_id)
554-
for key, value in list(data.items()):
553+
for key, value in data.items():
555554
if key in dev_dict:
556555
dev_dict[key] = value # type: ignore [literal-required]
557556

@@ -560,7 +559,7 @@ async def async_update(self) -> list[GatewayData | dict[str, DeviceData]]:
560559
if item == "binary_sensors":
561560
notifs = self._notifications
562561
if item in dev_dict:
563-
for key, value in list(data.items()):
562+
for key, value in data.items():
564563
update_helper(
565564
data,
566565
self.gw_devices,
@@ -571,8 +570,8 @@ async def async_update(self) -> list[GatewayData | dict[str, DeviceData]]:
571570
notifs,
572571
)
573572

574-
# After all device data has been determined, add/update for cooling
575-
self.update_for_cooling(self.gw_devices)
573+
# Update for cooling
574+
self.update_for_cooling(dev_dict)
576575

577576
return [self.gw_data, self.gw_devices]
578577

0 commit comments

Comments
 (0)