Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions custom_components/solaredgeoptimizers/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def _async_update_data(self):

update = False

timetocheck = datetime.now() - CHECK_TIME_DELTA
timetocheck = dt_util.utcnow() - CHECK_TIME_DELTA # tz-aware UTC

for optimizer in data:
_LOGGER.debug(
Expand All @@ -94,7 +94,13 @@ async def _async_update_data(self):
optimizer.lastmeasurement,
)

if optimizer.lastmeasurement > timetocheck:
ts = optimizer.lastmeasurement

# SolarEdge returns a *naive* UTC timestamp – tag it as UTC
if ts.tzinfo is None:
ts = ts.replace(tzinfo=timezone.utc)

if ts > timetocheck:
update = True
break

Expand All @@ -109,4 +115,4 @@ async def _async_update_data(self):
except Exception as err:
_LOGGER.error("Error in updating updater")
_LOGGER.error(err)
raise UpdateFailed(err)
raise UpdateFailed(err)
3 changes: 3 additions & 0 deletions custom_components/solaredgeoptimizers/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.entity import DeviceInfo

from datetime import timezone
from homeassistant.util import dt as dt_util # HA helper, tz-aware

import logging

from homeassistant.components.sensor import (
Expand Down