@@ -624,40 +624,43 @@ def test_saving_session_custom_entity_no_rewrite_match(my_predbat):
624624friendly_name: Predbat Octopus Power Down For Predbat
625625"""
626626
627- ha .dummy_items .clear ()
628- ha .dummy_items ["binary_sensor.predbat_octopus_power_down_for_predbat" ] = yaml .safe_load (session_binary )
629- ha .dummy_items ["sensor.octopus_free_session" ] = {}
630- my_predbat .args ["octopus_saving_session" ] = "binary_sensor.predbat_octopus_power_down_for_predbat"
631- my_predbat .args ["octopus_free_session" ] = "sensor.octopus_free_session"
632- if "octopus_free_url" in my_predbat .args :
633- del my_predbat .args ["octopus_free_url" ]
634- if "octopus_saving_session_join" in my_predbat .args :
635- del my_predbat .args ["octopus_saving_session_join" ]
636- my_predbat .args ["octopus_saving_session_octopoints_per_penny" ] = 10
637- # Reset throttle so a join is attempted
638- my_predbat .octopus_last_joined_try = None
639-
640- ha .service_store_enable = True
641- ha .service_store = []
642- my_predbat .fetch_octopus_sessions ()
643- service_result = ha .get_service_store ()
644- ha .service_store_enable = False
627+ saved_args = my_predbat .args .copy ()
628+ try :
629+ ha .dummy_items .clear ()
630+ ha .dummy_items ["binary_sensor.predbat_octopus_power_down_for_predbat" ] = yaml .safe_load (session_binary )
631+ ha .dummy_items ["sensor.octopus_free_session" ] = {}
632+ my_predbat .args ["octopus_saving_session" ] = "binary_sensor.predbat_octopus_power_down_for_predbat"
633+ my_predbat .args ["octopus_free_session" ] = "sensor.octopus_free_session"
634+ if "octopus_free_url" in my_predbat .args :
635+ del my_predbat .args ["octopus_free_url" ]
636+ if "octopus_saving_session_join" in my_predbat .args :
637+ del my_predbat .args ["octopus_saving_session_join" ]
638+ my_predbat .args ["octopus_saving_session_octopoints_per_penny" ] = 10
639+ # Reset throttle so a join is attempted
640+ my_predbat .octopus_last_joined_try = None
645641
646- join_calls = [svc for svc in service_result if "join" in svc [0 ]]
647- if len (join_calls ) != 1 :
648- print (f"ERROR: Expected 1 join call reading available_events from the configured entity, got { len (join_calls )} : { service_result } " )
649- failed = True
650- elif join_calls [0 ][1 ].get ("entity_id" ) != "binary_sensor.predbat_octopus_power_down_for_predbat" :
651- print (f"ERROR: Expected join call to use the configured entity, got { join_calls [0 ][1 ]} " )
652- failed = True
653- else :
654- print (" PASS: available_events read from the configured entity despite no rewrite match" )
642+ ha .service_store_enable = True
643+ ha .service_store = []
644+ my_predbat .fetch_octopus_sessions ()
645+ service_result = ha .get_service_store ()
646+ ha .service_store_enable = False
655647
656- if not failed :
657- print ("PASS: Custom entity name (no rewrite match) auto-join test passed" )
648+ join_calls = [svc for svc in service_result if "join" in svc [0 ]]
649+ if len (join_calls ) != 1 :
650+ print (f"ERROR: Expected 1 join call reading available_events from the configured entity, got { len (join_calls )} : { service_result } " )
651+ failed = True
652+ elif join_calls [0 ][1 ].get ("entity_id" ) != "binary_sensor.predbat_octopus_power_down_for_predbat" :
653+ print (f"ERROR: Expected join call to use the configured entity, got { join_calls [0 ][1 ]} " )
654+ failed = True
655+ else :
656+ print (" PASS: available_events read from the configured entity despite no rewrite match" )
658657
659- # Restore default throttle state so we do not leak it to other tests
660- my_predbat .octopus_last_joined_try = None
658+ if not failed :
659+ print ("PASS: Custom entity name (no rewrite match) auto-join test passed" )
660+ finally :
661+ my_predbat .args = saved_args
662+ # Restore default throttle state so we do not leak it to other tests
663+ my_predbat .octopus_last_joined_try = None
661664
662665 return failed
663666
0 commit comments