@@ -6792,9 +6792,8 @@ def add_if_not_exist(self, x64bit_addr=None, x16bit_addr=None, node_id=None):
67926792 if x64bit_addr == self .__xbee_device .get_64bit_addr ():
67936793 return self .__xbee_device
67946794
6795- remote = RemoteXBeeDevice (self .__xbee_device , x64bit_addr = x64bit_addr ,
6796- x16bit_addr = x16bit_addr , node_id = node_id )
6797- return self .add_remote (remote )
6795+ return self .__add_remote_from_attr (NetworkEventReason .MANUAL , x64bit_addr = x64bit_addr ,
6796+ x16bit_addr = x16bit_addr , node_id = node_id )
67986797
67996798 def add_remote (self , remote_xbee_device ):
68006799 """
@@ -6840,6 +6839,43 @@ def __add_remote(self, remote_xbee, reason):
68406839
68416840 return remote_xbee
68426841
6842+ def __add_remote_from_attr (self , reason , x64bit_addr = None , x16bit_addr = None , node_id = None ,
6843+ role = Role .UNKNOWN ):
6844+ """
6845+ Creates a new XBee using the provided data and adds it to the network if it is not
6846+ included yet.
6847+
6848+ If the XBee is already in the network, its data will be updated with the parameters of the
6849+ XBee that are not ``None``.
6850+
6851+ Args:
6852+ reason (:class:`.NetworkEventReason`): The reason of the addition to the network.
6853+ x64bit_addr (:class:`digi.xbee.models.address.XBee64BitAddress`, optional,
6854+ default=``None``): The 64-bit address of the remote XBee.
6855+ x16bit_addr (:class:`digi.xbee.models.address.XBee16BitAddress`, optional,
6856+ default=``None``): The 16-bit address of the remote XBee.
6857+ node_id (String, optional, default=``None``): The node identifier of the remote XBee.
6858+ role (:class:`digi.xbee.models.protocol.Role`, optional, default=``Role.UNKNOWN``):
6859+ The role of the remote XBee
6860+
6861+ Returns:
6862+ :class:`.RemoteXBeeDevice`: the remote XBee device generated from the provided data if
6863+ the data provided is correct and the XBee device's protocol is valid, ``None``
6864+ otherwise.
6865+
6866+ .. seealso::
6867+ | :class:`.NetworkEventReason`
6868+ | :class:`digi.xbee.models.address.XBee16BitAddress`
6869+ | :class:`digi.xbee.models.address.XBee64BitAddress`
6870+ | :class:`digi.xbee.models.protocol.Role`
6871+
6872+ Returns:
6873+ :class:`.AbstractXBeeDevice`: The created XBee with the updated parameters.
6874+ """
6875+ return self .__add_remote (
6876+ self .__create_remote (x64bit_addr = x64bit_addr , x16bit_addr = x16bit_addr ,
6877+ node_id = node_id , role = role ), reason )
6878+
68436879 def add_remotes (self , remote_xbee_devices ):
68446880 """
68456881 Adds a list of remote XBee devices to the network.
@@ -6893,8 +6929,9 @@ def discovery_gen_callback(xbee_packet):
68936929 self .__discover_result = xbee_packet .status
68946930 self .stop_discovery_process ()
68956931 elif nd_id == XBeeNetwork .ND_PACKET_REMOTE :
6896- remote = self .__create_remote (xbee_packet .command_value )
6897- # if remote was created successfully and it is not int the
6932+ x16 , x64 , n_id , role = self .__get_data_for_remote (xbee_packet .command_value )
6933+ remote = self .__create_remote (x64bit_addr = x64 , x16bit_addr = x16 , node_id = n_id ,
6934+ role = role )
68986935 # XBee device list, add it and notify callbacks.
68996936 if remote is not None :
69006937 # if remote was created successfully and it is not in the
@@ -6921,7 +6958,9 @@ def discovery_spec_callback(xbee_packet):
69216958 self .stop_discovery_process ()
69226959 elif nd_id == XBeeNetwork .ND_PACKET_REMOTE :
69236960 # if it is not a finish signal, it contains info about a remote XBee device.
6924- remote = self .__create_remote (xbee_packet .command_value )
6961+ x16 , x64 , n_id , role = self .__get_data_for_remote (xbee_packet .command_value )
6962+ remote = self .__create_remote (x64bit_addr = x64 , x16bit_addr = x16 , node_id = n_id ,
6963+ role = role )
69256964 # if it's the sought XBee device, put it in the proper variable.
69266965 if self .__sought_device_id == remote .get_node_id ():
69276966 with self .__lock :
@@ -7074,23 +7113,36 @@ def __calculate_timeout(self):
70747113
70757114 return discovery_timeout
70767115
7077- def __create_remote (self , discovery_data ):
7116+ def __create_remote (self , x64bit_addr = XBee64BitAddress .UNKNOWN_ADDRESS ,
7117+ x16bit_addr = XBee16BitAddress .UNKNOWN_ADDRESS , node_id = None , role = Role .UNKNOWN ):
70787118 """
70797119 Creates and returns a :class:`.RemoteXBeeDevice` from the provided data,
70807120 if the data contains the required information and in the required
70817121 format.
7082-
7122+
7123+ Args:
7124+ x64bit_addr (:class:`digi.xbee.models.address.XBee64BitAddress`, optional,
7125+ default=``XBee64BitAddress.UNKNOWN_ADDRESS``): The 64-bit address of the remote XBee.
7126+ x16bit_addr (:class:`digi.xbee.models.address.XBee16BitAddress`, optional,
7127+ default=``XBee16BitAddress.UNKNOWN_ADDRESS``): The 16-bit address of the remote XBee.
7128+ node_id (String, optional, default=``None``): The node identifier of the remote XBee.
7129+ role (:class:`digi.xbee.models.protocol.Role`, optional, default=``Role.UNKNOWN``):
7130+ The role of the remote XBee
7131+
70837132 Returns:
7084- :class:`.RemoteXBeeDevice`: the remote XBee device generated from the provided data if the data
7085- provided is correct and the XBee device's protocol is valid, ``None`` otherwise.
7133+ :class:`.RemoteXBeeDevice`: the remote XBee device generated from the provided data if
7134+ the data provided is correct and the XBee device's protocol is valid, ``None``
7135+ otherwise.
70867136
70877137 .. seealso::
7088- | :meth:`.XBeeNetwork.__get_data_for_remote`
7138+ | :class:`digi.xbee.models.address.XBee16BitAddress`
7139+ | :class:`digi.xbee.models.address.XBee64BitAddress`
7140+ | :class:`digi.xbee.models.protocol.Role`
70897141 """
7090- if discovery_data is None :
7142+ if not x64bit_addr and not x16bit_addr :
70917143 return None
7144+
70927145 p = self .__xbee_device .get_protocol ()
7093- x16bit_addr , x64bit_addr , node_id , role = self .__get_data_for_remote (discovery_data )
70947146
70957147 if p == XBeeProtocol .ZIGBEE :
70967148 xb = RemoteZigBeeDevice (self .__xbee_device , x64bit_addr = x64bit_addr ,
0 commit comments