Skip to content

Commit

Permalink
expose new release_address() for master nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Jun 20, 2024
1 parent fccdb4e commit 07668d4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
24 changes: 20 additions & 4 deletions circuitpython_nrf24l01/rf24_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 336 in circuitpython_nrf24l01/rf24_mesh.py

View check run for this annotation

Codecov / codecov/patch

circuitpython_nrf24l01/rf24_mesh.py#L336

Added line #L336 was not covered by tests
self._dhcp()
return msg_t

Expand Down Expand Up @@ -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

Check warning on line 452 in circuitpython_nrf24l01/rf24_mesh.py

View check run for this annotation

Codecov / codecov/patch

circuitpython_nrf24l01/rf24_mesh.py#L448-L452

Added lines #L448 - L452 were not covered by tests

def lookup_address(self, node_id: Optional[int] = None) -> int:
"""Convert a node's unique ID number into its corresponding
:ref:`Logical Address <Logical Address>`."""
Expand Down
12 changes: 7 additions & 5 deletions docs/network_docs/mesh_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
**************
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 07668d4

Please sign in to comment.