Skip to content

Commit 14bc897

Browse files
committed
Implement more try-excepts
1 parent 75ebdbb commit 14bc897

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

plugwise_usb/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from .api import NodeEvent, PlugwiseNode, StickEvent
1616
from .connection import StickController
17-
from .exceptions import StickError, SubscriptionError
17+
from .exceptions import NodeError, StickError, SubscriptionError
1818
from .network import StickNetwork
1919

2020
FuncT = TypeVar("FuncT", bound=Callable[..., Any])
@@ -350,15 +350,21 @@ async def register_node(self, mac: str) -> bool:
350350
"""Add node to plugwise network."""
351351
if self._network is None:
352352
return False
353-
return await self._network.register_node(mac)
353+
try:
354+
return await self._network.register_node(mac)
355+
except NodeError as exc:
356+
raise NodeError(f"Unable to add Node ({mac}): {exc}") from exc
354357

355358
@raise_not_connected
356359
@raise_not_initialized
357360
async def unregister_node(self, mac: str) -> None:
358361
"""Remove node to plugwise network."""
359362
if self._network is None:
360363
return
361-
await self._network.unregister_node(mac)
364+
try:
365+
await self._network.unregister_node(mac)
366+
except MessageError as exc:
367+
raise NodeError(f"Unable to remove Node ({mac}): {exc}") from exc
362368

363369
async def disconnect(self) -> None:
364370
"""Disconnect from USB-Stick."""

plugwise_usb/network/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async def unregister_node(self, mac: str) -> None:
164164
await self._nodes[mac].unload()
165165
self._nodes.pop(mac)
166166
except KeyError as exc:
167-
raise MessageError("Mac not registered, already deleted?")
167+
raise MessageError("Mac not registered, already deleted?") from exc
168168

169169
# region - Handle stick connect/disconnect events
170170
def _subscribe_to_protocol_events(self) -> None:

0 commit comments

Comments
 (0)