Skip to content

Commit ccb10ec

Browse files
committed
Replace internal variables with data in output, improve raise messages
1 parent 1c7a8b9 commit ccb10ec

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

plugwise/smile.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ async def set_preset(self, loc_id: str, preset: str) -> None:
216216
if (presets := self._presets(loc_id)) is None:
217217
raise PlugwiseError("Plugwise: no presets available.") # pragma: no cover
218218
if preset not in list(presets):
219-
raise PlugwiseError("Plugwise: invalid preset.")
219+
raise PlugwiseError(f"Plugwise: invalid preset {preset}.")
220220

221221
current_location = self._domain_objects.find(f'location[@id="{loc_id}"]')
222222
location_name = current_location.find("name").text
@@ -268,12 +268,11 @@ async def set_dhw_mode(
268268
- and the 5 modes available on the Loria.
269269
"""
270270
if (
271-
self._dhw_allowed_modes
272-
and mode not in self._dhw_allowed_modes
271+
mode not in self.gw_entities[appl_id]["dhw_modes"]
273272
or length is None
274273
or not isinstance(length, int)
275274
):
276-
raise PlugwiseError("Plugwise: invalid dhw mode or invalid dhw modes list.")
275+
raise PlugwiseError(f"Plugwise: invalid dhw mode {mode} or invalid length {length}.")
277276

278277
match length:
279278
case 2:
@@ -291,8 +290,8 @@ async def set_dhw_mode(
291290

292291
async def set_gateway_mode(self, mode: str) -> None:
293292
"""Set the gateway mode."""
294-
if mode not in self._gw_allowed_modes:
295-
raise PlugwiseError("Plugwise: invalid gateway mode.")
293+
if mode not in self.gw_entities[self.gateway_id]["gateway_modes"]:
294+
raise PlugwiseError(f"Plugwise: invalid gateway mode {mode}.")
296295

297296
end_time = "2037-04-21T08:00:53.000Z"
298297
valid = ""
@@ -323,8 +322,8 @@ async def set_gateway_mode(self, mode: str) -> None:
323322

324323
async def set_regulation_mode(self, mode: str) -> None:
325324
"""Set the heating regulation mode."""
326-
if mode not in self._reg_allowed_modes:
327-
raise PlugwiseError("Plugwise: invalid regulation mode.")
325+
if mode not in self.gw_entities[self.gateway_id]["regulation_modes"]:
326+
raise PlugwiseError(f"Plugwise: invalid regulation mode {mode}.")
328327

329328
duration = ""
330329
if "bleeding" in mode:
@@ -364,7 +363,7 @@ async def set_schedule_state(
364363
if state is None:
365364
state = STATE_ON
366365
elif state not in (STATE_OFF, STATE_ON):
367-
raise PlugwiseError("Plugwise: invalid schedule state.")
366+
raise PlugwiseError(f"Plugwise: invalid schedule state {state}.")
368367

369368
# Translate selection of Off-schedule-option to disabling the active schedule
370369
if name == OFF:

0 commit comments

Comments
 (0)