Skip to content

Commit 6716707

Browse files
committed
Update network files
1 parent 2d27c1a commit 6716707

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

plugwise_usb/network/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from ..connection import StickController
1515
from ..constants import UTF8
1616
from ..exceptions import CacheError, MessageError, NodeError, StickError, StickTimeout
17-
from ..helpers.util import validate_mac
1817
from ..messages.requests import CirclePlusAllowJoiningRequest, NodePingRequest
1918
from ..messages.responses import (
2019
NODE_AWAKE_RESPONSE_ID,
@@ -149,8 +148,6 @@ def registry(self) -> dict[int, tuple[str, NodeType | None]]:
149148

150149
async def register_node(self, mac: str) -> bool:
151150
"""Register node to Plugwise network."""
152-
if not validate_mac(mac):
153-
raise NodeError(f"Invalid mac '{mac}' to register")
154151
address = await self._register.register_node(mac)
155152
return await self._discover_node(address, mac, None)
156153

@@ -261,7 +258,6 @@ async def node_rejoin_message(self, response: PlugwiseResponse) -> bool:
261258
f"Invalid response message type ({response.__class__.__name__}) received, expected NodeRejoinResponse"
262259
)
263260
mac = response.mac_decoded
264-
address = self._register.network_address(mac)
265261
if (address := self._register.network_address(mac)) is not None:
266262
if self._nodes.get(mac) is None:
267263
if self._discover_sed_tasks.get(mac) is None:
@@ -513,11 +509,14 @@ async def stop(self) -> None:
513509

514510
async def allow_join_requests(self, state: bool) -> None:
515511
"""Enable or disable Plugwise network."""
512+
_LOGGER.debug("Send AllowJoiningRequest to Circle+ with state=%s", state)
516513
request = CirclePlusAllowJoiningRequest(self._controller.send, state)
517514
if (response := await request.send()) is None:
518-
raise NodeError("No response to get notifications for join request.")
515+
raise NodeError("No response for CirclePlusAllowJoiningRequest.")
519516

520-
if response.response_type != NodeResponseType.JOIN_ACCEPTED:
517+
if response.response_type not in (
518+
NodeResponseType.JOIN_ACCEPTED, NodeResponseType.CIRCLE_PLUS
519+
):
521520
raise MessageError(
522521
f"Unknown NodeResponseType '{response.response_type.name}' received"
523522
)
@@ -553,3 +552,4 @@ async def _notify_node_event_subscribers(self, event: NodeEvent, mac: str) -> No
553552
callback_list.append(callback(event, mac))
554553
if len(callback_list) > 0:
555554
await gather(*callback_list)
555+

plugwise_usb/network/registry.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
NodeRemoveRequest,
1818
PlugwiseRequest,
1919
)
20-
from ..messages.responses import NodeResponseType, PlugwiseResponse
20+
from ..messages.responses import PlugwiseResponse #, StickResponseType
2121
from .cache import NetworkRegistrationCache
2222

2323
_LOGGER = logging.getLogger(__name__)
@@ -246,20 +246,20 @@ async def save_registry_to_cache(self) -> None:
246246
async def register_node(self, mac: str) -> int:
247247
"""Register node to Plugwise network and return network address."""
248248
if not validate_mac(mac):
249-
raise NodeError(f"Invalid mac '{mac}' to register")
249+
raise NodeError(f"MAC '{mac}' invalid")
250250

251251
request = NodeAddRequest(self._send_to_controller, bytes(mac, UTF8), True)
252-
response = await request.send()
253-
if response is None or response.ack_id != NodeResponseType.JOIN_ACCEPTED:
254-
raise NodeError(f"Failed to register node {mac}")
252+
await request.send()
253+
# if response is None or response.ack_id != StickResponseType.ACCEPT:
254+
# raise NodeError(f"Failed to register node {mac}")
255255
self.update_network_registration(self._first_free_address, mac, None)
256256
self._first_free_address += 1
257257
return self._first_free_address - 1
258258

259259
async def unregister_node(self, mac: str) -> None:
260260
"""Unregister node from current Plugwise network."""
261261
if not validate_mac(mac):
262-
raise NodeError(f"Invalid mac '{mac}' to unregister")
262+
raise NodeError(f"MAC '{mac}' invalid")
263263

264264
mac_registered = False
265265
for registration in self._registry.values():
@@ -270,7 +270,6 @@ async def unregister_node(self, mac: str) -> None:
270270
raise NodeError(f"No existing registration '{mac}' found to unregister")
271271

272272
request = NodeRemoveRequest(self._send_to_controller, self._mac_nc, mac)
273-
response = await request.send()
274273
if (response := await request.send()) is None:
275274
raise NodeError(
276275
f"The Zigbee network coordinator '{self._mac_nc!r}'"

0 commit comments

Comments
 (0)