From 07668d4aaeff42c5ddc915dfa8e0a9de451c230e Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Thu, 20 Jun 2024 14:07:18 -0700 Subject: [PATCH] expose new release_address() for master nodes per nRF24/RF24Mesh#244 --- circuitpython_nrf24l01/rf24_mesh.py | 24 ++++++++++++++++++++---- docs/network_docs/mesh_api.rst | 12 +++++++----- 2 files changed, 27 insertions(+), 9 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 `.""" diff --git a/docs/network_docs/mesh_api.rst b/docs/network_docs/mesh_api.rst index b1f1544..5a8635e 100644 --- a/docs/network_docs/mesh_api.rst +++ b/docs/network_docs/mesh_api.rst @@ -31,6 +31,13 @@ RF24MeshNoMaster class .. seealso:: For all parameters' descriptions, see the :py:class:`~circuitpython_nrf24l01.rf24.RF24` class' constructor documentation. +.. automethod:: circuitpython_nrf24l01.rf24_mesh.RF24MeshNoMaster.release_address + + .. hint:: + This should be called from a mesh network node that is disconnecting from the network. + This is also recommended for mesh network nodes that are entering a powered down (or + sleep) mode. + RF24Mesh class ************** @@ -170,11 +177,6 @@ Advanced API .. automethod:: circuitpython_nrf24l01.rf24_mesh.RF24Mesh.release_address - .. hint:: - This should be called from a mesh network node that is disconnecting from the network. - This is also recommended for mesh network nodes that are entering a powered down (or - sleep) mode. - .. autoproperty:: circuitpython_nrf24l01.rf24_mesh.RF24Mesh.allow_children .. autoattribute:: circuitpython_nrf24l01.rf24_mesh.RF24Mesh.block_less_callback