Skip to content

Commit

Permalink
fix: Fixed previous consumption peak/off peak sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Nov 7, 2023
1 parent 6d544a1 commit b3d4f6f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b3d4f6f

Please sign in to comment.