Skip to content

Commit

Permalink
wip function get measurement data
Browse files Browse the repository at this point in the history
  • Loading branch information
duhow committed Nov 13, 2024
1 parent ec36d1c commit 076f40c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions custom_components/aigues_barcelona/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,27 @@ async def _clear_statistics(self) -> None:
clear_statistics, self.hass.data[RECORDER_DATA_INSTANCE], to_clear
)

async def _async_import_statistics(self, consumptions) -> None:
# force sort by datetime
consumptions = sorted(
consumptions, key=lambda x: datetime.fromisoformat(x["datetime"])
)

# Retrieve the last stored value of accumulatedConsumption
async def get_last_measurement_stored(self):
last_stored_value = 0.0
last_stored_date = None

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.get("sum") and stat_id["sum"] > last_stored_value:
last_stored_value = stat_id["sum"]
last_stored_date = stat_id["start"]

return last_stored_date

async def _async_import_statistics(self, consumptions) -> None:
# force sort by datetime
consumptions = sorted(
consumptions, key=lambda x: datetime.fromisoformat(x["datetime"])
)

stats = list()
for metric in consumptions:
Expand Down

0 comments on commit 076f40c

Please sign in to comment.