Revert metoffice weather daytime (#60978)

This commit is contained in:
Martin Hjelmare 2021-12-04 10:29:48 +01:00 committed by GitHub
parent 8bb1a3fac4
commit c9bb688a79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 20 deletions

View File

@ -24,8 +24,6 @@ DOMAIN = "metoffice"
DEFAULT_NAME = "Met Office" DEFAULT_NAME = "Met Office"
ATTRIBUTION = "Data provided by the Met Office" ATTRIBUTION = "Data provided by the Met Office"
ATTR_FORECAST_DAYTIME = "daytime"
DEFAULT_SCAN_INTERVAL = timedelta(minutes=15) DEFAULT_SCAN_INTERVAL = timedelta(minutes=15)
METOFFICE_COORDINATES = "metoffice_coordinates" METOFFICE_COORDINATES = "metoffice_coordinates"

View File

@ -15,7 +15,6 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import get_device_info from . import get_device_info
from .const import ( from .const import (
ATTR_FORECAST_DAYTIME,
ATTRIBUTION, ATTRIBUTION,
CONDITION_CLASSES, CONDITION_CLASSES,
DEFAULT_NAME, DEFAULT_NAME,
@ -47,7 +46,7 @@ async def async_setup_entry(
) )
def _build_forecast_data(timestep, use_3hourly): def _build_forecast_data(timestep):
data = {} data = {}
data[ATTR_FORECAST_TIME] = timestep.date.isoformat() data[ATTR_FORECAST_TIME] = timestep.date.isoformat()
if timestep.weather: if timestep.weather:
@ -60,9 +59,6 @@ def _build_forecast_data(timestep, use_3hourly):
data[ATTR_FORECAST_WIND_BEARING] = timestep.wind_direction.value data[ATTR_FORECAST_WIND_BEARING] = timestep.wind_direction.value
if timestep.wind_speed: if timestep.wind_speed:
data[ATTR_FORECAST_WIND_SPEED] = timestep.wind_speed.value data[ATTR_FORECAST_WIND_SPEED] = timestep.wind_speed.value
if not use_3hourly:
# if it's close to noon, mark as Day, otherwise as Night
data[ATTR_FORECAST_DAYTIME] = abs(timestep.date.hour - 12) < 6
return data return data
@ -86,7 +82,6 @@ class MetOfficeWeather(CoordinatorEntity, WeatherEntity):
) )
self._attr_name = f"{DEFAULT_NAME} {hass_data[METOFFICE_NAME]} {mode_label}" self._attr_name = f"{DEFAULT_NAME} {hass_data[METOFFICE_NAME]} {mode_label}"
self._attr_unique_id = hass_data[METOFFICE_COORDINATES] self._attr_unique_id = hass_data[METOFFICE_COORDINATES]
self._use_3hourly = use_3hourly
if not use_3hourly: if not use_3hourly:
self._attr_unique_id = f"{self._attr_unique_id}_{MODE_DAILY}" self._attr_unique_id = f"{self._attr_unique_id}_{MODE_DAILY}"
@ -160,7 +155,7 @@ class MetOfficeWeather(CoordinatorEntity, WeatherEntity):
if self.coordinator.data.forecast is None: if self.coordinator.data.forecast is None:
return None return None
return [ return [
_build_forecast_data(timestep, self._use_3hourly) _build_forecast_data(timestep)
for timestep in self.coordinator.data.forecast for timestep in self.coordinator.data.forecast
] ]

View File

@ -181,13 +181,6 @@ async def test_one_weather_site_running(hass, requests_mock, legacy_patchable_ti
assert weather.attributes.get("forecast")[7]["temperature"] == 13 assert weather.attributes.get("forecast")[7]["temperature"] == 13
assert weather.attributes.get("forecast")[7]["wind_speed"] == 13 assert weather.attributes.get("forecast")[7]["wind_speed"] == 13
assert weather.attributes.get("forecast")[7]["wind_bearing"] == "SE" assert weather.attributes.get("forecast")[7]["wind_bearing"] == "SE"
assert weather.attributes.get("forecast")[7]["daytime"] is True
# Check that night entry is correctly marked as Night
assert (
weather.attributes.get("forecast")[6]["datetime"] == "2020-04-29T00:00:00+00:00"
)
assert weather.attributes.get("forecast")[6]["daytime"] is False
@patch( @patch(
@ -263,7 +256,6 @@ async def test_two_weather_sites_running(hass, requests_mock, legacy_patchable_t
assert weather.attributes.get("forecast")[18]["temperature"] == 9 assert weather.attributes.get("forecast")[18]["temperature"] == 9
assert weather.attributes.get("forecast")[18]["wind_speed"] == 4 assert weather.attributes.get("forecast")[18]["wind_speed"] == 4
assert weather.attributes.get("forecast")[18]["wind_bearing"] == "NW" assert weather.attributes.get("forecast")[18]["wind_bearing"] == "NW"
assert "daytime" not in weather.attributes.get("forecast")[18]
# Wavertree daily weather platform expected results # Wavertree daily weather platform expected results
weather = hass.states.get("weather.met_office_wavertree_daily") weather = hass.states.get("weather.met_office_wavertree_daily")
@ -287,7 +279,6 @@ async def test_two_weather_sites_running(hass, requests_mock, legacy_patchable_t
assert weather.attributes.get("forecast")[7]["temperature"] == 13 assert weather.attributes.get("forecast")[7]["temperature"] == 13
assert weather.attributes.get("forecast")[7]["wind_speed"] == 13 assert weather.attributes.get("forecast")[7]["wind_speed"] == 13
assert weather.attributes.get("forecast")[7]["wind_bearing"] == "SE" assert weather.attributes.get("forecast")[7]["wind_bearing"] == "SE"
assert weather.attributes.get("forecast")[7]["daytime"] is True
# King's Lynn 3-hourly weather platform expected results # King's Lynn 3-hourly weather platform expected results
weather = hass.states.get("weather.met_office_king_s_lynn_3_hourly") weather = hass.states.get("weather.met_office_king_s_lynn_3_hourly")
@ -312,7 +303,6 @@ async def test_two_weather_sites_running(hass, requests_mock, legacy_patchable_t
assert weather.attributes.get("forecast")[18]["temperature"] == 10 assert weather.attributes.get("forecast")[18]["temperature"] == 10
assert weather.attributes.get("forecast")[18]["wind_speed"] == 7 assert weather.attributes.get("forecast")[18]["wind_speed"] == 7
assert weather.attributes.get("forecast")[18]["wind_bearing"] == "SE" assert weather.attributes.get("forecast")[18]["wind_bearing"] == "SE"
assert "daytime" not in weather.attributes.get("forecast")[18]
# King's Lynn daily weather platform expected results # King's Lynn daily weather platform expected results
weather = hass.states.get("weather.met_office_king_s_lynn_daily") weather = hass.states.get("weather.met_office_king_s_lynn_daily")
@ -336,4 +326,3 @@ async def test_two_weather_sites_running(hass, requests_mock, legacy_patchable_t
assert weather.attributes.get("forecast")[5]["temperature"] == 11 assert weather.attributes.get("forecast")[5]["temperature"] == 11
assert weather.attributes.get("forecast")[5]["wind_speed"] == 7 assert weather.attributes.get("forecast")[5]["wind_speed"] == 7
assert weather.attributes.get("forecast")[5]["wind_bearing"] == "ESE" assert weather.attributes.get("forecast")[5]["wind_bearing"] == "ESE"
assert weather.attributes.get("forecast")[5]["daytime"] is True