mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Replace remaining utcnow calls + add ruff check (#97964)
This commit is contained in:
parent
588db501fb
commit
72e6f79086
@ -22,6 +22,7 @@ from homeassistant.helpers.update_coordinator import (
|
|||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
)
|
)
|
||||||
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import ATTR_EXPIRES, ATTR_NAME_SERVERS, ATTR_REGISTRAR, ATTR_UPDATED, DOMAIN
|
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:
|
if domain.expiration_date is None:
|
||||||
return None
|
return None
|
||||||
# We need to cast here, as (unlike Pyright) mypy isn't able to determine the type.
|
# 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:
|
def _ensure_timezone(timestamp: datetime | None) -> datetime | None:
|
||||||
|
@ -515,6 +515,8 @@ select = [
|
|||||||
"C", # complexity
|
"C", # complexity
|
||||||
"COM818", # Trailing comma on bare tuple prohibited
|
"COM818", # Trailing comma on bare tuple prohibited
|
||||||
"D", # docstrings
|
"D", # docstrings
|
||||||
|
"DTZ003", # Use datetime.now(tz=) instead of datetime.utcnow()
|
||||||
|
"DTZ004", # Use datetime.fromtimestamp(ts, tz=) instead of datetime.utcfromtimestamp(ts)
|
||||||
"E", # pycodestyle
|
"E", # pycodestyle
|
||||||
"F", # pyflakes/autoflake
|
"F", # pyflakes/autoflake
|
||||||
"G", # flake8-logging-format
|
"G", # flake8-logging-format
|
||||||
|
@ -8,7 +8,11 @@ from aiounifi.websocket import WebsocketState
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import DOMAIN as TRACKER_DOMAIN
|
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 (
|
from homeassistant.components.unifi.const import (
|
||||||
CONF_ALLOW_BANDWIDTH_SENSORS,
|
CONF_ALLOW_BANDWIDTH_SENSORS,
|
||||||
CONF_ALLOW_UPTIME_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.const import ATTR_DEVICE_CLASS, STATE_UNAVAILABLE, EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.entity_component import DEFAULT_SCAN_INTERVAL
|
|
||||||
from homeassistant.helpers.entity_registry import RegistryEntryDisabler
|
from homeassistant.helpers.entity_registry import RegistryEntryDisabler
|
||||||
import homeassistant.util.dt as dt_util
|
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")
|
ssid_1 = hass.states.get("sensor.ssid_1")
|
||||||
assert ssid_1.state == "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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
ssid_1 = hass.states.get("sensor.ssid_1")
|
ssid_1 = hass.states.get("sensor.ssid_1")
|
||||||
@ -697,7 +700,7 @@ async def test_wlan_client_sensors(
|
|||||||
wireless_client_1["essid"] = "SSID"
|
wireless_client_1["essid"] = "SSID"
|
||||||
mock_unifi_websocket(message=MessageKey.CLIENT, data=wireless_client_1)
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
ssid_1 = hass.states.get("sensor.ssid_1")
|
ssid_1 = hass.states.get("sensor.ssid_1")
|
||||||
@ -708,7 +711,7 @@ async def test_wlan_client_sensors(
|
|||||||
wireless_client_2["last_seen"] = 0
|
wireless_client_2["last_seen"] = 0
|
||||||
mock_unifi_websocket(message=MessageKey.CLIENT, data=wireless_client_2)
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
ssid_1 = hass.states.get("sensor.ssid_1")
|
ssid_1 = hass.states.get("sensor.ssid_1")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user