Skip to content

Commit eec5792

Browse files
fix: update datetime usage to use UTC for consistency in library updater (#4392)
1 parent e6e97c5 commit eec5792

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

custom_components/battery_notes/library_updater.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from homeassistant.helpers.aiohttp_client import async_get_clientsession
2121
from homeassistant.helpers.event import async_track_utc_time_change
2222
from homeassistant.helpers.storage import STORAGE_DIR
23+
from homeassistant.util import dt as dt_util
2324

2425
from .const import (
2526
DEFAULT_LIBRARY_URL,
@@ -62,14 +63,13 @@ def __init__(self, hass: HomeAssistant):
6263
self._client = LibraryUpdaterClient(session=async_get_clientsession(hass))
6364

6465
# Fire the library check every 24 hours from just before now
65-
refresh_time = datetime.now() - timedelta(hours=0, minutes=1)
66+
refresh_time = dt_util.utcnow() - timedelta(hours=0, minutes=1)
6667
async_track_utc_time_change(
6768
hass,
6869
self.timer_update,
6970
hour=refresh_time.hour,
7071
minute=refresh_time.minute,
7172
second=refresh_time.second,
72-
local=True,
7373
)
7474

7575
@callback
@@ -132,7 +132,7 @@ def _update_library_json(library_file: str, content: str) -> None:
132132

133133
domain_config = self.hass.data.get(MY_KEY)
134134
if domain_config:
135-
self.hass.data[MY_KEY].library_last_update = datetime.now()
135+
self.hass.data[MY_KEY].library_last_update = dt_util.utcnow()
136136

137137
_LOGGER.debug("Updated library")
138138
else:
@@ -160,7 +160,7 @@ async def time_to_update_library(self, hours: int) -> bool:
160160
return True
161161

162162
if library_last_update := self.hass.data[MY_KEY].library_last_update:
163-
time_since_last_update = datetime.now() - library_last_update
163+
time_since_last_update = dt_util.utcnow() - library_last_update
164164

165165
time_difference_in_hours = time_since_last_update / timedelta(hours=1)
166166

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ ignore = [
8989

9090
# Project preference
9191
"ERA001", # Found commented-out code
92+
"FBT001", # Boolean-typed positional argument in function definition
93+
"FBT002", # Boolean-typed positional argument in function definition
9294
"RUF001", # String contains ambiguous character
9395
"S101", # Use of assert detected
9496
"TC001", # Move application import into type checking
@@ -101,11 +103,8 @@ ignore = [
101103
"ANN201", # Missing return type annotation for public function
102104
"ANN202", # Missing return type annotation for private function
103105
"ANN204", # Missing return type annotation for special method
104-
"DTZ005", # The use of `datetime.datetime.now()` without `tz` argument is not allowed
105106
"EM101", # Exception must not use a string literal, assign to variable first
106107
"EM102", # Exception must not use an f-string literal, assign to variable first
107-
"FBT001", # Boolean-typed positional argument in function definition
108-
"FBT002", # Boolean-typed positional argument in function definition
109108
"PLR2004", # Magic value used in comparison
110109
"PTH103", # `os.makedirs()` should be replaced by `Path.mkdir()`
111110
"PTH104", # `os.rename()` should be replaced by `Path.rename()`

0 commit comments

Comments
 (0)