From bef62d39bd2961822be9929ce93c62264a5b53d7 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Sat, 21 Dec 2024 13:21:50 +0000 Subject: [PATCH] Catch crash with no button setting and press_and_poll_button on https://github.com/springfall2008/batpred/issues/1742 --- apps/predbat/inverter.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/predbat/inverter.py b/apps/predbat/inverter.py index 302d379ae..8e5c4ef4c 100644 --- a/apps/predbat/inverter.py +++ b/apps/predbat/inverter.py @@ -1732,8 +1732,7 @@ def adjust_force_export(self, force_export, new_start_time=None, new_end_time=No self.log("Warn: Inverter {} unable write export end time as neither REST or discharge_end_time are set".format(self.id)) if ((new_end != old_end) or (new_start != old_start)) and self.inv_time_button_press: - entity_id = self.base.get_arg("charge_discharge_update_button", indirect=False, index=self.id) - self.press_and_poll_button(entity_id) + self.press_and_poll_button() # REST version of writing slot if self.rest_data and new_start and new_end and ((new_start != old_start) or (new_end != old_end)): @@ -2093,8 +2092,7 @@ def adjust_charge_window(self, charge_start_time, charge_end_time, minutes_now): # For Solis inverters we also have to press the update_charge_discharge button to send the times to the inverter if self.inv_time_button_press: - entity_id = self.base.get_arg("charge_discharge_update_button", indirect=False, index=self.id) - self.press_and_poll_button(entity_id) + self.press_and_poll_button() if self.base.set_inverter_notify: self.base.call_notify("Predbat: Inverter {} Charge window change to: {} - {} at {}".format(self.id, new_start, new_end, self.base.time_now_str())) @@ -2125,6 +2123,10 @@ def press_and_poll_button(self, entity_id): """ Call a button press service (Solis) and wait for the data to update """ + entity_id = self.base.get_arg("charge_discharge_update_button", indirect=False, index=self.id) + if not entity_id: + return False + for retry in range(8): self.base.call_service_wrapper("button/press", entity_id=entity_id) time.sleep(self.inv_write_and_poll_sleep)