From 24449d8d952ac25ddcfad969966f83f884374768 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Thu, 20 Jun 2024 13:57:20 -0700 Subject: [PATCH] expose new release_address() for master nodes --- circuitpython_nrf24l01/rf24_mesh.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/circuitpython_nrf24l01/rf24_mesh.py b/circuitpython_nrf24l01/rf24_mesh.py index 6caa5bd..f51bed1 100644 --- a/circuitpython_nrf24l01/rf24_mesh.py +++ b/circuitpython_nrf24l01/rf24_mesh.py @@ -333,10 +333,7 @@ def update(self) -> int: self.frame_buf.message = bytes([ret_val]) self._write(self.frame_buf.header.to_node, TX_NORMAL) elif msg_t == MESH_ADDR_RELEASE: - for n_id, addr in self.dhcp_dict.items(): - if addr == self.frame_buf.header.from_node: - del self.dhcp_dict[n_id] - break + self.release_address(self.frame_buf.header.from_node) self._dhcp() return msg_t @@ -435,6 +432,25 @@ def print_details(self, dump_pipes: bool = False, network_only: bool = False): if dump_pipes: self._rf24.print_pipes() + def release_address(self, address: int = 0) -> bool: + """Release an assigned address from any corresponding mesh node's ID. + + .. important:: + This function is meant for use on master nodes. If the ``address`` + parameter is not specified, then + `RF24MeshNoMaster.release_address()` is called. + + :param address: The address to release. + :returns: `True` if the address was released, otherwise `False`. + """ + if not address: + return super().release_address() + for id, addr in self.dhcp_dict.items(): + if addr == address: + del self.dhcp_dict[id] + return True + return False + def lookup_address(self, node_id: Optional[int] = None) -> int: """Convert a node's unique ID number into its corresponding :ref:`Logical Address `."""