refactor(metoffice): use dt_util.now in weather.py (#180902)

Co-authored-by: Gemini <200291788+gemini-code-assist@users.noreply.github.com>
This commit is contained in:
robotsnh
2026-08-31 21:40:44 +02:00
committed by GitHub
co-authored by Gemini
parent 601ed3f198
commit 7950dd4334
+10 -10
View File
@@ -1,6 +1,5 @@
"""Support for UK Met Office weather service."""
from datetime import datetime
from typing import Any, cast, override
from homeassistant.components.weather import (
@@ -30,6 +29,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.util import dt as dt_util
from . import get_device_info
from .const import (
@@ -274,9 +274,9 @@ class MetOfficeWeather(
self.forecast_coordinators["daily"],
)
timesteps = coordinator.data.timesteps
start_datetime = datetime.now( # pylint: disable=home-assistant-enforce-now
tz=timesteps[0]["time"].tzinfo
).replace(hour=0, minute=0, second=0, microsecond=0)
start_datetime = dt_util.now(time_zone=timesteps[0]["time"].tzinfo).replace(
hour=0, minute=0, second=0, microsecond=0
)
return [
_build_daily_forecast_data(timestep)
for timestep in timesteps
@@ -293,9 +293,9 @@ class MetOfficeWeather(
)
timesteps = coordinator.data.timesteps
start_datetime = datetime.now( # pylint: disable=home-assistant-enforce-now
tz=timesteps[0]["time"].tzinfo
).replace(minute=0, second=0, microsecond=0)
start_datetime = dt_util.now(time_zone=timesteps[0]["time"].tzinfo).replace(
minute=0, second=0, microsecond=0
)
return [
_build_hourly_forecast_data(timestep)
for timestep in timesteps
@@ -311,9 +311,9 @@ class MetOfficeWeather(
self.forecast_coordinators["twice_daily"],
)
timesteps = coordinator.data.timesteps
start_datetime = datetime.now( # pylint: disable=home-assistant-enforce-now
tz=timesteps[0]["time"].tzinfo
).replace(hour=0, minute=0, second=0, microsecond=0)
start_datetime = dt_util.now(time_zone=timesteps[0]["time"].tzinfo).replace(
hour=0, minute=0, second=0, microsecond=0
)
return [
_build_twice_daily_forecast_data(timestep)
for timestep in timesteps