Skip to content

Commit 2739064

Browse files
authored
Show current day/hour in metoffice forecasts (home-assistant#152689)
1 parent d9f6a6b commit 2739064

File tree

2 files changed

+152
-3
lines changed

2 files changed

+152
-3
lines changed

homeassistant/components/metoffice/weather.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,13 @@ def _async_forecast_daily(self) -> list[WeatherForecast] | None:
270270
self.forecast_coordinators["daily"],
271271
)
272272
timesteps = coordinator.data.timesteps
273+
start_datetime = datetime.now(tz=timesteps[0]["time"].tzinfo).replace(
274+
hour=0, minute=0, second=0, microsecond=0
275+
)
273276
return [
274277
_build_daily_forecast_data(timestep)
275278
for timestep in timesteps
276-
if timestep["time"] > datetime.now(tz=timesteps[0]["time"].tzinfo)
279+
if timestep["time"] >= start_datetime
277280
]
278281

279282
@callback
@@ -285,10 +288,13 @@ def _async_forecast_hourly(self) -> list[WeatherForecast] | None:
285288
)
286289

287290
timesteps = coordinator.data.timesteps
291+
start_datetime = datetime.now(tz=timesteps[0]["time"].tzinfo).replace(
292+
minute=0, second=0, microsecond=0
293+
)
288294
return [
289295
_build_hourly_forecast_data(timestep)
290296
for timestep in timesteps
291-
if timestep["time"] > datetime.now(tz=timesteps[0]["time"].tzinfo)
297+
if timestep["time"] >= start_datetime
292298
]
293299

294300
@callback
@@ -299,8 +305,11 @@ def _async_forecast_twice_daily(self) -> list[WeatherForecast] | None:
299305
self.forecast_coordinators["twice_daily"],
300306
)
301307
timesteps = coordinator.data.timesteps
308+
start_datetime = datetime.now(tz=timesteps[0]["time"].tzinfo).replace(
309+
hour=0, minute=0, second=0, microsecond=0
310+
)
302311
return [
303312
_build_twice_daily_forecast_data(timestep)
304313
for timestep in timesteps
305-
if timestep["time"] > datetime.now(tz=timesteps[0]["time"].tzinfo)
314+
if timestep["time"] >= start_datetime
306315
]

tests/components/metoffice/snapshots/test_weather.ambr

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
dict({
44
'weather.met_office_wavertree': dict({
55
'forecast': list([
6+
dict({
7+
'apparent_temperature': 9.8,
8+
'condition': 'rainy',
9+
'datetime': '2024-11-23T00:00:00+00:00',
10+
'precipitation': None,
11+
'precipitation_probability': 65,
12+
'pressure': 987.5,
13+
'temperature': 12.6,
14+
'templow': 11.5,
15+
'uv_index': 1,
16+
'wind_bearing': 176,
17+
'wind_gust_speed': 55.55,
18+
'wind_speed': 28.33,
19+
}),
620
dict({
721
'apparent_temperature': 9.2,
822
'condition': 'cloudy',
@@ -95,6 +109,19 @@
95109
dict({
96110
'weather.met_office_wavertree': dict({
97111
'forecast': list([
112+
dict({
113+
'apparent_temperature': 5.8,
114+
'condition': 'rainy',
115+
'datetime': '2024-11-23T12:00:00+00:00',
116+
'precipitation': 0.25,
117+
'precipitation_probability': 61,
118+
'pressure': 987.5,
119+
'temperature': 9.3,
120+
'uv_index': 1,
121+
'wind_bearing': 176,
122+
'wind_gust_speed': 55.55,
123+
'wind_speed': 28.33,
124+
}),
98125
dict({
99126
'apparent_temperature': 6.8,
100127
'condition': 'rainy',
@@ -727,6 +754,36 @@
727754
dict({
728755
'weather.met_office_wavertree': dict({
729756
'forecast': list([
757+
dict({
758+
'apparent_temperature': 9.5,
759+
'condition': 'rainy',
760+
'datetime': '2024-11-23T00:00:00+00:00',
761+
'is_daytime': False,
762+
'precipitation': None,
763+
'precipitation_probability': 74,
764+
'pressure': 984.9,
765+
'temperature': 13.9,
766+
'templow': 10.7,
767+
'uv_index': None,
768+
'wind_bearing': 171,
769+
'wind_gust_speed': 50.69,
770+
'wind_speed': 26.78,
771+
}),
772+
dict({
773+
'apparent_temperature': 9.8,
774+
'condition': 'rainy',
775+
'datetime': '2024-11-23T12:00:00+00:00',
776+
'is_daytime': True,
777+
'precipitation': None,
778+
'precipitation_probability': 65,
779+
'pressure': 987.5,
780+
'temperature': 14.5,
781+
'templow': 11.6,
782+
'uv_index': 1,
783+
'wind_bearing': 176,
784+
'wind_gust_speed': 55.55,
785+
'wind_speed': 28.33,
786+
}),
730787
dict({
731788
'apparent_temperature': 4.8,
732789
'condition': 'cloudy',
@@ -915,6 +972,20 @@
915972
dict({
916973
'weather.met_office_wavertree': dict({
917974
'forecast': list([
975+
dict({
976+
'apparent_temperature': 9.8,
977+
'condition': 'rainy',
978+
'datetime': '2024-11-23T00:00:00+00:00',
979+
'precipitation': None,
980+
'precipitation_probability': 65,
981+
'pressure': 987.5,
982+
'temperature': 12.6,
983+
'templow': 11.5,
984+
'uv_index': 1,
985+
'wind_bearing': 176,
986+
'wind_gust_speed': 55.55,
987+
'wind_speed': 28.33,
988+
}),
918989
dict({
919990
'apparent_temperature': 9.2,
920991
'condition': 'cloudy',
@@ -1007,6 +1078,19 @@
10071078
dict({
10081079
'weather.met_office_wavertree': dict({
10091080
'forecast': list([
1081+
dict({
1082+
'apparent_temperature': 5.8,
1083+
'condition': 'rainy',
1084+
'datetime': '2024-11-23T12:00:00+00:00',
1085+
'precipitation': 0.25,
1086+
'precipitation_probability': 61,
1087+
'pressure': 987.5,
1088+
'temperature': 9.3,
1089+
'uv_index': 1,
1090+
'wind_bearing': 176,
1091+
'wind_gust_speed': 55.55,
1092+
'wind_speed': 28.33,
1093+
}),
10101094
dict({
10111095
'apparent_temperature': 6.8,
10121096
'condition': 'rainy',
@@ -1639,6 +1723,36 @@
16391723
dict({
16401724
'weather.met_office_wavertree': dict({
16411725
'forecast': list([
1726+
dict({
1727+
'apparent_temperature': 9.5,
1728+
'condition': 'rainy',
1729+
'datetime': '2024-11-23T00:00:00+00:00',
1730+
'is_daytime': False,
1731+
'precipitation': None,
1732+
'precipitation_probability': 74,
1733+
'pressure': 984.9,
1734+
'temperature': 13.9,
1735+
'templow': 10.7,
1736+
'uv_index': None,
1737+
'wind_bearing': 171,
1738+
'wind_gust_speed': 50.69,
1739+
'wind_speed': 26.78,
1740+
}),
1741+
dict({
1742+
'apparent_temperature': 9.8,
1743+
'condition': 'rainy',
1744+
'datetime': '2024-11-23T12:00:00+00:00',
1745+
'is_daytime': True,
1746+
'precipitation': None,
1747+
'precipitation_probability': 65,
1748+
'pressure': 987.5,
1749+
'temperature': 14.5,
1750+
'templow': 11.6,
1751+
'uv_index': 1,
1752+
'wind_bearing': 176,
1753+
'wind_gust_speed': 55.55,
1754+
'wind_speed': 28.33,
1755+
}),
16421756
dict({
16431757
'apparent_temperature': 4.8,
16441758
'condition': 'cloudy',
@@ -1825,6 +1939,19 @@
18251939
# ---
18261940
# name: test_forecast_subscription
18271941
list([
1942+
dict({
1943+
'apparent_temperature': 5.8,
1944+
'condition': 'rainy',
1945+
'datetime': '2024-11-23T12:00:00+00:00',
1946+
'precipitation': 0.25,
1947+
'precipitation_probability': 61,
1948+
'pressure': 987.5,
1949+
'temperature': 9.3,
1950+
'uv_index': 1,
1951+
'wind_bearing': 176,
1952+
'wind_gust_speed': 55.55,
1953+
'wind_speed': 28.33,
1954+
}),
18281955
dict({
18291956
'apparent_temperature': 6.8,
18301957
'condition': 'rainy',
@@ -2453,6 +2580,19 @@
24532580
# ---
24542581
# name: test_forecast_subscription.1
24552582
list([
2583+
dict({
2584+
'apparent_temperature': 5.8,
2585+
'condition': 'rainy',
2586+
'datetime': '2024-11-23T12:00:00+00:00',
2587+
'precipitation': 0.25,
2588+
'precipitation_probability': 61,
2589+
'pressure': 987.5,
2590+
'temperature': 9.3,
2591+
'uv_index': 1,
2592+
'wind_bearing': 176,
2593+
'wind_gust_speed': 55.55,
2594+
'wind_speed': 28.33,
2595+
}),
24562596
dict({
24572597
'apparent_temperature': 6.8,
24582598
'condition': 'rainy',

0 commit comments

Comments
 (0)