@@ -1739,16 +1739,22 @@ def get_bluetooth_mac_addr(self):
17391739 return utils .hex_to_string (
17401740 self .get_parameter (ATStringCommand .BL , apply = False ), pretty = False )
17411741
1742- def update_bluetooth_password (self , new_password ):
1742+ def update_bluetooth_password (self , new_password , apply = True , save = True ):
17431743 """
17441744 Changes the Bluetooth password of this XBee with the new one provided.
17451745
17461746 Note that your device must include Bluetooth Low Energy support.
17471747
17481748 Args:
17491749 new_password (String): New Bluetooth password.
1750+ apply (Boolean, optional, default=`True`): `True` to apply changes,
1751+ `False` otherwise, `None` to use `is_apply_changes_enabled()`
1752+ returned value.
1753+ save (Boolean, optional, default=`True`): `True` to save changes,
1754+ `False` otherwise.
17501755
17511756 Raises:
1757+ ValueError: If `new_password` is invalid.
17521758 TimeoutException: If response is not received before the read
17531759 timeout expires.
17541760 XBeeException: If the XBee's communication interface is closed.
@@ -1757,13 +1763,52 @@ def update_bluetooth_password(self, new_password):
17571763 the operating mode.
17581764 ATCommandException: If response is not as expected.
17591765 """
1766+ if not isinstance (new_password , (str , bytes , bytearray )):
1767+ raise ValueError ("Password must be a string, bytes, or bytearray" )
1768+
17601769 import srp
17611770
17621771 # Generate the salt and verifier using the SRP library.
17631772 salt , verifier = srp .create_salted_verification_key (
17641773 self ._BLE_API_USERNAME , new_password , hash_alg = srp .SHA256 ,
17651774 ng_type = srp .NG_1024 , salt_len = 4 )
17661775
1776+ self .update_bluetooth_salt_verifier (salt , verifier , apply = apply , save = save )
1777+
1778+ def update_bluetooth_salt_verifier (self , salt , verifier , apply = True , save = True ):
1779+ """
1780+ Changes the Bluetooth password of this XBee with the new one provided.
1781+
1782+ Note that your device must include Bluetooth Low Energy support.
1783+
1784+ Args:
1785+ salt (bytes): New Bluetooth password.
1786+ verifier (bytes): `True` to apply changes,
1787+ `False` otherwise, `None` to use `is_apply_changes_enabled()`
1788+ returned value.
1789+ apply (Boolean, optional, default=`True`): `True` to apply changes,
1790+ `False` otherwise, `None` to use `is_apply_changes_enabled()`
1791+ returned value.
1792+ save (Boolean, optional, default=`True`): `True` to save changes,
1793+ `False` otherwise.
1794+
1795+ Raises:
1796+ ValueError: If `salt` or `verifier` are invalid.
1797+ TimeoutException: If response is not received before the read
1798+ timeout expires.
1799+ XBeeException: If the XBee's communication interface is closed.
1800+ InvalidOperatingModeException: If the XBee's operating mode is not
1801+ API or ESCAPED API. This method only checks the cached value of
1802+ the operating mode.
1803+ ATCommandException: If response is not as expected.
1804+ """
1805+ if not isinstance (salt , (bytes , bytearray )):
1806+ raise ValueError ("Salt must be a bytes or bytearray" )
1807+ if not isinstance (verifier , (bytes , bytearray )):
1808+ raise ValueError ("Verifier must be a bytes or bytearray" )
1809+
1810+ apply_changes = apply if apply is not None else self .is_apply_changes_enabled ()
1811+
17671812 # Ensure the verifier is 128 bytes.
17681813 verifier = (128 - len (verifier )) * b'\x00 ' + verifier
17691814
@@ -1784,11 +1829,11 @@ def update_bluetooth_password(self, new_password):
17841829 verifier [index :(index + at_length )], apply = False )
17851830 index += at_length
17861831 self .set_parameter (ATStringCommand .DOLLAR_Y ,
1787- verifier [index :(index + at_length )], apply = False )
1832+ verifier [index :(index + at_length )], apply = apply_changes and not save )
17881833
17891834 # Write and apply changes.
1790- self . write_changes ()
1791- self .apply_changes ( )
1835+ if save :
1836+ self .execute_command ( ATStringCommand . WR , apply = apply_changes )
17921837
17931838 def update_firmware (self , xml_firmware_file , xbee_firmware_file = None ,
17941839 bootloader_firmware_file = None , timeout = None , progress_callback = None ):
0 commit comments