Skip to content

Commit

Permalink
last_stats_time is now float with latest HA update
Browse files Browse the repository at this point in the history
  • Loading branch information
dreautall committed Mar 29, 2023
1 parent 0b8c99f commit e7dbf27
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions custom_components/stromnetzgraz/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import asyncio
from datetime import timedelta
from datetime import timedelta, datetime
import logging
import pandas
import numpy
Expand Down Expand Up @@ -229,6 +229,12 @@ async def _insert_statistics(self):
if stat:
_sum = stat[statistic_id][0]["sum"]
last_stats_time = stat[statistic_id][0]["start"]
if isinstance(last_stats_time, float):
last_stats_time = datetime.fromtimestamp(
stat[statistic_id][0]["start"]
)
else:
last_stats_time = last_stats_time.replace(tzinfo=None)
else:
_sum = 0.0
last_stats_time = None
Expand All @@ -254,7 +260,10 @@ async def _insert_statistics(self):

# make sure minutes & (micro)seconds is 0, or HA will throw an error
start = start.to_pydatetime().replace(minute=0, second=0, microsecond=0)
if last_stats_time is not None and start <= last_stats_time:
if (
last_stats_time is not None
and start.replace(tzinfo=None) <= last_stats_time
):
continue

_sum += consump
Expand Down

0 comments on commit e7dbf27

Please sign in to comment.