@@ -380,26 +380,27 @@ async def test_cms_responses_normal_v16(
380
380
) as ws :
381
381
# use a different id for debugging
382
382
cp = ChargePoint (f"{ cp_id } _client" , ws )
383
- with contextlib .suppress (asyncio .TimeoutError ):
384
- await asyncio .wait_for (
385
- asyncio .gather (
386
- cp .start (),
387
- cp .send_boot_notification (),
388
- cp .send_authorize (),
389
- cp .send_heartbeat (),
390
- cp .send_status_notification (),
391
- cp .send_security_event (),
392
- cp .send_firmware_status (),
393
- cp .send_data_transfer (),
394
- cp .send_start_transaction (12345 ),
395
- cp .send_meter_err_phases (),
396
- cp .send_meter_line_voltage (),
397
- cp .send_meter_periodic_data (),
398
- # add delay to allow meter data to be processed
399
- cp .send_stop_transaction (1 ),
400
- ),
401
- timeout = 8 ,
402
- )
383
+ cp_task = asyncio .create_task (cp .start ())
384
+
385
+ await cp .send_boot_notification ()
386
+ await wait_ready (cs .charge_points [cp_id ])
387
+ await cp .send_boot_notification ()
388
+ await cp .send_authorize ()
389
+ await cp .send_heartbeat ()
390
+ await cp .send_status_notification ()
391
+ await cp .send_security_event ()
392
+ await cp .send_firmware_status ()
393
+ await cp .send_data_transfer ()
394
+ await cp .send_start_transaction (12345 )
395
+ await cp .send_meter_err_phases ()
396
+ await cp .send_meter_line_voltage ()
397
+ await cp .send_meter_periodic_data ()
398
+ # add delay to allow meter data to be processed
399
+ await cp .send_stop_transaction (1 )
400
+
401
+ cp_task .cancel ()
402
+ with contextlib .suppress (asyncio .CancelledError ):
403
+ await cp_task
403
404
await ws .close ()
404
405
405
406
cpid = cs .charge_points [cp_id ].settings .cpid
@@ -485,6 +486,8 @@ async def test_cms_responses_actions_v16(
485
486
timeout = 10 ,
486
487
)
487
488
cp_task .cancel ()
489
+ with contextlib .suppress (asyncio .CancelledError ):
490
+ await cp_task
488
491
await ws .close ()
489
492
490
493
# cpid set in cs after websocket connection
@@ -638,6 +641,8 @@ async def test_cms_responses_errors_v16(
638
641
)
639
642
await cs .charge_points [cp_id ].stop ()
640
643
cp_task .cancel ()
644
+ with contextlib .suppress (asyncio .CancelledError ):
645
+ await cp_task
641
646
await ws .close ()
642
647
643
648
# test services when charger is unavailable
@@ -650,7 +655,7 @@ async def test_cms_responses_errors_v16(
650
655
@pytest .mark .timeout (20 ) # Set timeout for this test
651
656
@pytest .mark .parametrize (
652
657
"setup_config_entry" ,
653
- [{"port" : 9007 , "cp_id" : "CP_1_norm_mc" , "cms" : "cms_norm" , "num_connectors" : 2 }],
658
+ [{"port" : 9007 , "cp_id" : "CP_1_norm_mc" , "cms" : "cms_norm" }],
654
659
indirect = True ,
655
660
)
656
661
@pytest .mark .parametrize ("cp_id" , ["CP_1_norm_mc" ])
@@ -692,6 +697,8 @@ async def test_cms_responses_normal_multiple_connectors_v16(
692
697
await cp .send_stop_transaction (1 )
693
698
694
699
cp_task .cancel ()
700
+ with contextlib .suppress (asyncio .CancelledError ):
701
+ await cp_task
695
702
await ws .close ()
696
703
697
704
cpid = cs .charge_points [cp_id ].settings .cpid
@@ -770,6 +777,8 @@ async def test_clear_profile_v16(hass, socket_enabled, cp_id, port, setup_config
770
777
assert isinstance (cp .last_clear_profile_kwargs , dict )
771
778
772
779
cp_task .cancel ()
780
+ with contextlib .suppress (asyncio .CancelledError ):
781
+ await cp_task
773
782
await ws .close ()
774
783
775
784
@@ -792,7 +801,7 @@ async def set_report_session_energyreport(
792
801
)
793
802
@pytest .mark .parametrize ("cp_id" , ["CP_1_stop_paths" ])
794
803
@pytest .mark .parametrize ("port" , [9010 ])
795
- async def test_stop_transaction_paths_v16 (
804
+ async def test_stop_transaction_paths_v16_a (
796
805
hass , socket_enabled , cp_id , port , setup_config_entry
797
806
):
798
807
"""Exercise all branches of ocppv16.on_stop_transaction."""
@@ -832,8 +841,26 @@ async def test_stop_transaction_paths_v16(
832
841
assert cs .get_unit (cpid , "Energy.Session" , connector_id = 1 ) == "kWh"
833
842
834
843
cp_task .cancel ()
844
+ with contextlib .suppress (asyncio .CancelledError ):
845
+ await cp_task
835
846
await ws .close ()
836
847
848
+
849
+ # @pytest.mark.skip(reason="skip")
850
+ @pytest .mark .timeout (20 )
851
+ @pytest .mark .parametrize (
852
+ "setup_config_entry" ,
853
+ [{"port" : 9021 , "cp_id" : "CP_1_stop_paths_a1" , "cms" : "cms_stop_paths_a1" }],
854
+ indirect = True ,
855
+ )
856
+ @pytest .mark .parametrize ("cp_id" , ["CP_1_stop_paths_a1" ])
857
+ @pytest .mark .parametrize ("port" , [9021 ])
858
+ async def test_stop_transaction_paths_v16_a1 (
859
+ hass , socket_enabled , cp_id , port , setup_config_entry
860
+ ):
861
+ """Exercise all branches of ocppv16.on_stop_transaction."""
862
+ cs : CentralSystem = setup_config_entry
863
+
837
864
#
838
865
# SCENARIO A (variant): charger reports session energy AND last EAIR already kWh.
839
866
#
@@ -862,8 +889,26 @@ async def test_stop_transaction_paths_v16(
862
889
assert cs .get_unit (cpid , "Energy.Session" , connector_id = 1 ) == "kWh"
863
890
864
891
cp_task .cancel ()
892
+ with contextlib .suppress (asyncio .CancelledError ):
893
+ await cp_task
865
894
await ws .close ()
866
895
896
+
897
+ # @pytest.mark.skip(reason="skip")
898
+ @pytest .mark .timeout (20 )
899
+ @pytest .mark .parametrize (
900
+ "setup_config_entry" ,
901
+ [{"port" : 9022 , "cp_id" : "CP_1_stop_paths_b" , "cms" : "cms_stop_paths_b" }],
902
+ indirect = True ,
903
+ )
904
+ @pytest .mark .parametrize ("cp_id" , ["CP_1_stop_paths_b" ])
905
+ @pytest .mark .parametrize ("port" , [9022 ])
906
+ async def test_stop_transaction_paths_v16_b (
907
+ hass , socket_enabled , cp_id , port , setup_config_entry
908
+ ):
909
+ """Exercise all branches of ocppv16.on_stop_transaction."""
910
+ cs : CentralSystem = setup_config_entry
911
+
867
912
#
868
913
# SCENARIO B: charger reports session energy BUT SessionEnergy already set → do not overwrite.
869
914
#
@@ -895,8 +940,26 @@ async def test_stop_transaction_paths_v16(
895
940
assert round (sess , 3 ) == 7.777 # unchanged
896
941
897
942
cp_task .cancel ()
943
+ with contextlib .suppress (asyncio .CancelledError ):
944
+ await cp_task
898
945
await ws .close ()
899
946
947
+
948
+ # @pytest.mark.skip(reason="skip")
949
+ @pytest .mark .timeout (20 )
950
+ @pytest .mark .parametrize (
951
+ "setup_config_entry" ,
952
+ [{"port" : 9023 , "cp_id" : "CP_1_stop_paths_c" , "cms" : "cms_stop_paths_c" }],
953
+ indirect = True ,
954
+ )
955
+ @pytest .mark .parametrize ("cp_id" , ["CP_1_stop_paths_c" ])
956
+ @pytest .mark .parametrize ("port" , [9023 ])
957
+ async def test_stop_transaction_paths_v16_c (
958
+ hass , socket_enabled , cp_id , port , setup_config_entry
959
+ ):
960
+ """Exercise all branches of ocppv16.on_stop_transaction."""
961
+ cs : CentralSystem = setup_config_entry
962
+
900
963
#
901
964
# SCENARIO C: _charger_reports_session_energy = False -> compute from meter_stop - meter_start
902
965
#
@@ -1048,6 +1111,8 @@ async def test_on_meter_values_paths_v16(
1048
1111
1049
1112
finally :
1050
1113
cp_task .cancel ()
1114
+ with contextlib .suppress (asyncio .CancelledError ):
1115
+ await cp_task
1051
1116
await ws .close ()
1052
1117
1053
1118
@@ -1163,6 +1228,8 @@ def fake_get_ha_metric(name: str, connector_id: int | None = None):
1163
1228
assert cs .get_unit (cpid , "Energy.Session" , connector_id = 1 ) == "kWh"
1164
1229
1165
1230
cp_task .cancel ()
1231
+ with contextlib .suppress (asyncio .CancelledError ):
1232
+ await cp_task
1166
1233
await ws .close ()
1167
1234
1168
1235
@@ -1225,6 +1292,8 @@ async def test_api_get_extra_attr_paths(
1225
1292
1226
1293
# Clean up
1227
1294
cp_task .cancel ()
1295
+ with contextlib .suppress (asyncio .CancelledError ):
1296
+ await cp_task
1228
1297
await ws .close ()
1229
1298
1230
1299
@@ -1273,6 +1342,8 @@ async def test_update_firmware_supported_valid_url_v16(
1273
1342
)
1274
1343
1275
1344
cp_task .cancel ()
1345
+ with contextlib .suppress (asyncio .CancelledError ):
1346
+ await cp_task
1276
1347
await ws .close ()
1277
1348
1278
1349
@@ -1315,6 +1386,8 @@ async def test_update_firmware_supported_invalid_url_v16(
1315
1386
assert getattr (cp , "last_update_firmware" , None ) is None
1316
1387
1317
1388
cp_task .cancel ()
1389
+ with contextlib .suppress (asyncio .CancelledError ):
1390
+ await cp_task
1318
1391
await ws .close ()
1319
1392
1320
1393
@@ -1357,6 +1430,8 @@ async def test_update_firmware_not_supported_v16(
1357
1430
assert getattr (cp , "last_update_firmware" , None ) is None
1358
1431
1359
1432
cp_task .cancel ()
1433
+ with contextlib .suppress (asyncio .CancelledError ):
1434
+ await cp_task
1360
1435
await ws .close ()
1361
1436
1362
1437
@@ -1402,17 +1477,19 @@ async def boom(_req):
1402
1477
assert getattr (cp , "last_update_firmware" , None ) is None
1403
1478
1404
1479
cp_task .cancel ()
1480
+ with contextlib .suppress (asyncio .CancelledError ):
1481
+ await cp_task
1405
1482
await ws .close ()
1406
1483
1407
1484
1408
1485
@pytest .mark .timeout (20 )
1409
1486
@pytest .mark .parametrize (
1410
1487
"setup_config_entry" ,
1411
- [{"port" : 9018 , "cp_id" : "CP_1_unit_fallback" , "cms" : "cms_unit_fallback" }],
1488
+ [{"port" : 9020 , "cp_id" : "CP_1_unit_fallback" , "cms" : "cms_unit_fallback" }],
1412
1489
indirect = True ,
1413
1490
)
1414
1491
@pytest .mark .parametrize ("cp_id" , ["CP_1_unit_fallback" ])
1415
- @pytest .mark .parametrize ("port" , [9018 ])
1492
+ @pytest .mark .parametrize ("port" , [9020 ])
1416
1493
async def test_api_get_unit_fallback_to_later_connectors (
1417
1494
hass , socket_enabled , cp_id , port , setup_config_entry
1418
1495
):
@@ -1453,6 +1530,8 @@ async def test_api_get_unit_fallback_to_later_connectors(
1453
1530
1454
1531
# Cleanup
1455
1532
cp_task .cancel ()
1533
+ with contextlib .suppress (asyncio .CancelledError ):
1534
+ await cp_task
1456
1535
await ws .close ()
1457
1536
1458
1537
@@ -1523,6 +1602,8 @@ async def test_api_get_extra_attr_fallback_to_later_connectors(
1523
1602
1524
1603
# Cleanup
1525
1604
cp_task .cancel ()
1605
+ with contextlib .suppress (asyncio .CancelledError ):
1606
+ await cp_task
1526
1607
await ws .close ()
1527
1608
1528
1609
@@ -1651,7 +1732,6 @@ async def test_get_diagnostics_and_data_transfer_v16(
1651
1732
cp_task .cancel ()
1652
1733
with contextlib .suppress (asyncio .CancelledError ):
1653
1734
await cp_task
1654
-
1655
1735
await ws .close ()
1656
1736
1657
1737
0 commit comments