From f7e7e4a2a2886f6416d9826129fa0f1ea1d0e652 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Sat, 4 Jan 2025 16:28:31 +0000 Subject: [PATCH] Don't enable low power in monitor mode (#1841) * Don't enable low power in monitor mode https://github.com/springfall2008/batpred/issues/1816 * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- apps/predbat/prediction.py | 3 ++- apps/predbat/unit_test.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/predbat/prediction.py b/apps/predbat/prediction.py index 0a4a22d8..2e63e8bc 100644 --- a/apps/predbat/prediction.py +++ b/apps/predbat/prediction.py @@ -116,6 +116,7 @@ def __init__(self, base=None, pv_forecast_minute_step=None, pv_forecast_minute10 self.set_discharge_during_charge = base.set_discharge_during_charge self.set_read_only = base.set_read_only self.set_charge_low_power = base.set_charge_low_power + self.set_charge_window = base.set_charge_window self.charge_low_power_margin = base.charge_low_power_margin self.car_charging_slots = base.car_charging_slots self.car_charging_limit = base.car_charging_limit @@ -642,7 +643,7 @@ def run_prediction(self, charge_limit, charge_window, export_window, export_limi four_hour_rule = False elif (charge_window_n >= 0) and soc < charge_limit_n: # Charge enable - if save in ["best", "best10", "test"]: + if self.set_charge_window and (save in ["best", "best10", "test"]): # Only tune charge rate on final plan not every simulation charge_rate_now = find_charge_rate( minute_absolute, diff --git a/apps/predbat/unit_test.py b/apps/predbat/unit_test.py index 7f9777e7..dc14e8dc 100644 --- a/apps/predbat/unit_test.py +++ b/apps/predbat/unit_test.py @@ -1439,6 +1439,8 @@ def simple_scenario( assert_iboost_running_full=False, car_soc=0, car_limit=100, + set_charge_low_power=False, + set_charge_window=True, ): """ No PV, No Load @@ -1463,6 +1465,8 @@ def simple_scenario( my_predbat.battery_rate_max_charge_scaled = battery_rate_max_charge / 60.0 my_predbat.battery_rate_max_discharge_scaled = battery_rate_max_charge / 60.0 my_predbat.car_charging_from_battery = car_charging_from_battery + my_predbat.set_charge_low_power = set_charge_low_power + my_predbat.set_charge_window = set_charge_window my_predbat.iboost_enable = iboost_enable my_predbat.iboost_gas = iboost_gas @@ -4721,6 +4725,15 @@ def run_model_tests(my_predbat): ) failed |= simple_scenario("pv_only_bat_dc_export_limit_load", my_predbat, 0.5, 3, assert_final_metric=-export_rate * 24 * 0.5, assert_final_soc=24, with_battery=True, hybrid=True, export_limit=0.5) failed |= simple_scenario("battery_charge", my_predbat, 0, 0, assert_final_metric=import_rate * 10, assert_final_soc=10, with_battery=True, charge=10, battery_size=10) + + failed |= simple_scenario("battery_charge_low_off", my_predbat, 0, 0, assert_final_metric=import_rate * 10, assert_final_soc=10, with_battery=True, charge=10, battery_size=10, set_charge_low_power=False, keep=5, assert_keep=24.59) + failed |= simple_scenario("battery_charge_low_on", my_predbat, 0, 0, assert_final_metric=import_rate * 10, assert_final_soc=10, with_battery=True, charge=10, battery_size=10, set_charge_low_power=True, keep=5, assert_keep=88.89) + failed |= simple_scenario( + "battery_charge_low_on_monitor", my_predbat, 0, 0, assert_final_metric=import_rate * 10, assert_final_soc=10, with_battery=True, charge=10, battery_size=10, set_charge_low_power=True, keep=5, assert_keep=24.59, set_charge_window=False + ) + + if failed: + return failed failed |= simple_scenario("battery_charge_prev_charge", my_predbat, 0, 0, assert_final_metric=import_rate * 10, assert_final_soc=10, with_battery=True, charge=10, battery_size=10) failed |= simple_scenario(