Skip to content

Commit

Permalink
Catch crash with no button setting and press_and_poll_button on (#1769)
Browse files Browse the repository at this point in the history
  • Loading branch information
springfall2008 authored Dec 21, 2024
1 parent f12db7b commit 1697f56
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/predbat/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1697f56

Please sign in to comment.