Replace remaining utcnow calls + add ruff check (#97964)
This commit is contained in:
parent
588db501fb
commit
72e6f79086
3 changed files with 15 additions and 6 deletions
|
@ -22,6 +22,7 @@ from homeassistant.helpers.update_coordinator import (
|
|||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import ATTR_EXPIRES, ATTR_NAME_SERVERS, ATTR_REGISTRAR, ATTR_UPDATED, DOMAIN
|
||||
|
||||
|
@ -45,7 +46,10 @@ def _days_until_expiration(domain: Domain) -> int | None:
|
|||
if domain.expiration_date is None:
|
||||
return None
|
||||
# We need to cast here, as (unlike Pyright) mypy isn't able to determine the type.
|
||||
return cast(int, (domain.expiration_date - domain.expiration_date.utcnow()).days)
|
||||
return cast(
|
||||
int,
|
||||
(domain.expiration_date - dt_util.utcnow().replace(tzinfo=None)).days,
|
||||
)
|
||||
|
||||
|
||||
def _ensure_timezone(timestamp: datetime | None) -> datetime | None:
|
||||
|
|
|
@ -515,6 +515,8 @@ select = [
|
|||
"C", # complexity
|
||||
"COM818", # Trailing comma on bare tuple prohibited
|
||||
"D", # docstrings
|
||||
"DTZ003", # Use datetime.now(tz=) instead of datetime.utcnow()
|
||||
"DTZ004", # Use datetime.fromtimestamp(ts, tz=) instead of datetime.utcfromtimestamp(ts)
|
||||
"E", # pycodestyle
|
||||
"F", # pyflakes/autoflake
|
||||
"G", # flake8-logging-format
|
||||
|
|
|
@ -8,7 +8,11 @@ from aiounifi.websocket import WebsocketState
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.device_tracker import DOMAIN as TRACKER_DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
|
||||
from homeassistant.components.sensor import (
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
SCAN_INTERVAL,
|
||||
SensorDeviceClass,
|
||||
)
|
||||
from homeassistant.components.unifi.const import (
|
||||
CONF_ALLOW_BANDWIDTH_SENSORS,
|
||||
CONF_ALLOW_UPTIME_SENSORS,
|
||||
|
@ -19,7 +23,6 @@ from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
|
|||
from homeassistant.const import ATTR_DEVICE_CLASS, STATE_UNAVAILABLE, EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_component import DEFAULT_SCAN_INTERVAL
|
||||
from homeassistant.helpers.entity_registry import RegistryEntryDisabler
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
|
@ -686,7 +689,7 @@ async def test_wlan_client_sensors(
|
|||
ssid_1 = hass.states.get("sensor.ssid_1")
|
||||
assert ssid_1.state == "1"
|
||||
|
||||
async_fire_time_changed(hass, datetime.utcnow() + DEFAULT_SCAN_INTERVAL)
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
ssid_1 = hass.states.get("sensor.ssid_1")
|
||||
|
@ -697,7 +700,7 @@ async def test_wlan_client_sensors(
|
|||
wireless_client_1["essid"] = "SSID"
|
||||
mock_unifi_websocket(message=MessageKey.CLIENT, data=wireless_client_1)
|
||||
|
||||
async_fire_time_changed(hass, datetime.utcnow() + DEFAULT_SCAN_INTERVAL)
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
ssid_1 = hass.states.get("sensor.ssid_1")
|
||||
|
@ -708,7 +711,7 @@ async def test_wlan_client_sensors(
|
|||
wireless_client_2["last_seen"] = 0
|
||||
mock_unifi_websocket(message=MessageKey.CLIENT, data=wireless_client_2)
|
||||
|
||||
async_fire_time_changed(hass, datetime.utcnow() + DEFAULT_SCAN_INTERVAL)
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
ssid_1 = hass.states.get("sensor.ssid_1")
|
||||
|
|
Loading…
Add table
Reference in a new issue