Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/predbat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2090,8 +2090,8 @@
"export_limit": {"type": "sensor_list", "sensor_type": "float", "entries": "num_inverters"},
"inverter_battery_rate_min": {"type": "integer", "zero": False, "entries": "num_inverters"},
"inverter_reserve_max": {"type": "integer", "zero": False, "entries": "num_inverters"},
"battery_charge_power_curve": {"type": "int_float_dict"},
"battery_discharge_power_curve": {"type": "int_float_dict"},
"battery_charge_power_curve": {"type": "int_float_dict", "or_auto": True},
"battery_discharge_power_curve": {"type": "int_float_dict", "or_auto": True},
"battery_charge_power_curve_default": {"type": "int_float_dict"},
"battery_discharge_power_curve_default": {"type": "int_float_dict"},
"clock_skew": {"type": "integer"},
Expand Down
4 changes: 3 additions & 1 deletion apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,9 @@ def validate_config(self):
errors += 1
break
elif expected_type == "int_float_dict":
if isinstance(value, dict):
if spec.get("or_auto", False) and value == "auto":
matches = True
elif isinstance(value, dict):
matches = True
for key in value:
if not self.validate_is_int(key):
Expand Down
20 changes: 20 additions & 0 deletions apps/predbat/tests/test_battery_curve_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def run_battery_curve_keys_tests(my_predbat):
test_get_curve_value_with_string_keys(my_predbat)
test_get_curve_value_with_mixed_keys(my_predbat)
test_get_curve_value_custom_default(my_predbat)
test_validate_config_auto_curve(my_predbat)
print("**** Battery curve keys tests: All tests passed ****")
except AssertionError as e:
print(f"**** Battery curve keys tests FAILED: {e} ****")
Expand Down Expand Up @@ -76,6 +77,25 @@ def test_get_curve_value_custom_default(my_predbat):
print("✓ Custom default test passed")


def test_validate_config_auto_curve(my_predbat):
"""Test that battery_charge_power_curve and battery_discharge_power_curve set to 'auto' passes validation"""
original_args = my_predbat.args.copy()
try:
# Get baseline error count without the curve settings
my_predbat.args.pop("battery_charge_power_curve", None)
my_predbat.args.pop("battery_discharge_power_curve", None)
baseline_errors = my_predbat.validate_config()

# Now set both curves to "auto" and verify no additional errors are introduced
my_predbat.args["battery_charge_power_curve"] = "auto"
my_predbat.args["battery_discharge_power_curve"] = "auto"
errors_with_auto = my_predbat.validate_config()
assert errors_with_auto == baseline_errors, f"Setting curves to 'auto' introduced extra validation errors: baseline={baseline_errors}, with_auto={errors_with_auto}"
print("✓ Auto curve validation test passed")
finally:
my_predbat.args = original_args


if __name__ == "__main__":
# Note: When running standalone, validate_curve is not available
# This is meant to be run through the test framework with my_predbat instance
Expand Down
Loading