Skip to content

Commit 489d2e8

Browse files
committed
Add PlugwiseError exception, adapt to this change
1 parent 5b75762 commit 489d2e8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

plugwise/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class InvalidSetupError(PlugwiseException):
5959
"""Raised when adding an Anna while an Adam exists."""
6060

6161

62+
class PlugwiseError(PlugwiseException):
63+
"""Raise when a non-specific error happens."""
64+
65+
6266
class UnsupportedDeviceError(PlugwiseException):
6367
"""Raised when device is not supported."""
6468

plugwise/smile.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from .exceptions import (
3535
ConnectionFailedError,
3636
InvalidSetupError,
37-
PlugwiseException,
37+
PlugwiseError,
3838
UnsupportedDeviceError,
3939
)
4040
from .helper import SmileComm, SmileHelper, update_helper
@@ -467,7 +467,7 @@ async def _set_schedule_state_legacy(self, name: str, status: str) -> bool:
467467
schedule_rule_id = rule.attrib["id"]
468468

469469
if schedule_rule_id is None:
470-
raise PlugwiseException("No schedule available.")
470+
raise PlugwiseError("No schedule available.")
471471

472472
state = "false"
473473
if status == "on":
@@ -494,7 +494,7 @@ async def set_schedule_state(self, loc_id: str, name: str, state: str) -> bool:
494494

495495
schedule_rule = self._rule_ids_by_name(name, loc_id)
496496
if not schedule_rule or schedule_rule is None:
497-
raise PlugwiseException("No schedule available.")
497+
raise PlugwiseError("No schedule with this name available.")
498498

499499
schedule_rule_id: str = next(iter(schedule_rule))
500500

@@ -533,7 +533,7 @@ async def _set_preset_legacy(self, preset: str) -> bool:
533533
"""Set the given Preset on the relevant Thermostat - from DOMAIN_OBJECTS."""
534534
locator = f'rule/directives/when/then[@icon="{preset}"].../.../...'
535535
if (rule := self._domain_objects.find(locator)) is None:
536-
raise PlugwiseException("No presets available.")
536+
raise PlugwiseError("Invalid preset.")
537537

538538
uri = RULES
539539
data = f'<rules><rule id="{rule.attrib["id"]}"><active>true</active></rule></rules>'
@@ -550,7 +550,7 @@ async def set_preset(self, loc_id: str, preset: str) -> bool:
550550
location_type = current_location.find("type").text
551551

552552
if preset not in self._presets(loc_id):
553-
raise PlugwiseException("Preset not available.")
553+
raise PlugwiseError("Invalid preset.")
554554

555555
uri = f"{LOCATIONS};id={loc_id}"
556556
data = (
@@ -637,14 +637,14 @@ async def set_switch_state(
637637
lock_state: str = self._appliances.find(locator).text
638638
# Don't bother switching a relay when the corresponding lock-state is true
639639
if lock_state == "true":
640-
raise PlugwiseException("Cannot switch a locked Relay.")
640+
raise PlugwiseError("Cannot switch a locked Relay.")
641641

642642
await self._request(uri, method="put", data=data)
643643

644644
async def set_regulation_mode(self, mode: str) -> bool:
645645
"""Set the heating regulation mode."""
646646
if mode not in self._allowed_modes:
647-
raise PlugwiseException("Invalid regulation mode.")
647+
raise PlugwiseError("Invalid regulation mode.")
648648

649649
uri = f"{APPLIANCES};type=gateway/regulation_mode_control"
650650
duration = ""

0 commit comments

Comments
 (0)