mirror of
https://github.com/home-assistant/core.git
synced 2026-08-28 10:16:02 -05:00
Avoid a naive datetime.now() in sharkiq (#180043)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""Data update coordinator for shark iq vacuums."""
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import timedelta
|
||||
from typing import override
|
||||
|
||||
from sharkiq import (
|
||||
@@ -16,6 +16,7 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import API_TIMEOUT, DOMAIN, LOGGER, UPDATE_INTERVAL
|
||||
|
||||
@@ -72,7 +73,9 @@ class SharkIqUpdateCoordinator(DataUpdateCoordinator[bool]):
|
||||
try:
|
||||
if (
|
||||
self.ayla_api.token_expiring_soon
|
||||
or datetime.now() # pylint: disable=home-assistant-enforce-naive-now
|
||||
# The Ayla client builds auth_expiration from its own
|
||||
# datetime.now(), so it is a naive local time.
|
||||
or dt_util.naive_now()
|
||||
> self.ayla_api.auth_expiration - timedelta(seconds=600)
|
||||
):
|
||||
await self.ayla_api.async_refresh_auth()
|
||||
|
||||
@@ -45,6 +45,7 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import (
|
||||
CONFIG,
|
||||
@@ -111,7 +112,7 @@ class MockAyla(AylaApi):
|
||||
@property
|
||||
def auth_expiration(self) -> datetime:
|
||||
"""Sample expiration timestamp that is always 1200 seconds behind now()."""
|
||||
return datetime.now() - timedelta(seconds=1200) # pylint: disable=home-assistant-enforce-naive-now
|
||||
return dt_util.naive_now() - timedelta(seconds=1200)
|
||||
|
||||
|
||||
class MockShark(SharkIqVacuum):
|
||||
|
||||
Reference in New Issue
Block a user