Skip to content

Commit fbf1610

Browse files
test(octopus): restore shared state on failure, and check the suspended switch is really published (#5341 review)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent afb51ce commit fbf1610

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎apps/predbat/tests/test_octopus_smart_control.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"car_charging_soc",
4646
"car_charging_soc_next",
4747
"car_charging_loss",
48+
"car_charging_limit_model",
4849
)
4950
ARG_KEYS = ("car_charging_loss", "car_charging_soc", "car_charging_limit", "octopus_intelligent_slot", "octopus_intelligent_smart_control")
5051

‎apps/predbat/tests/test_octopus_smart_control_switch.py‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,21 @@ async def _switch_back_on_while_sending(query, *args, **kwargs):
186186
# because my_predbat is shared by every test in the run
187187
original_args = dict(my_predbat.args)
188188
del api.set_arg
189-
api.intelligent_devices[ACTIVE_ID]["suspended"] = False
190-
api.intelligent_devices[SUSPENDED_ID]["suspended"] = True
191-
api.automatic_config({})
192-
failed |= _check("t7 switch wired", my_predbat.args.get("octopus_intelligent_smart_control") == [active_switch], "args {}".format(my_predbat.args))
193-
failed |= _check("t7 slot wired alongside", len(my_predbat.args.get("octopus_intelligent_slot", [])) == 1, "args {}".format(my_predbat.args))
194-
api.intelligent_devices[ACTIVE_ID]["suspended"] = True
195-
api.automatic_config({})
196-
failed |= _check("t7 none when all suspended", my_predbat.args.get("octopus_intelligent_smart_control") == [], "args {}".format(my_predbat.args))
197-
failed |= _check("t7 switches still published for suspended", api.published.get(active_switch) is not None, "")
198-
my_predbat.args.clear()
199-
my_predbat.args.update(original_args)
189+
try:
190+
api.intelligent_devices[ACTIVE_ID]["suspended"] = False
191+
api.intelligent_devices[SUSPENDED_ID]["suspended"] = True
192+
api.automatic_config({})
193+
failed |= _check("t7 switch wired", my_predbat.args.get("octopus_intelligent_smart_control") == [active_switch], "args {}".format(my_predbat.args))
194+
failed |= _check("t7 slot wired alongside", len(my_predbat.args.get("octopus_intelligent_slot", [])) == 1, "args {}".format(my_predbat.args))
195+
api.intelligent_devices[ACTIVE_ID]["suspended"] = True
196+
api.automatic_config({})
197+
failed |= _check("t7 none when all suspended", my_predbat.args.get("octopus_intelligent_smart_control") == [], "args {}".format(my_predbat.args))
198+
api.published = {}
199+
await api.async_intelligent_update_sensor("acc-1")
200+
failed |= _check("t7 switches still published for suspended", api.published.get(active_switch) == "off" and api.published.get(suspended_switch) == "off", "published {}".format(api.published))
201+
finally:
202+
my_predbat.args.clear()
203+
my_predbat.args.update(original_args)
200204
return failed
201205

202206

0 commit comments

Comments
 (0)