@@ -756,7 +756,7 @@ def send_unicast(aps_frame, data, message_tag, nwk):
756756 )
757757
758758 await app .send_packet (packet )
759- app ._concurrent_requests_semaphore .max_value = 10000
759+ app ._concurrent_requests_semaphore .max_concurrency = 10000
760760 results = await asyncio .gather (
761761 * (app .send_packet (packet ) for _ in range (256 + 1 )), return_exceptions = True
762762 )
@@ -1024,7 +1024,7 @@ async def test_send_packet_unicast_concurrency(app, packet, monkeypatch):
10241024 monkeypatch .setattr (bellows .zigbee .application , "MESSAGE_SEND_TIMEOUT_MAINS" , 0.5 )
10251025 monkeypatch .setattr (bellows .zigbee .application , "MESSAGE_SEND_TIMEOUT_BATTERY" , 0.5 )
10261026
1027- app ._concurrent_requests_semaphore .max_value = 10
1027+ app ._concurrent_requests_semaphore .max_concurrency = 12
10281028
10291029 max_concurrency = 0
10301030 in_flight_requests = 0
@@ -1073,9 +1073,14 @@ async def send_unicast(nwk, aps_frame, message_tag, data):
10731073
10741074 app ._ezsp .send_unicast = AsyncMock (side_effect = send_unicast )
10751075
1076- responses = await asyncio .gather (* [app .send_packet (packet ) for _ in range (100 )])
1076+ responses = await asyncio .gather (
1077+ * [
1078+ app .send_packet (packet .replace (priority = zigpy_t .PacketPriority .HIGH ))
1079+ for _ in range (100 )
1080+ ]
1081+ )
10771082 assert len (responses ) == 100
1078- assert max_concurrency == 10
1083+ assert max_concurrency == 12
10791084 assert in_flight_requests == 0
10801085
10811086
@@ -2027,6 +2032,96 @@ async def test_write_network_info(
20272032 ]
20282033
20292034
2035+ @pytest .mark .parametrize (
2036+ ("node_ieee" , "current_eui64" , "can_rewrite" , "can_burn" , "confirmation_flag" ),
2037+ [
2038+ (
2039+ zigpy_t .EUI64 .UNKNOWN ,
2040+ t .EUI64 .convert ("00:01:02:03:04:05:06:07" ),
2041+ False ,
2042+ False ,
2043+ False ,
2044+ ),
2045+ (
2046+ t .EUI64 .convert ("00:01:02:03:04:05:06:07" ),
2047+ t .EUI64 .convert ("00:01:02:03:04:05:06:07" ),
2048+ False ,
2049+ False ,
2050+ False ,
2051+ ),
2052+ (
2053+ t .EUI64 .convert ("aa:aa:aa:aa:aa:aa:aa:aa" ),
2054+ t .EUI64 .convert ("00:01:02:03:04:05:06:07" ),
2055+ True ,
2056+ False ,
2057+ False ,
2058+ ),
2059+ (
2060+ t .EUI64 .convert ("aa:aa:aa:aa:aa:aa:aa:aa" ),
2061+ t .EUI64 .convert ("00:01:02:03:04:05:06:07" ),
2062+ False ,
2063+ True ,
2064+ True ,
2065+ ),
2066+ ],
2067+ )
2068+ async def test_can_write_network_settings (
2069+ app : ControllerApplication ,
2070+ zigpy_backup : zigpy .backups .NetworkBackup ,
2071+ node_ieee : t .EUI64 ,
2072+ current_eui64 : t .EUI64 ,
2073+ can_rewrite : bool ,
2074+ can_burn : bool ,
2075+ confirmation_flag : bool ,
2076+ ) -> None :
2077+ """Test `can_write_network_settings`."""
2078+ app ._ezsp .getEui64 = AsyncMock (return_value = [current_eui64 ])
2079+ app ._ezsp .can_rewrite_custom_eui64 = AsyncMock (return_value = can_rewrite )
2080+ app ._ezsp .can_burn_userdata_custom_eui64 = AsyncMock (return_value = can_burn )
2081+ app ._get_board_info = AsyncMock (
2082+ return_value = ("Mock board" , "Mock Manufacturer" , "Mock version" )
2083+ )
2084+
2085+ node_info = zigpy_backup .node_info .replace (ieee = node_ieee )
2086+ network_info = zigpy_backup .network_info
2087+
2088+ if confirmation_flag :
2089+ network_info = network_info .replace (
2090+ stack_specific = {
2091+ "ezsp" : {
2092+ ** network_info .stack_specific .get ("ezsp" , {}),
2093+ "i_understand_i_can_update_eui64_only_once_and_i_still_want_to_do_it" : True ,
2094+ }
2095+ }
2096+ )
2097+
2098+ assert await app .can_write_network_settings (
2099+ network_info = network_info ,
2100+ node_info = node_info ,
2101+ )
2102+
2103+
2104+ async def test_write_network_info_uses_write_custom_eui64 (
2105+ app : ControllerApplication ,
2106+ zigpy_backup : zigpy .backups .NetworkBackup ,
2107+ ) -> None :
2108+ """Test that `write_network_info` uses `write_custom_eui64` correctly."""
2109+ app ._ezsp .can_rewrite_custom_eui64 = AsyncMock (return_value = True )
2110+ app ._ezsp .write_custom_eui64 = AsyncMock ()
2111+
2112+ different_ieee = t .EUI64 .convert ("aa:aa:aa:aa:aa:aa:aa:aa" )
2113+ node_info = zigpy_backup .node_info .replace (ieee = different_ieee )
2114+
2115+ with patch .object (app , "_reset" ):
2116+ await app .write_network_info (
2117+ node_info = node_info ,
2118+ network_info = zigpy_backup .network_info ,
2119+ )
2120+
2121+ # Verify write_custom_eui64 was called without burn_into_userdata flag
2122+ assert app ._ezsp .write_custom_eui64 .mock_calls == [call (different_ieee )]
2123+
2124+
20302125async def test_network_scan (app : ControllerApplication ) -> None :
20312126 app ._ezsp ._protocol .startScan .return_value = [t .sl_Status .OK ]
20322127
@@ -2209,7 +2304,7 @@ async def test_migration_failure_eui64_overwrite_confirmation(
22092304 # Migration explicitly fails if we need to write the EUI64 but the adapter treats it
22102305 # as a write-once operation
22112306 with pytest .raises (
2212- zigpy .exceptions .ControllerException ,
2307+ zigpy .exceptions .DestructiveWriteNetworkSettings ,
22132308 match = (
22142309 "Please upgrade your adapter firmware. The adapter IEEE address needs to be"
22152310 " replaced and firmware 'Mock version' does not support writing it multiple"
@@ -2229,7 +2324,7 @@ async def test_migration_failure_eui64_overwrite_confirmation(
22292324 app ._ezsp , "write_custom_eui64" , wraps = app ._ezsp .write_custom_eui64
22302325 ), patch .object (app ._ezsp , "can_burn_userdata_custom_eui64" , return_value = False ):
22312326 with pytest .raises (
2232- zigpy .exceptions .ControllerException ,
2327+ zigpy .exceptions .CannotWriteNetworkSettings ,
22332328 match = (
22342329 "Please upgrade your adapter firmware. The adapter IEEE address has"
22352330 " been overwritten and firmware 'Mock version' does not support writing"
0 commit comments