From 422ca1f3db6ff3656e7eecf48a9a13e5a486ca7b Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Tue, 30 Jan 2024 08:38:27 +0000 Subject: [PATCH 1/2] Issue with reserve max causing flip/flop charging at 100% https://github.com/springfall2008/batpred/issues/667 --- apps/predbat/predbat.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index febff66c4..b5e1d071a 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -3040,9 +3040,9 @@ async def get_history_async_hook(self, result, entity_id, days): Async function to get history from HA """ if days: - result["data"] = await self.get_history(entity_id=entity_id, days=days) + result['data'] = await self.get_history(entity_id=entity_id, days=days) else: - result["data"] = await self.get_history(entity_id=entity_id) + result['data'] = await self.get_history(entity_id=entity_id) def get_history_async(self, entity_id, days=None): """ @@ -3052,11 +3052,11 @@ def get_history_async(self, entity_id, days=None): task = self.create_task(self.get_history_async_hook(result, entity_id=entity_id, days=days)) cnt = 0 while not task.done() and (cnt < 120): - time.sleep(0.05) + time.sleep(0.05) cnt += 0.05 - if "data" in result: - return result["data"] + if 'data' in result: + return result['data'] else: self.log("Failure to fetch history for {}".format(entity_id)) raise ValueError @@ -9216,7 +9216,7 @@ def execute_plan(self): status = "Freeze charging" status_extra = " target {}%".format(inverter.soc_percent) else: - if self.set_soc_enable and self.set_reserve_enable and self.set_reserve_hold and ((inverter.soc_percent + 1) >= self.charge_limit_percent_best[0]): + if self.set_soc_enable and self.set_reserve_enable and self.set_reserve_hold and ((inverter.soc_percent + 1) >= self.charge_limit_percent_best[0]) and (inverter.reserve_max >= inverter.soc_percent): status = "Hold charging" inverter.disable_charge_window() disabled_charge_window = True From 467e267b865f76e106e8d4ed2dc20d9c519a48d4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Tue, 30 Jan 2024 08:39:49 +0000 Subject: [PATCH 2/2] [pre-commit.ci lite] apply automatic fixes --- apps/predbat/predbat.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index b5e1d071a..e1f72ca84 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -3040,9 +3040,9 @@ async def get_history_async_hook(self, result, entity_id, days): Async function to get history from HA """ if days: - result['data'] = await self.get_history(entity_id=entity_id, days=days) + result["data"] = await self.get_history(entity_id=entity_id, days=days) else: - result['data'] = await self.get_history(entity_id=entity_id) + result["data"] = await self.get_history(entity_id=entity_id) def get_history_async(self, entity_id, days=None): """ @@ -3052,11 +3052,11 @@ def get_history_async(self, entity_id, days=None): task = self.create_task(self.get_history_async_hook(result, entity_id=entity_id, days=days)) cnt = 0 while not task.done() and (cnt < 120): - time.sleep(0.05) + time.sleep(0.05) cnt += 0.05 - if 'data' in result: - return result['data'] + if "data" in result: + return result["data"] else: self.log("Failure to fetch history for {}".format(entity_id)) raise ValueError @@ -9216,7 +9216,13 @@ def execute_plan(self): status = "Freeze charging" status_extra = " target {}%".format(inverter.soc_percent) else: - if self.set_soc_enable and self.set_reserve_enable and self.set_reserve_hold and ((inverter.soc_percent + 1) >= self.charge_limit_percent_best[0]) and (inverter.reserve_max >= inverter.soc_percent): + if ( + self.set_soc_enable + and self.set_reserve_enable + and self.set_reserve_hold + and ((inverter.soc_percent + 1) >= self.charge_limit_percent_best[0]) + and (inverter.reserve_max >= inverter.soc_percent) + ): status = "Hold charging" inverter.disable_charge_window() disabled_charge_window = True