From 27390647ff92fa0ed84e29364ca0ea94794d6d9b Mon Sep 17 00:00:00 2001 From: avee87 <6134677+avee87@users.noreply.github.com> Date: Sat, 25 Oct 2025 00:14:46 +0100 Subject: [PATCH] Show current day/hour in metoffice forecasts (#152689) --- homeassistant/components/metoffice/weather.py | 15 +- .../metoffice/snapshots/test_weather.ambr | 140 ++++++++++++++++++ 2 files changed, 152 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/metoffice/weather.py b/homeassistant/components/metoffice/weather.py index 04a2c0fd5b8..5624faebfb2 100644 --- a/homeassistant/components/metoffice/weather.py +++ b/homeassistant/components/metoffice/weather.py @@ -270,10 +270,13 @@ class MetOfficeWeather( self.forecast_coordinators["daily"], ) timesteps = coordinator.data.timesteps + start_datetime = datetime.now(tz=timesteps[0]["time"].tzinfo).replace( + hour=0, minute=0, second=0, microsecond=0 + ) return [ _build_daily_forecast_data(timestep) for timestep in timesteps - if timestep["time"] > datetime.now(tz=timesteps[0]["time"].tzinfo) + if timestep["time"] >= start_datetime ] @callback @@ -285,10 +288,13 @@ class MetOfficeWeather( ) timesteps = coordinator.data.timesteps + start_datetime = datetime.now(tz=timesteps[0]["time"].tzinfo).replace( + minute=0, second=0, microsecond=0 + ) return [ _build_hourly_forecast_data(timestep) for timestep in timesteps - if timestep["time"] > datetime.now(tz=timesteps[0]["time"].tzinfo) + if timestep["time"] >= start_datetime ] @callback @@ -299,8 +305,11 @@ class MetOfficeWeather( self.forecast_coordinators["twice_daily"], ) timesteps = coordinator.data.timesteps + start_datetime = datetime.now(tz=timesteps[0]["time"].tzinfo).replace( + hour=0, minute=0, second=0, microsecond=0 + ) return [ _build_twice_daily_forecast_data(timestep) for timestep in timesteps - if timestep["time"] > datetime.now(tz=timesteps[0]["time"].tzinfo) + if timestep["time"] >= start_datetime ] diff --git a/tests/components/metoffice/snapshots/test_weather.ambr b/tests/components/metoffice/snapshots/test_weather.ambr index 74b54d1bc2f..2fcef6f088b 100644 --- a/tests/components/metoffice/snapshots/test_weather.ambr +++ b/tests/components/metoffice/snapshots/test_weather.ambr @@ -3,6 +3,20 @@ dict({ 'weather.met_office_wavertree': dict({ 'forecast': list([ + dict({ + 'apparent_temperature': 9.8, + 'condition': 'rainy', + 'datetime': '2024-11-23T00:00:00+00:00', + 'precipitation': None, + 'precipitation_probability': 65, + 'pressure': 987.5, + 'temperature': 12.6, + 'templow': 11.5, + 'uv_index': 1, + 'wind_bearing': 176, + 'wind_gust_speed': 55.55, + 'wind_speed': 28.33, + }), dict({ 'apparent_temperature': 9.2, 'condition': 'cloudy', @@ -95,6 +109,19 @@ dict({ 'weather.met_office_wavertree': dict({ 'forecast': list([ + dict({ + 'apparent_temperature': 5.8, + 'condition': 'rainy', + 'datetime': '2024-11-23T12:00:00+00:00', + 'precipitation': 0.25, + 'precipitation_probability': 61, + 'pressure': 987.5, + 'temperature': 9.3, + 'uv_index': 1, + 'wind_bearing': 176, + 'wind_gust_speed': 55.55, + 'wind_speed': 28.33, + }), dict({ 'apparent_temperature': 6.8, 'condition': 'rainy', @@ -727,6 +754,36 @@ dict({ 'weather.met_office_wavertree': dict({ 'forecast': list([ + dict({ + 'apparent_temperature': 9.5, + 'condition': 'rainy', + 'datetime': '2024-11-23T00:00:00+00:00', + 'is_daytime': False, + 'precipitation': None, + 'precipitation_probability': 74, + 'pressure': 984.9, + 'temperature': 13.9, + 'templow': 10.7, + 'uv_index': None, + 'wind_bearing': 171, + 'wind_gust_speed': 50.69, + 'wind_speed': 26.78, + }), + dict({ + 'apparent_temperature': 9.8, + 'condition': 'rainy', + 'datetime': '2024-11-23T12:00:00+00:00', + 'is_daytime': True, + 'precipitation': None, + 'precipitation_probability': 65, + 'pressure': 987.5, + 'temperature': 14.5, + 'templow': 11.6, + 'uv_index': 1, + 'wind_bearing': 176, + 'wind_gust_speed': 55.55, + 'wind_speed': 28.33, + }), dict({ 'apparent_temperature': 4.8, 'condition': 'cloudy', @@ -915,6 +972,20 @@ dict({ 'weather.met_office_wavertree': dict({ 'forecast': list([ + dict({ + 'apparent_temperature': 9.8, + 'condition': 'rainy', + 'datetime': '2024-11-23T00:00:00+00:00', + 'precipitation': None, + 'precipitation_probability': 65, + 'pressure': 987.5, + 'temperature': 12.6, + 'templow': 11.5, + 'uv_index': 1, + 'wind_bearing': 176, + 'wind_gust_speed': 55.55, + 'wind_speed': 28.33, + }), dict({ 'apparent_temperature': 9.2, 'condition': 'cloudy', @@ -1007,6 +1078,19 @@ dict({ 'weather.met_office_wavertree': dict({ 'forecast': list([ + dict({ + 'apparent_temperature': 5.8, + 'condition': 'rainy', + 'datetime': '2024-11-23T12:00:00+00:00', + 'precipitation': 0.25, + 'precipitation_probability': 61, + 'pressure': 987.5, + 'temperature': 9.3, + 'uv_index': 1, + 'wind_bearing': 176, + 'wind_gust_speed': 55.55, + 'wind_speed': 28.33, + }), dict({ 'apparent_temperature': 6.8, 'condition': 'rainy', @@ -1639,6 +1723,36 @@ dict({ 'weather.met_office_wavertree': dict({ 'forecast': list([ + dict({ + 'apparent_temperature': 9.5, + 'condition': 'rainy', + 'datetime': '2024-11-23T00:00:00+00:00', + 'is_daytime': False, + 'precipitation': None, + 'precipitation_probability': 74, + 'pressure': 984.9, + 'temperature': 13.9, + 'templow': 10.7, + 'uv_index': None, + 'wind_bearing': 171, + 'wind_gust_speed': 50.69, + 'wind_speed': 26.78, + }), + dict({ + 'apparent_temperature': 9.8, + 'condition': 'rainy', + 'datetime': '2024-11-23T12:00:00+00:00', + 'is_daytime': True, + 'precipitation': None, + 'precipitation_probability': 65, + 'pressure': 987.5, + 'temperature': 14.5, + 'templow': 11.6, + 'uv_index': 1, + 'wind_bearing': 176, + 'wind_gust_speed': 55.55, + 'wind_speed': 28.33, + }), dict({ 'apparent_temperature': 4.8, 'condition': 'cloudy', @@ -1825,6 +1939,19 @@ # --- # name: test_forecast_subscription list([ + dict({ + 'apparent_temperature': 5.8, + 'condition': 'rainy', + 'datetime': '2024-11-23T12:00:00+00:00', + 'precipitation': 0.25, + 'precipitation_probability': 61, + 'pressure': 987.5, + 'temperature': 9.3, + 'uv_index': 1, + 'wind_bearing': 176, + 'wind_gust_speed': 55.55, + 'wind_speed': 28.33, + }), dict({ 'apparent_temperature': 6.8, 'condition': 'rainy', @@ -2453,6 +2580,19 @@ # --- # name: test_forecast_subscription.1 list([ + dict({ + 'apparent_temperature': 5.8, + 'condition': 'rainy', + 'datetime': '2024-11-23T12:00:00+00:00', + 'precipitation': 0.25, + 'precipitation_probability': 61, + 'pressure': 987.5, + 'temperature': 9.3, + 'uv_index': 1, + 'wind_bearing': 176, + 'wind_gust_speed': 55.55, + 'wind_speed': 28.33, + }), dict({ 'apparent_temperature': 6.8, 'condition': 'rainy',