Skip to content

Commit 4a1eca2

Browse files
committed
Add check for no presets
1 parent 16876d5 commit 4a1eca2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

plugwise/helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,16 +648,16 @@ def _control_state(self, loc_id: str) -> str | bool:
648648

649649
def _presets_legacy(self) -> dict[str, list[float]]:
650650
"""Helper-function for presets() - collect Presets for a legacy Anna."""
651-
preset_dictionary: dict[str, list[float]] = {}
651+
presets: dict[str, list[float]] = {}
652652
for directive in self._domain_objects.findall("rule/directives/when/then"):
653653
if directive is not None and "icon" in directive.keys():
654654
# Ensure list of heating_setpoint, cooling_setpoint
655-
preset_dictionary[directive.attrib["icon"]] = [
655+
presets[directive.attrib["icon"]] = [
656656
float(directive.attrib["temperature"]),
657657
0,
658658
]
659659

660-
return preset_dictionary
660+
return presets
661661

662662
def _presets(self, loc_id: str) -> dict[str, list[float]]:
663663
"""Collect Presets for a Thermostat based on location_id."""

plugwise/smile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,9 @@ async def _set_preset_legacy(self, preset: str) -> None:
547547

548548
async def set_preset(self, loc_id: str, preset: str) -> None:
549549
"""Set the given Preset on the relevant Thermostat - from LOCATIONS."""
550-
if preset not in self._presets(loc_id):
550+
if presets := self._presets(loc_id) is None:
551+
raise PlugwiseError("Plugwise: no presets available.")
552+
if preset not in presets:
551553
raise PlugwiseError("Plugwise: invalid preset.")
552554

553555
if self._smile_legacy:

0 commit comments

Comments
 (0)