|
8 | 8 | import logging |
9 | 9 | from typing import Final |
10 | 10 |
|
11 | | -from ..api import NodeType |
| 11 | +from ..api import NodeType, PlugwiseNode |
12 | 12 | from ..constants import UTF8 |
13 | 13 | from ..exceptions import CacheError, NodeError, StickError |
14 | 14 | from ..helpers.util import validate_mac |
@@ -266,27 +266,26 @@ async def register_node(self, mac: str) -> None: |
266 | 266 | if self.update_network_registration(mac): |
267 | 267 | await self._exec_node_discover_callback(mac, None, False) |
268 | 268 |
|
269 | | - async def unregister_node(self, mac: str) -> None: |
| 269 | + async def unregister_node(self, node: PlugwiseNode) -> None: |
270 | 270 | """Unregister node from current Plugwise network.""" |
271 | | - if not validate_mac(mac): |
272 | | - raise NodeError(f"MAC {mac} invalid") |
273 | | - |
274 | | - if mac not in self._registry: |
275 | | - raise NodeError(f"No existing Node ({mac}) found to unregister") |
| 271 | + if node.mac not in self._registry: |
| 272 | + raise NodeError(f"No existing Node ({node.mac}) found to unregister") |
276 | 273 |
|
277 | | - request = NodeRemoveRequest(self._send_to_controller, self._mac_nc, mac) |
| 274 | + # First reset the node, then remove it from the network. |
| 275 | + node.reset_node() |
| 276 | + request = NodeRemoveRequest(self._send_to_controller, self._mac_nc, node.mac) |
278 | 277 | if (response := await request.send()) is None: |
279 | 278 | raise NodeError( |
280 | 279 | f"The Zigbee network coordinator '{self._mac_nc!r}'" |
281 | | - + f" did not respond to unregister node '{mac}'" |
| 280 | + + f" did not respond to unregister node '{node.mac}'" |
282 | 281 | ) |
283 | 282 | if response.status.value != 1: |
284 | 283 | raise NodeError( |
285 | 284 | f"The Zigbee network coordinator '{self._mac_nc!r}'" |
286 | | - + f" failed to unregister node '{mac}'" |
| 285 | + + f" failed to unregister node '{node.mac}'" |
287 | 286 | ) |
288 | 287 |
|
289 | | - await self.remove_network_registration(mac) |
| 288 | + await self.remove_network_registration(node.mac) |
290 | 289 |
|
291 | 290 | async def clear_register_cache(self) -> None: |
292 | 291 | """Clear current cache.""" |
|
0 commit comments