Skip to content

Commit 40d9884

Browse files
committed
Add input checks for set_preset() and set_schedule_state()
1 parent 4de6713 commit 40d9884

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

plugwise/helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def __init__(self) -> None:
258258
self._on_off_device = False
259259
self._opentherm_device = False
260260
self._outdoor_temp: float
261+
self._presets_list: list[str] = []
261262
self._smile_legacy = False
262263
self._stretch_v2 = False
263264
self._stretch_v3 = False

plugwise/smile.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ def _device_data_climate(
144144
device_data["preset_modes"] = None
145145
device_data["active_preset"] = None
146146
if presets := self._presets(loc_id):
147-
presets_list = list(presets)
147+
self._presets_list = list(presets)
148148
# Adam does not show vacation preset anymore, issue #185
149149
if self.smile_name == "Adam":
150-
presets_list.remove("vacation")
151-
device_data["preset_modes"] = presets_list
150+
self._presets_list.remove("vacation")
151+
device_data["preset_modes"] = self._presets_list
152152

153153
device_data["active_preset"] = self._preset(loc_id)
154154

@@ -486,6 +486,9 @@ async def set_schedule_state(
486486
Determined from - DOMAIN_OBJECTS.
487487
In HA Core used to set the hvac_mode: in practice switch between schedule on - off.
488488
"""
489+
if state not in ["on", "off"]:
490+
raise PlugwiseError("Plugwise: invalid schedule state.")
491+
489492
# Do nothing when name == None and the state does not change. No need to show
490493
# an error, as doing nothing is the correct action in this scenario.
491494
if name is None:
@@ -550,6 +553,9 @@ async def _set_preset_legacy(self, preset: str) -> None:
550553

551554
async def set_preset(self, loc_id: str, preset: str) -> None:
552555
"""Set the given Preset on the relevant Thermostat - from LOCATIONS."""
556+
if preset not in self._presets_list:
557+
raise PlugwiseError("Plugwise: invalid preset.")
558+
553559
if self._smile_legacy:
554560
await self._set_preset_legacy(preset)
555561
return

0 commit comments

Comments
 (0)