1
mirror of https://github.com/home-assistant/core synced 2024-10-01 05:30:36 +02:00

Migrate metoffice to native_* (#74312)

This commit is contained in:
avee87 2022-07-02 21:27:47 +01:00 committed by GitHub
parent 3bebbf7970
commit 08c2bd82bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 25 deletions

View File

@ -1,15 +1,15 @@
"""Support for UK Met Office weather service."""
from homeassistant.components.weather import (
ATTR_FORECAST_CONDITION,
ATTR_FORECAST_NATIVE_TEMP,
ATTR_FORECAST_NATIVE_WIND_SPEED,
ATTR_FORECAST_PRECIPITATION_PROBABILITY,
ATTR_FORECAST_TEMP,
ATTR_FORECAST_TIME,
ATTR_FORECAST_WIND_BEARING,
ATTR_FORECAST_WIND_SPEED,
WeatherEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS
from homeassistant.const import PRESSURE_HPA, SPEED_MILES_PER_HOUR, TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -55,11 +55,11 @@ def _build_forecast_data(timestep):
if timestep.precipitation:
data[ATTR_FORECAST_PRECIPITATION_PROBABILITY] = timestep.precipitation.value
if timestep.temperature:
data[ATTR_FORECAST_TEMP] = timestep.temperature.value
data[ATTR_FORECAST_NATIVE_TEMP] = timestep.temperature.value
if timestep.wind_direction:
data[ATTR_FORECAST_WIND_BEARING] = timestep.wind_direction.value
if timestep.wind_speed:
data[ATTR_FORECAST_WIND_SPEED] = timestep.wind_speed.value
data[ATTR_FORECAST_NATIVE_WIND_SPEED] = timestep.wind_speed.value
return data
@ -73,6 +73,10 @@ def _get_weather_condition(metoffice_code):
class MetOfficeWeather(CoordinatorEntity, WeatherEntity):
"""Implementation of a Met Office weather condition."""
_attr_native_temperature_unit = TEMP_CELSIUS
_attr_native_pressure_unit = PRESSURE_HPA
_attr_native_wind_speed_unit = SPEED_MILES_PER_HOUR
def __init__(self, coordinator, hass_data, use_3hourly):
"""Initialise the platform with a data instance."""
super().__init__(coordinator)
@ -94,17 +98,12 @@ class MetOfficeWeather(CoordinatorEntity, WeatherEntity):
return None
@property
def temperature(self):
def native_temperature(self):
"""Return the platform temperature."""
if self.coordinator.data.now.temperature:
return self.coordinator.data.now.temperature.value
return None
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property
def visibility(self):
"""Return the platform visibility."""
@ -119,7 +118,7 @@ class MetOfficeWeather(CoordinatorEntity, WeatherEntity):
return _visibility
@property
def pressure(self):
def native_pressure(self):
"""Return the mean sea-level pressure."""
weather_now = self.coordinator.data.now
if weather_now and weather_now.pressure:
@ -135,7 +134,7 @@ class MetOfficeWeather(CoordinatorEntity, WeatherEntity):
return None
@property
def wind_speed(self):
def native_wind_speed(self):
"""Return the wind speed."""
weather_now = self.coordinator.data.now
if weather_now and weather_now.wind_speed:

View File

@ -133,7 +133,8 @@ async def test_one_weather_site_running(hass, requests_mock):
assert weather.state == "sunny"
assert weather.attributes.get("temperature") == 17
assert weather.attributes.get("wind_speed") == 9
assert weather.attributes.get("wind_speed") == 14.48
assert weather.attributes.get("wind_speed_unit") == "km/h"
assert weather.attributes.get("wind_bearing") == "SSE"
assert weather.attributes.get("visibility") == "Good - 10-20"
assert weather.attributes.get("humidity") == 50
@ -148,7 +149,7 @@ async def test_one_weather_site_running(hass, requests_mock):
assert weather.attributes.get("forecast")[26]["condition"] == "cloudy"
assert weather.attributes.get("forecast")[26]["precipitation_probability"] == 9
assert weather.attributes.get("forecast")[26]["temperature"] == 10
assert weather.attributes.get("forecast")[26]["wind_speed"] == 4
assert weather.attributes.get("forecast")[26]["wind_speed"] == 6.44
assert weather.attributes.get("forecast")[26]["wind_bearing"] == "NNE"
# Wavertree daily weather platform expected results
@ -157,7 +158,7 @@ async def test_one_weather_site_running(hass, requests_mock):
assert weather.state == "sunny"
assert weather.attributes.get("temperature") == 19
assert weather.attributes.get("wind_speed") == 9
assert weather.attributes.get("wind_speed") == 14.48
assert weather.attributes.get("wind_bearing") == "SSE"
assert weather.attributes.get("visibility") == "Good - 10-20"
assert weather.attributes.get("humidity") == 50
@ -172,7 +173,7 @@ async def test_one_weather_site_running(hass, requests_mock):
assert weather.attributes.get("forecast")[3]["condition"] == "rainy"
assert weather.attributes.get("forecast")[3]["precipitation_probability"] == 59
assert weather.attributes.get("forecast")[3]["temperature"] == 13
assert weather.attributes.get("forecast")[3]["wind_speed"] == 13
assert weather.attributes.get("forecast")[3]["wind_speed"] == 20.92
assert weather.attributes.get("forecast")[3]["wind_bearing"] == "SE"
@ -229,7 +230,8 @@ async def test_two_weather_sites_running(hass, requests_mock):
assert weather.state == "sunny"
assert weather.attributes.get("temperature") == 17
assert weather.attributes.get("wind_speed") == 9
assert weather.attributes.get("wind_speed") == 14.48
assert weather.attributes.get("wind_speed_unit") == "km/h"
assert weather.attributes.get("wind_bearing") == "SSE"
assert weather.attributes.get("visibility") == "Good - 10-20"
assert weather.attributes.get("humidity") == 50
@ -244,7 +246,7 @@ async def test_two_weather_sites_running(hass, requests_mock):
assert weather.attributes.get("forecast")[18]["condition"] == "clear-night"
assert weather.attributes.get("forecast")[18]["precipitation_probability"] == 1
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"] == 6.44
assert weather.attributes.get("forecast")[18]["wind_bearing"] == "NW"
# Wavertree daily weather platform expected results
@ -253,7 +255,8 @@ async def test_two_weather_sites_running(hass, requests_mock):
assert weather.state == "sunny"
assert weather.attributes.get("temperature") == 19
assert weather.attributes.get("wind_speed") == 9
assert weather.attributes.get("wind_speed") == 14.48
assert weather.attributes.get("wind_speed_unit") == "km/h"
assert weather.attributes.get("wind_bearing") == "SSE"
assert weather.attributes.get("visibility") == "Good - 10-20"
assert weather.attributes.get("humidity") == 50
@ -268,7 +271,7 @@ async def test_two_weather_sites_running(hass, requests_mock):
assert weather.attributes.get("forecast")[3]["condition"] == "rainy"
assert weather.attributes.get("forecast")[3]["precipitation_probability"] == 59
assert weather.attributes.get("forecast")[3]["temperature"] == 13
assert weather.attributes.get("forecast")[3]["wind_speed"] == 13
assert weather.attributes.get("forecast")[3]["wind_speed"] == 20.92
assert weather.attributes.get("forecast")[3]["wind_bearing"] == "SE"
# King's Lynn 3-hourly weather platform expected results
@ -277,7 +280,8 @@ async def test_two_weather_sites_running(hass, requests_mock):
assert weather.state == "sunny"
assert weather.attributes.get("temperature") == 14
assert weather.attributes.get("wind_speed") == 2
assert weather.attributes.get("wind_speed") == 3.22
assert weather.attributes.get("wind_speed_unit") == "km/h"
assert weather.attributes.get("wind_bearing") == "E"
assert weather.attributes.get("visibility") == "Very Good - 20-40"
assert weather.attributes.get("humidity") == 60
@ -292,7 +296,7 @@ async def test_two_weather_sites_running(hass, requests_mock):
assert weather.attributes.get("forecast")[18]["condition"] == "cloudy"
assert weather.attributes.get("forecast")[18]["precipitation_probability"] == 9
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"] == 11.27
assert weather.attributes.get("forecast")[18]["wind_bearing"] == "SE"
# King's Lynn daily weather platform expected results
@ -301,7 +305,8 @@ async def test_two_weather_sites_running(hass, requests_mock):
assert weather.state == "cloudy"
assert weather.attributes.get("temperature") == 9
assert weather.attributes.get("wind_speed") == 4
assert weather.attributes.get("wind_speed") == 6.44
assert weather.attributes.get("wind_speed_unit") == "km/h"
assert weather.attributes.get("wind_bearing") == "ESE"
assert weather.attributes.get("visibility") == "Very Good - 20-40"
assert weather.attributes.get("humidity") == 75
@ -316,5 +321,5 @@ async def test_two_weather_sites_running(hass, requests_mock):
assert weather.attributes.get("forecast")[2]["condition"] == "cloudy"
assert weather.attributes.get("forecast")[2]["precipitation_probability"] == 14
assert weather.attributes.get("forecast")[2]["temperature"] == 11
assert weather.attributes.get("forecast")[2]["wind_speed"] == 7
assert weather.attributes.get("forecast")[2]["wind_speed"] == 11.27
assert weather.attributes.get("forecast")[2]["wind_bearing"] == "ESE"