Skip to content

Commit 286a33f

Browse files
committed
Revert NodeAddRequest related changes
1 parent fd644b2 commit 286a33f

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

plugwise_usb/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,9 @@ async def register_node(self, mac: str) -> bool:
352352
return False
353353

354354
try:
355-
await self._network.register_node(mac)
355+
return await self._network.register_node(mac)
356356
except NodeError as exc:
357357
raise NodeError(f"Unable to add Node ({mac}): {exc}") from exc
358-
return True
359358

360359
@raise_not_connected
361360
@raise_not_initialized

plugwise_usb/messages/requests.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
NodeImageValidationResponse,
3535
NodeInfoResponse,
3636
NodePingResponse,
37+
NodeRejoinResponse,
3738
NodeRemoveResponse,
3839
NodeResponse,
3940
NodeSpecificResponse,
@@ -107,9 +108,6 @@ def __init__(
107108
self._response_future: Future[PlugwiseResponse] = self._loop.create_future()
108109
self._waiting_for_response = False
109110

110-
self.no_stick_response = False
111-
112-
113111
def __repr__(self) -> str:
114112
"""Convert request into writable str."""
115113
if self._seq_id is None:
@@ -409,8 +407,6 @@ def serialize(self) -> bytes:
409407
class NodeAddRequest(PlugwiseRequest):
410408
"""Add node to the Plugwise Network and add it to memory of Circle+ node.
411409
412-
The Stick does not respond with ACCEPT to this request (@bouwew)
413-
414410
Supported protocols : 1.0, 2.0
415411
Response message : NodeRejoinResponse, b"0061" (@bouwew)
416412
"""
@@ -430,11 +426,19 @@ def __init__(
430426
self._args.append(Int(accept_value, length=2))
431427

432428
self.max_retries = 1 # No retrying, will delay the NodeRejoinResponse
433-
self.no_stick_response = True
434429

435-
async def send(self) -> None:
430+
async def send(self) -> NodeRejoinResponse | None:
436431
"""Send request."""
437-
await self._send_request()
432+
result = await self._send_request()
433+
if isinstance(result, NodeRejoinResponse):
434+
return result
435+
436+
if result is None:
437+
return None
438+
439+
raise MessageError(
440+
f"Invalid response message. Received {result.__class__.__name__}, expected NodeRejoinResponse"
441+
)
438442

439443
# This message has an exceptional format (MAC at end of message)
440444
# and therefore a need to override the serialize method

plugwise_usb/network/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ async def register_node(self, mac: str) -> bool:
153153

154154
try:
155155
await self._register.register_node(mac)
156-
except NodeError as exc:
156+
except (MessageError, NodeError) as exc:
157157
raise NodeError(f"{exc}") from exc
158+
return True
158159

159160
async def clear_cache(self) -> None:
160161
"""Clear register cache."""

plugwise_usb/network/registry.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,13 @@ async def register_node(self, mac: str) -> None:
251251
raise NodeError(f"MAC '{mac}' invalid")
252252

253253
request = NodeAddRequest(self._send_to_controller, bytes(mac, UTF8), True)
254-
await request.send()
254+
try:
255+
response = await request.send()
256+
# pylint: disable-next=consider-using-assignment-expr
257+
if response is None:
258+
raise NodeError(f"Failed to register node {mac}, no response received")
259+
except MessageError as exc:
260+
raise MessageError(f"Failed to register Node ({mac}) due to {exc}") from exc
255261

256262
async def update_node_registration(self, mac: str) -> int:
257263
"""Register (re)joined node to Plugwise network and return network address."""

0 commit comments

Comments
 (0)