Skip to content

Commit

Permalink
Allow button to be "unknown" state
Browse files Browse the repository at this point in the history
  • Loading branch information
fboundy committed Feb 21, 2024
1 parent 4c2b494 commit aa1249a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/pv_opt/pv_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ def get_ha_value(self, entity_id):

# if the state is None return None
if state is not None:
if state in ['unknown', 'unavailable']:
if (state in ['unknown', 'unavailable']) and (entity_id != 'button'):
e = f"HA returned {state} for state of {entity_id}"
self._status(f"ERROR: {e}")
raise ValueError(e)
Expand Down
18 changes: 12 additions & 6 deletions apps/pv_opt/solis.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,23 @@ def _solis_control_charge_discharge(self, direction, enable, **kwargs):
entity_id = self.host.config["id_timed_charge_discharge_button"]
self.host.call_service("button/press", entity_id=entity_id)
time.sleep(0.5)
time_pressed = pd.Timestamp(self.host.get_state(entity_id))
try:
time_pressed = pd.Timestamp(self.host.get_state(entity_id))

dt = (pd.Timestamp.now(self.host.tz) - time_pressed).total_seconds()
if dt < 10:
self.log(f"Successfully pressed button {entity_id}")
dt = (pd.Timestamp.now(self.host.tz) - time_pressed).total_seconds()
if dt < 10:
self.log(f"Successfully pressed button {entity_id}")

else:
else:
self.log(
f"Failed to press button {entity_id}. Last pressed at {time_pressed.strftime(TIMEFORMAT)} ({dt:0.2f} seconds ago)"
)
except:
self.log(
f"Failed to press button {entity_id}. Last pressed at {time_pressed.strftime(TIMEFORMAT)} ({dt:0.2f} seconds ago)"
f"Failed to press button {entity_id}: it appears to never have been pressed."
)


else:
self.log("Inverter already at correct time settings")

Expand Down

0 comments on commit aa1249a

Please sign in to comment.