Skip to content

Commit 9993fad

Browse files
committed
Split off _get_schedule_states_with_off() function
1 parent 2078c53 commit 9993fad

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

plugwise/__init__.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,6 @@ def _device_data_adam(
203203

204204
return device_data
205205

206-
def check_reg_mode(self, mode: str) -> bool:
207-
"""Helper-function for device_data_climate()."""
208-
gateway = self.gw_devices[self.gateway_id]
209-
return (
210-
"regulation_modes" in gateway and gateway["select_regulation_mode"] == mode
211-
)
212-
213206
def _device_data_climate(
214207
self, device: DeviceData, device_data: DeviceData
215208
) -> DeviceData:
@@ -251,27 +244,45 @@ def _device_data_climate(
251244
if self.check_reg_mode("off"):
252245
device_data["mode"] = "off"
253246

254-
# Collect schedules with states for each thermostat
255-
if NONE not in avail_schedules:
247+
device_data = self._get_schedule_states_with_off(
248+
loc_id, avail_schedules, sel_schedule, device_data
249+
)
250+
251+
return device_data
252+
253+
def check_reg_mode(self, mode: str) -> bool:
254+
"""Helper-function for device_data_climate()."""
255+
gateway = self.gw_devices[self.gateway_id]
256+
return (
257+
"regulation_modes" in gateway and gateway["select_regulation_mode"] == mode
258+
)
259+
260+
def _get_schedule_states_with_off(
261+
self, location: str, schedules: list[str], selected: str, data: DeviceData
262+
) -> DeviceData:
263+
"""Collect schedules with states for each thermostat.
264+
265+
Also, replace NONE by OFF when none of the schedules are active,
266+
only for non-legacy thermostats.
267+
"""
268+
if NONE not in schedules:
256269
loc_schedule_states: dict[str, str] = {}
257-
for schedule in avail_schedules:
270+
for schedule in schedules:
258271
loc_schedule_states[schedule] = "off"
259-
if schedule == sel_schedule and device_data["mode"] == "auto":
272+
if schedule == selected and data["mode"] == "auto":
260273
loc_schedule_states[schedule] = "on"
261274

262-
self._schedule_old_states[loc_id] = loc_schedule_states
275+
self._schedule_old_states[location] = loc_schedule_states
263276

264-
# Replace NONE by OFF when none of the schedules are active,
265-
# only for non-legacy thermostats.
266277
all_off = True
267278
if not self._smile_legacy:
268-
for state in self._schedule_old_states[loc_id].values():
279+
for state in self._schedule_old_states[location].values():
269280
if state == "on":
270281
all_off = False
271282
if all_off:
272-
device_data["select_schedule"] = OFF
283+
data["select_schedule"] = OFF
273284

274-
return device_data
285+
return data
275286

276287
def _check_availability(
277288
self, device: DeviceData, device_data: DeviceData

0 commit comments

Comments
 (0)