Skip to content

Commit ab3aca4

Browse files
committed
Rework NodeAddRequest class
1 parent c9dd475 commit ab3aca4

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

plugwise_usb/messages/requests.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -409,26 +409,11 @@ def serialize(self) -> bytes:
409409
return MESSAGE_HEADER + msg + checksum + MESSAGE_FOOTER
410410

411411

412-
class PlugwiseRequestWithStickResponse(PlugwiseRequest):
413-
"""Base class of a plugwise request resulting in a StickResponse."""
414-
415-
async def send(self, suppress_node_errors: bool = False) -> StickResponse | None:
416-
"""Send request."""
417-
result = await self._send_request(suppress_node_errors)
418-
if isinstance(result, StickResponse):
419-
return result
420-
if result is None:
421-
return None
422-
raise MessageError(
423-
f"Invalid response message. Received {result.__class__.__name__}, expected NodeAckResponse"
424-
)
425-
426-
427412
class NodeAddRequest(PlugwiseRequest):
428413
"""Add node to the Plugwise Network and add it to memory of Circle+ node.
429414
430415
Supported protocols : 1.0, 2.0
431-
Response message : (@bouwew) b"0000" - StickResponse is returned
416+
Response message : (@bouwew) no Response
432417
"""
433418

434419
_identifier = b"0007"
@@ -440,10 +425,17 @@ def __init__(
440425
accept: bool,
441426
) -> None:
442427
"""Initialize NodeAddRequest message object."""
443-
super().__init__(None, mac)
428+
super().__init__(send_fn, mac)
444429
accept_value = 1 if accept else 0
445430
self._args.append(Int(accept_value, length=2))
446431

432+
async def send(self, suppress_node_errors: bool = False) -> None:
433+
"""Send request."""
434+
if (result := await self._send_request(suppress_node_errors)) is not None:
435+
raise MessageError(
436+
f"Invalid response message. Received {result.__class__.__name__}, expected no Response"
437+
)
438+
447439
# This message has an exceptional format (MAC at end of message)
448440
# and therefore a need to override the serialize method
449441
def serialize(self) -> bytes:

plugwise_usb/network/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ async def register_node(self, mac: str) -> int:
248248
if not validate_mac(mac):
249249
raise NodeError(f"MAC '{mac}' invalid")
250250

251-
_ = NodeAddRequest(self._send_to_controller, bytes(mac, UTF8), True)
252-
# response = await request.send()
251+
request = NodeAddRequest(self._send_to_controller, bytes(mac, UTF8), True)
252+
await request.send()
253253
# if response is None or response.ack_id != StickResponseType.ACCEPT:
254254
# raise NodeError(f"Failed to register node {mac}")
255255
self.update_network_registration(self._first_free_address, mac, None)

0 commit comments

Comments
 (0)