Skip to content

Commit

Permalink
Tidy up charge times when there are none
Browse files Browse the repository at this point in the history
  • Loading branch information
fboundy committed Nov 14, 2024
1 parent 319457d commit 1ef8b3d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions apps/pv_opt/pv_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2304,9 +2304,16 @@ def _write_output(self):
attributes={"Summary": self.summary_costs},
)

if len(self.windows) > 0:
hass_start = self.charge_start_datetime
hass_end = self.charge_end_datetime
else:
hass_start = pd.Timestamp.now().floor("1D")
hass_end = hass_start

self.write_to_hass(
entity=f"sensor.{self.prefix}_charge_start",
state=self.charge_start_datetime,
state=hass_start,
attributes={
"friendly_name": "PV Opt Next Charge Period Start",
"device_class": "timestamp",
Expand All @@ -2329,7 +2336,7 @@ def _write_output(self):

self.write_to_hass(
entity=f"sensor.{self.prefix}_charge_end",
state=self.charge_end_datetime,
state=hass_end,
attributes={
"friendly_name": "PV Opt Next Charge Period End",
},
Expand Down

0 comments on commit 1ef8b3d

Please sign in to comment.