From 1ef8b3d9e3f1a2b7c307108e7c6e3851e726ff70 Mon Sep 17 00:00:00 2001 From: fboundy Date: Thu, 14 Nov 2024 21:27:59 +0000 Subject: [PATCH] Tidy up charge times when there are none --- apps/pv_opt/pv_opt.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/pv_opt/pv_opt.py b/apps/pv_opt/pv_opt.py index cc833e3..994c896 100644 --- a/apps/pv_opt/pv_opt.py +++ b/apps/pv_opt/pv_opt.py @@ -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", @@ -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", },