From b3d4f6f876f0d3630bedec350e20c7c7c9f541f5 Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Mon, 6 Nov 2023 20:02:05 +0000 Subject: [PATCH] fix: Fixed previous consumption peak/off peak sensors --- .../electricity/previous_accumulative_consumption.py | 2 +- .../electricity/previous_accumulative_consumption_off_peak.py | 2 +- .../electricity/previous_accumulative_consumption_peak.py | 4 ++-- .../octopus_energy/electricity/previous_accumulative_cost.py | 3 +-- .../electricity/previous_accumulative_cost_off_peak.py | 4 ++-- .../electricity/previous_accumulative_cost_peak.py | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py b/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py index c1f7861c..57fd9d92 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py @@ -105,10 +105,10 @@ async def async_update(self): if not self.enabled: return - current = now() consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None + current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_consumption_off_peak.py b/custom_components/octopus_energy/electricity/previous_accumulative_consumption_off_peak.py index 12cc54e4..dd94ba21 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_consumption_off_peak.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_consumption_off_peak.py @@ -89,10 +89,10 @@ def last_reset(self): @property def state(self): """Retrieve the previous days accumulative consumption""" - current = now() consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None + current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_consumption_peak.py b/custom_components/octopus_energy/electricity/previous_accumulative_consumption_peak.py index 0bcb6ac9..e32ebb3a 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_consumption_peak.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_consumption_peak.py @@ -89,10 +89,10 @@ def last_reset(self): @property def state(self): """Retrieve the previous days accumulative consumption""" - current = now() consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None + current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, @@ -109,7 +109,7 @@ def state(self): self._state = consumption_and_cost["total_consumption_peak"] if "total_consumption_peak" in consumption_and_cost else 0 self._last_reset = consumption_and_cost["last_reset"] - self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"] + self._attributes["last_evaluated"] = consumption_and_cost["last_calculated_timestamp"] return self._state diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_cost.py b/custom_components/octopus_energy/electricity/previous_accumulative_cost.py index d6d27788..554fdef5 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_cost.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_cost.py @@ -101,11 +101,10 @@ async def async_update(self): if not self.enabled: return - current = now() consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None - current = now() + current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_cost_off_peak.py b/custom_components/octopus_energy/electricity/previous_accumulative_cost_off_peak.py index d69b5eab..c3d64d7a 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_cost_off_peak.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_cost_off_peak.py @@ -87,10 +87,10 @@ def last_reset(self): @property def state(self): """Retrieve the previously calculated state""" - current = now() consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None + current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current, @@ -107,7 +107,7 @@ def state(self): self._last_reset = consumption_and_cost["last_reset"] self._state = consumption_and_cost["total_cost_off_peak"] if "total_cost_off_peak" in consumption_and_cost else 0 - self._attributes["last_calculated_timestamp"] = consumption_and_cost["last_calculated_timestamp"] + self._attributes["last_evaluated"] = consumption_and_cost["last_calculated_timestamp"] return self._state diff --git a/custom_components/octopus_energy/electricity/previous_accumulative_cost_peak.py b/custom_components/octopus_energy/electricity/previous_accumulative_cost_peak.py index bb1f414d..196eb23c 100644 --- a/custom_components/octopus_energy/electricity/previous_accumulative_cost_peak.py +++ b/custom_components/octopus_energy/electricity/previous_accumulative_cost_peak.py @@ -87,10 +87,10 @@ def last_reset(self): @property def state(self): """Retrieve the previously calculated state""" - current = now() consumption_data = self.coordinator.data["consumption"] if self.coordinator is not None and self.coordinator.data is not None and "consumption" in self.coordinator.data else None rate_data = self.coordinator.data["rates"] if self.coordinator is not None and self.coordinator.data is not None and "rates" in self.coordinator.data else None standing_charge = self.coordinator.data["standing_charge"] if self.coordinator is not None and self.coordinator.data is not None and "standing_charge" in self.coordinator.data else None + current = consumption_data[0]["interval_start"] if consumption_data is not None and len(consumption_data) > 0 else None consumption_and_cost = calculate_electricity_consumption_and_cost( current,