Skip to content

Commit

Permalink
Merge pull request #362 from MTrab:Add-local-time
Browse files Browse the repository at this point in the history
Switching to localtime in all checks
  • Loading branch information
MTrab committed Sep 9, 2023
2 parents 2a02dba + 15f5101 commit 87b12d2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions custom_components/energidataservice/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from functools import partial
from importlib import import_module
from logging import getLogger
from pytz import timezone

import voluptuous as vol
from aiohttp import ServerDisconnectedError
Expand Down Expand Up @@ -146,12 +147,13 @@ async def update(self, dt=None) -> None: # type: ignore pylint: disable=unused-
midnight = datetime.strptime("23:59:59", "%H:%M:%S")
refresh = datetime.strptime(self.next_data_refresh, "%H:%M:%S")
now = datetime.utcnow()
now_local = datetime.now().astimezone(timezone(self._tz))

_LOGGER.debug(
"Now: %s:%s:%s (UTC)",
f"{now.hour:02d}",
f"{now.minute:02d}",
f"{now.second:02d}",
"Now: %s:%s:%s (local time)",
f"{now_local.hour:02d}",
f"{now_local.minute:02d}",
f"{now_local.second:02d}",
)
_LOGGER.debug(
"Refresh: %s:%s:%s (local time)",
Expand All @@ -161,9 +163,9 @@ async def update(self, dt=None) -> None: # type: ignore pylint: disable=unused-
)
if (
f"{midnight.hour}:{midnight.minute}:{midnight.second}"
> f"{now.hour:02d}:{now.minute:02d}:{now.second:02d}"
> f"{now_local.hour:02d}:{now_local.minute:02d}:{now_local.second:02d}"
and f"{refresh.hour:02d}:{refresh.minute:02d}:{refresh.second:02d}"
<= f"{now.hour:02d}:{now.minute:02d}:{now.second:02d}"
<= f"{now_local.hour:02d}:{now_local.minute:02d}:{now_local.second:02d}"
):
retry_update(self)
else:
Expand Down

0 comments on commit 87b12d2

Please sign in to comment.