Skip to content

Commit fb45b77

Browse files
committed
schema --> schedule
1 parent 7b90345 commit fb45b77

File tree

2 files changed

+58
-56
lines changed

2 files changed

+58
-56
lines changed

plugwise/helper.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,33 @@ def check_model(name: str, v_name: str) -> str:
9191
return name
9292

9393

94-
def schemas_schedule_temp(schedules: dict[str, Any], name: str) -> float | None:
95-
"""Helper-function for schemas().
96-
Obtain the schedule temperature of the schema/schedule.
94+
def schedules_schedule_temp(schedules: dict[str, Any], name: str) -> float | None:
95+
"""Helper-function for schedules().
96+
Obtain the schedule temperature of the schedule/schedule.
9797
"""
9898
if name == "None":
9999
return # pragma: no cover
100100

101-
schema_list: list[list[int, dt.time, float]] | None = []
101+
schedule_list: list[list[int, dt.time, float]] | None = []
102102
for period, temp in schedules[name].items():
103103
tmp_list: list[int, dt.time, float] = []
104104
moment, dummy = period.split(",")
105105
moment = moment.replace("[", "").split(" ")
106106
day_nr = DAYS.get(moment[0], "None")
107107
start_time = dt.datetime.strptime(moment[1], "%H:%M").time()
108108
tmp_list.extend((day_nr, start_time, temp))
109-
schema_list.append(tmp_list)
109+
schedule_list.append(tmp_list)
110110

111-
length = len(schema_list)
112-
schema_list = sorted(schema_list)
111+
length = len(schedule_list)
112+
schedule_list = sorted(schedule_list)
113113
for i in range(length):
114114
j = (i + 1) % (length - 1)
115115
now = dt.datetime.now().time()
116116
today = dt.datetime.now().weekday()
117-
if today in [schema_list[i][0], schema_list[j][0]] and in_between(
118-
now, schema_list[i][1], schema_list[j][1]
117+
if today in [schedule_list[i][0], schedule_list[j][0]] and in_between(
118+
now, schedule_list[i][1], schedule_list[j][1]
119119
):
120-
return schema_list[i][2]
120+
return schedule_list[i][2]
121121

122122

123123
def types_finder(data: etree) -> set[str]:
@@ -765,31 +765,31 @@ def _rule_ids_by_name(self, name: str, loc_id: str) -> dict[str]:
765765
"""Helper-function for _presets().
766766
Obtain the rule_id from the given name and and provide the location_id, when present.
767767
"""
768-
schema_ids: dict[str] = {}
768+
schedule_ids: dict[str] = {}
769769
locator = f'./contexts/context/zone/location[@id="{loc_id}"]'
770770
for rule in self._domain_objects.findall(f'./rule[name="{name}"]'):
771771
if rule.find(locator) is not None:
772-
schema_ids[rule.attrib["id"]] = loc_id
772+
schedule_ids[rule.attrib["id"]] = loc_id
773773
else:
774-
schema_ids[rule.attrib["id"]] = None
774+
schedule_ids[rule.attrib["id"]] = None
775775

776-
return schema_ids
776+
return schedule_ids
777777

778778
def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str]:
779-
"""Helper-function for _presets(), _schemas() and _last_active_schema().
779+
"""Helper-function for _presets(), _schedules() and _last_active_schedule().
780780
Obtain the rule_id from the given template_tag and provide the location_id, when present.
781781
"""
782-
schema_ids: dict[str] = {}
782+
schedule_ids: dict[str] = {}
783783
locator1 = f'./template[@tag="{tag}"]'
784784
locator2 = f'./contexts/context/zone/location[@id="{loc_id}"]'
785785
for rule in self._domain_objects.findall("./rule"):
786786
if rule.find(locator1) is not None:
787787
if rule.find(locator2) is not None:
788-
schema_ids[rule.attrib["id"]] = loc_id
788+
schedule_ids[rule.attrib["id"]] = loc_id
789789
else:
790-
schema_ids[rule.attrib["id"]] = None
790+
schedule_ids[rule.attrib["id"]] = None
791791

792-
return schema_ids
792+
return schedule_ids
793793

794794
def _appliance_measurements(
795795
self, appliance: etree, data: dict[str, Any], measurements: dict[str, Any]
@@ -1121,18 +1121,18 @@ def _preset(self, loc_id: str) -> str | None:
11211121
return
11221122
return active_rule.attrib["icon"]
11231123

1124-
def _schemas_legacy(
1124+
def _schedules_legacy(
11251125
self, avail: list[str], sched_temp: str, sel: str
11261126
) -> tuple[str, ...]:
1127-
"""Helper-function for _schemas().
1128-
Collect available schemas/schedules for the legacy thermostat.
1127+
"""Helper-function for _schedules().
1128+
Collect available schedules/schedules for the legacy thermostat.
11291129
"""
11301130
name: str | None = None
1131-
schemas: dict[str] = {}
1131+
schedules: dict[str] = {}
11321132

11331133
search = self._domain_objects
1134-
for schema in search.findall("./rule"):
1135-
if rule_name := schema.find("name").text:
1134+
for schedule in search.findall("./rule"):
1135+
if rule_name := schedule.find("name").text:
11361136
if "preset" not in rule_name:
11371137
name = rule_name
11381138

@@ -1143,16 +1143,16 @@ def _schemas_legacy(
11431143
active = result.text == "on"
11441144

11451145
if name is not None:
1146-
schemas[name] = active
1146+
schedules[name] = active
11471147
avail = [name]
11481148
if active:
11491149
sel = name
11501150

11511151
return avail, sel, sched_temp, None
11521152

1153-
def _schemas(self, location: str) -> tuple[str, ...]:
1153+
def _schedules(self, location: str) -> tuple[str, ...]:
11541154
"""Helper-function for smile.py: _device_data_climate().
1155-
Obtain the available schemas/schedules. Adam: a schedule can be connected to more than one location.
1155+
Obtain the available schedules/schedules. Adam: a schedule can be connected to more than one location.
11561156
NEW: when a location_id is present then the schedule is active. Valid for both Adam and non-legacy Anna.
11571157
"""
11581158
available: list[str] = ["None"]
@@ -1164,7 +1164,7 @@ def _schemas(self, location: str) -> tuple[str, ...]:
11641164

11651165
# Legacy Anna schedule, only one schedule allowed
11661166
if self._smile_legacy:
1167-
return self._schemas_legacy(available, schedule_temperature, selected)
1167+
return self._schedules_legacy(available, schedule_temperature, selected)
11681168

11691169
# Adam schedules, one schedule can be linked to various locations
11701170
# self._last_active contains the locations and the active schedule name per location, or None
@@ -1197,7 +1197,7 @@ def _schemas(self, location: str) -> tuple[str, ...]:
11971197
if count > 1:
11981198
schedule = temp
11991199
else:
1200-
# Schema with less than 2 items
1200+
# Schedule with less than 2 items
12011201
LOGGER.debug("Invalid schedule, only one entry, ignoring.")
12021202

12031203
if schedule:
@@ -1212,7 +1212,7 @@ def _schemas(self, location: str) -> tuple[str, ...]:
12121212
tmp_last_used = self._last_used_schedule(location, rule_ids)
12131213
if tmp_last_used in schedules:
12141214
last_used = tmp_last_used
1215-
schedule_temperature = schemas_schedule_temp(schedules, last_used)
1215+
schedule_temperature = schedules_schedule_temp(schedules, last_used)
12161216

12171217
return available, selected, schedule_temperature, last_used
12181218

@@ -1230,20 +1230,20 @@ def _last_used_schedule(self, loc_id: str, rule_ids: dict[str]) -> str | None:
12301230
return # pragma: no cover
12311231

12321232
epoch = dt.datetime(1970, 1, 1, tzinfo=pytz.utc)
1233-
schemas: dict[str] | None = {}
1233+
schedules: dict[str] | None = {}
12341234

12351235
for rule_id in rule_ids:
1236-
schema_name = self._domain_objects.find(
1236+
schedule_name = self._domain_objects.find(
12371237
f'./rule[@id="{rule_id}"]/name'
12381238
).text
1239-
schema_date = self._domain_objects.find(
1239+
schedule_date = self._domain_objects.find(
12401240
f'./rule[@id="{rule_id}"]/modified_date'
12411241
).text
1242-
schema_time = parse(schema_date)
1243-
schemas[schema_name] = (schema_time - epoch).total_seconds()
1242+
schedule_time = parse(schedule_date)
1243+
schedules[schedule_name] = (schedule_time - epoch).total_seconds()
12441244

1245-
if schemas:
1246-
last_used = sorted(schemas.items(), key=lambda kv: kv[1])[-1][0]
1245+
if schedules:
1246+
last_used = sorted(schedules.items(), key=lambda kv: kv[1])[-1][0]
12471247

12481248
return last_used
12491249

plugwise/smile.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,13 @@ def _device_data_climate(
162162
device_data["active_preset"] = self._preset(loc_id)
163163

164164
# Schedule
165-
avail_schemas, sel_schema, sched_setpoint, last_active = self._schemas(loc_id)
166-
device_data["available_schedules"] = avail_schemas
167-
device_data["selected_schedule"] = sel_schema
165+
avail_schedules, sel_schedule, sched_setpoint, last_active = self._schedules(
166+
loc_id
167+
)
168+
device_data["available_schedules"] = avail_schedules
169+
device_data["selected_schedule"] = sel_schedule
168170
if self._smile_legacy:
169-
device_data["last_used"] = "".join(map(str, avail_schemas))
171+
device_data["last_used"] = "".join(map(str, avail_schedules))
170172
else:
171173
device_data["last_used"] = last_active
172174
device_data["schedule_temperature"] = sched_setpoint
@@ -177,7 +179,7 @@ def _device_data_climate(
177179

178180
# Operation mode: auto, heat, cool
179181
device_data["mode"] = "auto"
180-
if sel_schema == "None":
182+
if sel_schedule == "None":
181183
device_data["mode"] = "heat"
182184
if self._heater_id is not None and self.cooling_active:
183185
device_data["mode"] = "cool"
@@ -474,25 +476,25 @@ async def async_update(self) -> dict[str, Any]:
474476

475477
async def _set_schedule_state_legacy(self, name: str, status: str) -> bool:
476478
"""Helper-function for set_schedule_state()."""
477-
schema_rule_id: str | None = None
479+
schedule_rule_id: str | None = None
478480
for rule in self._domain_objects.findall("rule"):
479481
if rule.find("name").text == name:
480-
schema_rule_id = rule.attrib["id"]
482+
schedule_rule_id = rule.attrib["id"]
481483

482-
if schema_rule_id is None:
484+
if schedule_rule_id is None:
483485
return False
484486

485487
state = "false"
486488
if status == "on":
487489
state = "true"
488-
locator = f'.//*[@id="{schema_rule_id}"]/template'
490+
locator = f'.//*[@id="{schedule_rule_id}"]/template'
489491
for rule in self._domain_objects.findall(locator):
490492
template_id = rule.attrib["id"]
491493

492-
uri = f"{RULES};id={schema_rule_id}"
494+
uri = f"{RULES};id={schedule_rule_id}"
493495
data = (
494496
"<rules><rule"
495-
f' id="{schema_rule_id}"><name><![CDATA[{name}]]></name><template'
497+
f' id="{schedule_rule_id}"><name><![CDATA[{name}]]></name><template'
496498
f' id="{template_id}" /><active>{state}</active></rule></rules>'
497499
)
498500

@@ -506,21 +508,21 @@ async def set_schedule_state(self, loc_id: str, name: str, state: str) -> bool:
506508
if self._smile_legacy:
507509
return await self._set_schedule_state_legacy(name, state)
508510

509-
schema_rule = self._rule_ids_by_name(name, loc_id)
510-
if not schema_rule or schema_rule is None:
511+
schedule_rule = self._rule_ids_by_name(name, loc_id)
512+
if not schedule_rule or schedule_rule is None:
511513
return False
512514

513-
schema_rule_id: str = next(iter(schema_rule))
515+
schedule_rule_id: str = next(iter(schedule_rule))
514516

515517
template = (
516518
'<template tag="zone_preset_based_on_time_and_presence_with_override" />'
517519
)
518520
if self.smile_name != "Adam":
519-
locator = f'.//*[@id="{schema_rule_id}"]/template'
521+
locator = f'.//*[@id="{schedule_rule_id}"]/template'
520522
template_id = self._domain_objects.find(locator).attrib["id"]
521523
template = f'<template id="{template_id}" />'
522524

523-
locator = f'.//*[@id="{schema_rule_id}"]/contexts'
525+
locator = f'.//*[@id="{schedule_rule_id}"]/contexts'
524526
contexts = self._domain_objects.find(locator)
525527
locator = f'.//*[@id="{loc_id}"].../...'
526528
subject = contexts.find(locator)
@@ -536,9 +538,9 @@ async def set_schedule_state(self, loc_id: str, name: str, state: str) -> bool:
536538

537539
contexts = etree.tostring(contexts, encoding="unicode").rstrip()
538540

539-
uri = f"{RULES};id={schema_rule_id}"
541+
uri = f"{RULES};id={schedule_rule_id}"
540542
data = (
541-
f'<rules><rule id="{schema_rule_id}"><name><![CDATA[{name}]]></name>'
543+
f'<rules><rule id="{schedule_rule_id}"><name><![CDATA[{name}]]></name>'
542544
f"{template}{contexts}</rule></rules>"
543545
)
544546
await self._request(uri, method="put", data=data)

0 commit comments

Comments
 (0)