From db307176ce26c8e253e527fe9a3c2fdcf72fa7da Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 18:36:43 +0000 Subject: [PATCH] [pre-commit.ci lite] apply automatic fixes --- apps/predbat/predbat.py | 2 +- apps/predbat/unit_test.py | 41 +++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 62129dc8..89ffbfe0 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -438,7 +438,7 @@ def reset(self): self.computed_charge_curve = False self.computed_discharge_curve = False self.isCharging = False - self.isCharging_Target = 0 + self.isCharging_Target = 0 self.isExporting = False self.isExporting_Target = 0 self.savings_today_predbat = 0.0 diff --git a/apps/predbat/unit_test.py b/apps/predbat/unit_test.py index 37c67a72..8bbd88e0 100644 --- a/apps/predbat/unit_test.py +++ b/apps/predbat/unit_test.py @@ -998,6 +998,7 @@ def call_service_template(self, service, data, domain="charge", extra_data={}) ha.service_store_enable = False return failed + def run_car_charging_smart_test(test_name, my_predbat, battery_size=10.0, limit=8.0, soc=0, rate=10.0, loss=1.0, max_price=99, smart=True, plan_time="00:00:00", expect_cost=0, expect_kwh=0): """ Run a car charging smart test @@ -1036,9 +1037,10 @@ def run_car_charging_smart_test(test_name, my_predbat, battery_size=10.0, limit= print("ERROR: Car charging total cost should be {} got {}".format(expect_cost, total_cost)) failed = True print(slots) - + return failed + def run_car_charging_smart_tests(my_predbat): """ Test car charging smart @@ -1056,13 +1058,14 @@ def run_car_charging_smart_tests(my_predbat): failed |= run_car_charging_smart_test("smart2", my_predbat, battery_size=12.0, limit=10.0, soc=0, rate=10.0, loss=1.0, max_price=99, smart=False, expect_cost=150, expect_kwh=10) failed |= run_car_charging_smart_test("smart3", my_predbat, battery_size=12.0, limit=10.0, soc=2, rate=10.0, loss=1.0, max_price=99, smart=True, expect_cost=80, expect_kwh=8) failed |= run_car_charging_smart_test("smart4", my_predbat, battery_size=12.0, limit=10.0, soc=2, rate=10.0, loss=0.5, max_price=99, smart=True, expect_cost=160, expect_kwh=16) - failed |= run_car_charging_smart_test("smart5", my_predbat, battery_size=100.0, limit=100.0, soc=0, rate=1.0, loss=1, max_price=99, smart=True, expect_cost=12*15, expect_kwh=12, plan_time="00:00:00") - failed |= run_car_charging_smart_test("smart6", my_predbat, battery_size=100.0, limit=100.0, soc=0, rate=1.0, loss=1, max_price=99, smart=True, expect_cost=14*15, expect_kwh=14, plan_time="02:00:00") - failed |= run_car_charging_smart_test("smart7", my_predbat, battery_size=100.0, limit=100.0, soc=0, rate=1.0, loss=1, max_price=10, smart=True, expect_cost=7*10, expect_kwh=7, plan_time="02:00:00") - failed |= run_car_charging_smart_test("smart8", my_predbat, battery_size=100.0, limit=100.0, soc=0, rate=1.0, loss=1, max_price=10, smart=False, expect_cost=7*10, expect_kwh=7, plan_time="02:00:00") + failed |= run_car_charging_smart_test("smart5", my_predbat, battery_size=100.0, limit=100.0, soc=0, rate=1.0, loss=1, max_price=99, smart=True, expect_cost=12 * 15, expect_kwh=12, plan_time="00:00:00") + failed |= run_car_charging_smart_test("smart6", my_predbat, battery_size=100.0, limit=100.0, soc=0, rate=1.0, loss=1, max_price=99, smart=True, expect_cost=14 * 15, expect_kwh=14, plan_time="02:00:00") + failed |= run_car_charging_smart_test("smart7", my_predbat, battery_size=100.0, limit=100.0, soc=0, rate=1.0, loss=1, max_price=10, smart=True, expect_cost=7 * 10, expect_kwh=7, plan_time="02:00:00") + failed |= run_car_charging_smart_test("smart8", my_predbat, battery_size=100.0, limit=100.0, soc=0, rate=1.0, loss=1, max_price=10, smart=False, expect_cost=7 * 10, expect_kwh=7, plan_time="02:00:00") return failed + def run_inverter_tests(): """ Test the inverter functions @@ -1146,7 +1149,7 @@ def run_inverter_tests(): expect_pv_power=1.5, expect_load_power=2.5, expect_soc_kwh=6.6, - ) + ) my_predbat.args["givtcp_rest"] = None dummy_rest = DummyRestAPI() @@ -1556,7 +1559,7 @@ def adjust_charge_window(self, charge_start_time, charge_end_time, minutes_now): self.charge_start_time_minutes = (charge_start_time - self.midnight_utc).total_seconds() / 60 self.charge_end_time_minutes = (charge_end_time - self.midnight_utc).total_seconds() / 60 self.charge_time_enable = True - #print("Charge start_time {} charge_end_time {}".format(self.charge_start_time_minutes, self.charge_end_time_minutes)) + # print("Charge start_time {} charge_end_time {}".format(self.charge_start_time_minutes, self.charge_end_time_minutes)) def adjust_charge_immediate(self, target_soc, freeze=False): self.immediate_charge_soc_target = target_soc @@ -1574,7 +1577,7 @@ def adjust_force_export(self, force_export, new_start_time=None, new_end_time=No if new_end_time is not None: delta = new_end_time - self.midnight_utc self.discharge_end_time_minutes = delta.total_seconds() / 60 - #print("Force export {} start_time {} end_time {}".format(self.force_export, self.discharge_start_time_minutes, self.discharge_end_time_minutes)) + # print("Force export {} start_time {} end_time {}".format(self.force_export, self.discharge_start_time_minutes, self.discharge_end_time_minutes)) def adjust_idle_time(self, charge_start=None, charge_end=None, discharge_start=None, discharge_end=None): self.idle_charge_start = charge_start @@ -1644,7 +1647,7 @@ def run_execute_test( has_charge_enable_time=True, inverter_hybrid=False, battery_max_rate=1000, - minutes_now = 12 * 60, + minutes_now=12 * 60, update_plan=False, ): print("Run scenario {}".format(name)) @@ -1688,7 +1691,7 @@ def run_execute_test( inverter.inv_has_target_soc = has_target_soc inverter.inv_has_charge_enable_time = has_charge_enable_time - #my_predbat.fetch_inverter_data() + # my_predbat.fetch_inverter_data() if my_predbat.soc_kw != soc_kw: print("ERROR: Predat level SOC should be {} got {}".format(soc_kw, my_predbat.soc_kw)) failed = True @@ -1716,7 +1719,7 @@ def run_execute_test( # Shift on plan? if update_plan: my_predbat.plan_last_updated = my_predbat.now_utc - my_predbat.args['threads'] = 0 + my_predbat.args["threads"] = 0 my_predbat.calculate_plan(recompute=False) status, status_extra = my_predbat.execute_plan() @@ -1805,9 +1808,9 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None): print("Combined export slots {} min_improvement_export {} set_export_freeze_only {}".format(my_predbat.combine_export_slots, my_predbat.metric_min_improvement_export, my_predbat.set_export_freeze_only)) if not expected_file: pass - #my_predbat.combine_export_slots = False + # my_predbat.combine_export_slots = False # my_predbat.best_soc_keep = 1.0 - #my_predbat.metric_min_improvement_export = 5 + # my_predbat.metric_min_improvement_export = 5 if re_do_rates: # Set rate thresholds @@ -1897,12 +1900,7 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None): print("Wrote plan to {}".format(filename)) # Expected - actual_data = { - "charge_limit_best": my_predbat.charge_limit_best, - "charge_window_best": my_predbat.charge_window_best, - "export_window_best": my_predbat.export_window_best, - "export_limits_best": my_predbat.export_limits_best - } + actual_data = {"charge_limit_best": my_predbat.charge_limit_best, "charge_window_best": my_predbat.charge_window_best, "export_window_best": my_predbat.export_window_best, "export_limits_best": my_predbat.export_limits_best} actual_json = json.dumps(actual_data) if expected_file: print("Compare with {}".format(expected_file)) @@ -1921,6 +1919,7 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None): print("Wrote plan json to {}".format(filename)) return failed + def run_execute_tests(my_predbat): print("**** Running execute tests ****\n") reset_inverter(my_predbat) @@ -2969,7 +2968,7 @@ def run_execute_tests(my_predbat): assert_immediate_soc_target=0, assert_discharge_start_time_minutes=my_predbat.minutes_now, assert_discharge_end_time_minutes=my_predbat.minutes_now + 60 + 1, - minutes_now = 775, + minutes_now=775, ) if failed: return failed @@ -2990,7 +2989,7 @@ def run_execute_tests(my_predbat): assert_charge_start_time_minutes=-1, assert_charge_end_time_minutes=my_predbat.minutes_now + 90, assert_charge_time_enable=True, - minutes_now = 780, + minutes_now=780, update_plan=True, ) if failed: