mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 02:24:51 -05:00
Avoid a naive datetime.now() in nice_go (#178248)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""Config flow for Nice G.O. integration."""
|
||||
|
||||
from collections.abc import Mapping
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import time
|
||||
from typing import Any, override
|
||||
|
||||
from nice_go import AuthFailedError, NiceGOApi
|
||||
@@ -59,7 +59,7 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
CONF_EMAIL: user_input[CONF_EMAIL],
|
||||
CONF_PASSWORD: user_input[CONF_PASSWORD],
|
||||
CONF_REFRESH_TOKEN: refresh_token,
|
||||
CONF_REFRESH_TOKEN_CREATION_TIME: datetime.now().timestamp(), # pylint: disable=home-assistant-enforce-naive-now
|
||||
CONF_REFRESH_TOKEN_CREATION_TIME: time.time(),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -100,7 +100,7 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
data={
|
||||
**user_input,
|
||||
CONF_REFRESH_TOKEN: refresh_token,
|
||||
CONF_REFRESH_TOKEN_CREATION_TIME: datetime.now().timestamp(), # pylint: disable=home-assistant-enforce-naive-now
|
||||
CONF_REFRESH_TOKEN_CREATION_TIME: time.time(),
|
||||
},
|
||||
unique_id=user_input[CONF_EMAIL],
|
||||
)
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
import asyncio
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Any, override
|
||||
|
||||
from nice_go import (
|
||||
@@ -174,7 +174,7 @@ class NiceGOUpdateCoordinator(DataUpdateCoordinator[dict[str, NiceGODevice]]):
|
||||
self.refresh_token_creation_time + REFRESH_TOKEN_EXPIRY_TIME.total_seconds()
|
||||
)
|
||||
try:
|
||||
if datetime.now().timestamp() >= expiry_time: # pylint: disable=home-assistant-enforce-naive-now
|
||||
if time.time() >= expiry_time:
|
||||
await self.update_refresh_token()
|
||||
else:
|
||||
await self.api.authenticate_refresh(
|
||||
@@ -205,7 +205,7 @@ class NiceGOUpdateCoordinator(DataUpdateCoordinator[dict[str, NiceGODevice]]):
|
||||
data = {
|
||||
**self.config_entry.data,
|
||||
CONF_REFRESH_TOKEN: refresh_token,
|
||||
CONF_REFRESH_TOKEN_CREATION_TIME: datetime.now().timestamp(), # pylint: disable=home-assistant-enforce-naive-now
|
||||
CONF_REFRESH_TOKEN_CREATION_TIME: time.time(),
|
||||
}
|
||||
self.hass.config_entries.async_update_entry(self.config_entry, data=data)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Common fixtures for the Nice G.O. tests."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from datetime import datetime
|
||||
import time
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from nice_go import Barrier, BarrierState, ConnectionState
|
||||
@@ -74,7 +74,7 @@ def mock_config_entry() -> MockConfigEntry:
|
||||
CONF_EMAIL: "test-email",
|
||||
CONF_PASSWORD: "test-password",
|
||||
CONF_REFRESH_TOKEN: "test-refresh-token",
|
||||
CONF_REFRESH_TOKEN_CREATION_TIME: datetime.now().timestamp(), # pylint: disable=home-assistant-enforce-naive-now
|
||||
CONF_REFRESH_TOKEN_CREATION_TIME: time.time(),
|
||||
},
|
||||
version=1,
|
||||
unique_id="test-email",
|
||||
|
||||
Reference in New Issue
Block a user