Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
duhow committed Oct 26, 2024
1 parent 627da2b commit f9e6e06
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions custom_components/aigues_barcelona/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,19 @@ async def _async_import_statistics(self, consumptions) -> None:
)

# Retrieve the last stored value of accumulatedConsumption
last_stored_value = None
last_stored_value = 0.0
all_ids = await get_db_instance(self.hass).async_add_executor_job(
list_statistic_ids, self.hass
)
for stat_id in all_ids:
if stat_id["statistic_id"] == self.internal_sensor_id:
if stat_id["sum"] and (last_stored_value is None or stat_id["sum"] > last_stored_value):
if stat_id.get("sum") and (
last_stored_value is None or stat_id["sum"] > last_stored_value
):
last_stored_value = stat_id["sum"]

stats = list()
sum_total = last_stored_value or 0.0
sum_total = last_stored_value
for metric in consumptions:
start_ts = datetime.fromisoformat(metric["datetime"])
start_ts = start_ts.replace(minute=0, second=0, microsecond=0) # required
Expand Down

0 comments on commit f9e6e06

Please sign in to comment.