Skip to content

Commit 414da02

Browse files
committed
Simplify NodeAddRequest and adapt related
1 parent 91b0c9e commit 414da02

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

plugwise_usb/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,12 @@ async def register_node(self, mac: str) -> bool:
350350
"""Add node to plugwise network."""
351351
if self._network is None:
352352
return False
353+
353354
try:
354-
return await self._network.register_node(mac)
355+
await self._network.register_node(mac)
355356
except NodeError as exc:
356357
raise NodeError(f"Unable to add Node ({mac}): {exc}") from exc
358+
return True
357359

358360
@raise_not_connected
359361
@raise_not_initialized

plugwise_usb/messages/requests.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ def serialize(self) -> bytes:
410410
class NodeAddRequest(PlugwiseRequest):
411411
"""Add node to the Plugwise Network and add it to memory of Circle+ node.
412412
413+
The Stick does not respond with ACCEPT to this request (@bouwew)
414+
413415
Supported protocols : 1.0, 2.0
414416
Response message : NodeRejoinResponse, b"0061" (@bouwew)
415417
"""
@@ -428,21 +430,12 @@ def __init__(
428430
accept_value = 1 if accept else 0
429431
self._args.append(Int(accept_value, length=2))
430432

431-
self.max_retries = 6
433+
self.max_retries = 1 # No retrying, will delay the NodeRejoinResponse
432434
self.no_stick_response = True
433435

434-
async def send(self) -> NodeRejoinResponse | None:
436+
async def send(self) -> None:
435437
"""Send request."""
436-
result = await self._send_request()
437-
if isinstance(result, NodeRejoinResponse):
438-
return result
439-
440-
if result is None:
441-
return None
442-
443-
raise MessageError(
444-
f"Invalid response message. Received {result.__class__.__name__}, expected NodeRejoinResponse"
445-
)
438+
await self._send_request()
446439

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

plugwise_usb/network/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,10 @@ async def register_node(self, mac: str) -> bool:
152152
return False
153153

154154
try:
155-
address = await self._register.register_node(mac)
156-
except (MessageError, NodeError) as exc:
155+
await self._register.register_node(mac)
156+
except NodeError as exc:
157157
raise NodeError(f"{exc}") from exc
158158

159-
return await self._discover_node(address, mac, None)
160-
161159
async def clear_cache(self) -> None:
162160
"""Clear register cache."""
163161
await self._register.clear_register_cache()

plugwise_usb/network/registry.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,13 @@ async def save_registry_to_cache(self) -> None:
245245
await self._network_cache.save_cache()
246246
_LOGGER.debug("save_registry_to_cache finished")
247247

248-
async def register_node(self, mac: str) -> int:
248+
async def register_node(self, mac: str) -> None:
249249
"""Register node to Plugwise network and return network address."""
250250
if not validate_mac(mac):
251251
raise NodeError(f"MAC '{mac}' invalid")
252252

253253
request = NodeAddRequest(self._send_to_controller, bytes(mac, UTF8), True)
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
261-
262-
return self.update_node_registration(mac)
254+
await request.send()
263255

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

0 commit comments

Comments
 (0)