|
66 | 66 | "car_charging_battery_size", |
67 | 67 | ) |
68 | 68 | IOG_SENSOR = "binary_sensor.octopus_intelligent_slot_test" |
| 69 | +SAVED_ARGS = ("car_charging_now", "octopus_intelligent_slot", "car_charging_now_response") |
69 | 70 |
|
70 | 71 |
|
71 | 72 | def _check(name, condition, detail=""): |
@@ -377,23 +378,49 @@ def _run_power(my_predbat): |
377 | 378 | return failed |
378 | 379 |
|
379 | 380 |
|
| 381 | +def _run_default_response(my_predbat): |
| 382 | + """ |
| 383 | + With car_charging_now_response unset, a charger status sensor reading "Charging" (e.g. a Zappi's |
| 384 | + plug_status) counts as charging. It did not before (GH#5335), so the Octopus Intelligent check |
| 385 | + cancelled the car's dispatch while it charged and the house battery lost the dispatch rate. |
| 386 | + """ |
| 387 | + failed = False |
| 388 | + print("Test 23: the default car_charging_now_response accepts a charger's Charging status") |
| 389 | + _car(my_predbat, False) |
| 390 | + my_predbat.args.pop("car_charging_now_response", None) |
| 391 | + for state, expected in (("Charging", True), ("EV Connected", False), ("on", True), ("off", False)): |
| 392 | + _sensor(my_predbat, state) |
| 393 | + my_predbat.get_car_charging_planned() |
| 394 | + failed |= _check("t23 cycle {!r}".format(state), my_predbat.car_charging_now == [expected], "now {}".format(my_predbat.car_charging_now)) |
| 395 | + failed |= _check("t23 live {!r}".format(state), my_predbat.car_charging_now_reading(0) is expected, "") |
| 396 | + |
| 397 | + print("Test 24: a car_charging_now_response set in apps.yaml replaces the default rather than adding to it") |
| 398 | + my_predbat.args["car_charging_now_response"] = ["yes", "on", "true"] |
| 399 | + _sensor(my_predbat, "Charging") |
| 400 | + my_predbat.get_car_charging_planned() |
| 401 | + failed |= _check("t24 Charging not in the set list", my_predbat.car_charging_now == [False], "now {}".format(my_predbat.car_charging_now)) |
| 402 | + _sensor(my_predbat, None) |
| 403 | + return failed |
| 404 | + |
| 405 | + |
380 | 406 | def test_car_charging_now(my_predbat): |
381 | 407 | """ |
382 | 408 | car_charging_now holds the battery and feeds the model, but never adds a car slot. |
383 | 409 | """ |
384 | 410 | print("*** Running test: car_charging_now") |
385 | 411 | saved_state = {field: copy.deepcopy(getattr(my_predbat, field, None)) for field in STATE_FIELDS} |
386 | | - saved_args = {key: copy.deepcopy(my_predbat.args[key]) for key in ("car_charging_now", "octopus_intelligent_slot") if key in my_predbat.args} |
| 412 | + saved_args = {key: copy.deepcopy(my_predbat.args[key]) for key in SAVED_ARGS if key in my_predbat.args} |
387 | 413 | try: |
388 | 414 | failed = _run_plan(my_predbat) |
389 | 415 | failed |= _run_poll(my_predbat) |
390 | 416 | failed |= _run_dynamic(my_predbat) |
391 | 417 | failed |= _run_iog(my_predbat) |
392 | 418 | failed |= _run_power(my_predbat) |
| 419 | + failed |= _run_default_response(my_predbat) |
393 | 420 | finally: |
394 | 421 | for field, value in saved_state.items(): |
395 | 422 | setattr(my_predbat, field, value) |
396 | | - for key in ("car_charging_now", "octopus_intelligent_slot"): |
| 423 | + for key in SAVED_ARGS: |
397 | 424 | if key in saved_args: |
398 | 425 | my_predbat.args[key] = saved_args[key] |
399 | 426 | else: |
|
0 commit comments