Avoid use of datetime.utc* methods deprecated in Python 3.12 (#93684)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
This commit is contained in:
@@ -17,7 +17,7 @@ import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.dt import utc_from_timestamp
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
_LOGGER = getLogger(__name__)
|
||||
|
||||
@@ -207,7 +207,7 @@ class FeedManager:
|
||||
self._firstrun = False
|
||||
else:
|
||||
# Set last entry timestamp as epoch time if not available
|
||||
self._last_entry_timestamp = datetime.utcfromtimestamp(0).timetuple()
|
||||
self._last_entry_timestamp = dt_util.utc_from_timestamp(0).timetuple()
|
||||
for entry in self._feed.entries:
|
||||
if (
|
||||
self._firstrun
|
||||
@@ -286,6 +286,6 @@ class StoredData:
|
||||
def _async_save_data(self) -> dict[str, str]:
|
||||
"""Save feed data to storage."""
|
||||
return {
|
||||
feed_id: utc_from_timestamp(timegm(struct_utc)).isoformat()
|
||||
feed_id: dt_util.utc_from_timestamp(timegm(struct_utc)).isoformat()
|
||||
for feed_id, struct_utc in self._data.items()
|
||||
}
|
||||
|
||||
@@ -102,9 +102,7 @@ class FileSizeCoordinator(DataUpdateCoordinator):
|
||||
raise UpdateFailed(f"Can not retrieve file statistics {error}") from error
|
||||
|
||||
size = statinfo.st_size
|
||||
last_updated = datetime.utcfromtimestamp(statinfo.st_mtime).replace(
|
||||
tzinfo=dt_util.UTC
|
||||
)
|
||||
last_updated = dt_util.utc_from_timestamp(statinfo.st_mtime)
|
||||
|
||||
_LOGGER.debug("size %s, last updated %s", size, last_updated)
|
||||
data: dict[str, int | float | datetime] = {
|
||||
|
||||
@@ -40,7 +40,7 @@ from homeassistant.helpers.network import NoURLAvailableError, get_url
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.setup import async_start_setup, async_when_setup_or_start
|
||||
from homeassistant.util import ssl as ssl_util
|
||||
from homeassistant.util import dt as dt_util, ssl as ssl_util
|
||||
from homeassistant.util.json import json_loads
|
||||
|
||||
from .auth import async_setup_auth
|
||||
@@ -503,14 +503,15 @@ class HomeAssistantHTTP:
|
||||
x509.NameAttribute(NameOID.COMMON_NAME, host),
|
||||
]
|
||||
)
|
||||
now = dt_util.utcnow()
|
||||
cert = (
|
||||
x509.CertificateBuilder()
|
||||
.subject_name(subject)
|
||||
.issuer_name(issuer)
|
||||
.public_key(key.public_key())
|
||||
.serial_number(x509.random_serial_number())
|
||||
.not_valid_before(datetime.datetime.utcnow())
|
||||
.not_valid_after(datetime.datetime.utcnow() + datetime.timedelta(days=30))
|
||||
.not_valid_before(now)
|
||||
.not_valid_after(now + datetime.timedelta(days=30))
|
||||
.add_extension(
|
||||
x509.SubjectAlternativeName([x509.DNSName(host)]),
|
||||
critical=False,
|
||||
|
||||
@@ -19,7 +19,7 @@ async def async_get_config_entry_diagnostics(
|
||||
payload: dict[str, Any] = {
|
||||
"now": dt_util.now().isoformat(),
|
||||
"timezone": str(dt_util.DEFAULT_TIME_ZONE),
|
||||
"system_timezone": str(datetime.datetime.utcnow().astimezone().tzinfo),
|
||||
"system_timezone": str(datetime.datetime.now().astimezone().tzinfo),
|
||||
}
|
||||
store = hass.data[DOMAIN][config_entry.entry_id]
|
||||
ics = await store.async_load()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
import aiohttp
|
||||
@@ -19,6 +19,7 @@ from homeassistant.helpers.update_coordinator import (
|
||||
DataUpdateCoordinator,
|
||||
UpdateFailed,
|
||||
)
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import CONF_ACCOUNT, DATA_CLIENT, DATA_COORDINATOR, DOMAIN
|
||||
|
||||
@@ -58,7 +59,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
raise UpdateFailed(exception) from exception
|
||||
if not authenticated:
|
||||
raise ConfigEntryAuthFailed("Not authenticated with OVO Energy")
|
||||
return await client.get_daily_usage(datetime.utcnow().strftime("%Y-%m"))
|
||||
return await client.get_daily_usage(dt_util.utcnow().strftime("%Y-%m"))
|
||||
|
||||
coordinator = DataUpdateCoordinator[OVODailyUsage](
|
||||
hass,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Support for monitoring Repetier Server Sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import time
|
||||
|
||||
@@ -10,6 +9,7 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import UNDEFINED, ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import REPETIER_API, SENSOR_TYPES, UPDATE_SIGNAL, RepetierSensorEntityDescription
|
||||
|
||||
@@ -170,7 +170,7 @@ class RepetierJobEndSensor(RepetierSensor):
|
||||
print_time = data["print_time"]
|
||||
from_start = data["from_start"]
|
||||
time_end = start + round(print_time, 0)
|
||||
self._state = datetime.utcfromtimestamp(time_end)
|
||||
self._state = dt_util.utc_from_timestamp(time_end)
|
||||
remaining = print_time - from_start
|
||||
remaining_secs = int(round(remaining, 0))
|
||||
_LOGGER.debug(
|
||||
@@ -192,7 +192,7 @@ class RepetierJobStartSensor(RepetierSensor):
|
||||
job_name = data["job_name"]
|
||||
start = data["start"]
|
||||
from_start = data["from_start"]
|
||||
self._state = datetime.utcfromtimestamp(start)
|
||||
self._state = dt_util.utc_from_timestamp(start)
|
||||
elapsed_secs = int(round(from_start, 0))
|
||||
_LOGGER.debug(
|
||||
"Job %s elapsed %s",
|
||||
|
||||
@@ -11,6 +11,7 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import (
|
||||
_LOGGER,
|
||||
@@ -141,7 +142,9 @@ class StarlineAccount:
|
||||
def gps_attrs(device: StarlineDevice) -> dict[str, Any]:
|
||||
"""Attributes for device tracker."""
|
||||
return {
|
||||
"updated": datetime.utcfromtimestamp(device.position["ts"]).isoformat(),
|
||||
"updated": dt_util.utc_from_timestamp(device.position["ts"])
|
||||
.replace(tzinfo=None)
|
||||
.isoformat(),
|
||||
"online": device.online,
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import attr
|
||||
import av
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import redact_credentials
|
||||
from .const import (
|
||||
@@ -140,7 +141,7 @@ class StreamMuxer:
|
||||
self._part_has_keyframe = False
|
||||
self._stream_settings = stream_settings
|
||||
self._stream_state = stream_state
|
||||
self._start_time = datetime.datetime.utcnow()
|
||||
self._start_time = dt_util.utcnow()
|
||||
|
||||
def make_new_av(
|
||||
self,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from pytraccar import (
|
||||
@@ -44,7 +44,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import slugify
|
||||
from homeassistant.util import dt as dt_util, slugify
|
||||
|
||||
from . import DOMAIN, TRACKER_UPDATE
|
||||
from .const import (
|
||||
@@ -334,7 +334,8 @@ class TraccarScanner:
|
||||
|
||||
async def import_events(self):
|
||||
"""Import events from Traccar."""
|
||||
start_intervel = datetime.utcnow()
|
||||
# get_reports_events requires naive UTC datetimes as of 1.0.0
|
||||
start_intervel = dt_util.utcnow().replace(tzinfo=None)
|
||||
events = await self._api.get_reports_events(
|
||||
devices=[device.id for device in self._devices],
|
||||
start_time=start_intervel,
|
||||
|
||||
Reference in New Issue
Block a user