Migrate met_eireann weather to native_* (#74391)
Co-authored-by: avee87 <6134677+avee87@users.noreply.github.com> Co-authored-by: Franck Nijhof <git@frenck.dev>pull/74522/head
parent
d0a86b3cd2
commit
6ba06c0f53
|
@ -1,6 +1,4 @@
|
|||
"""Constants for Met Éireann component."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_CONDITION_CLEAR_NIGHT,
|
||||
ATTR_CONDITION_CLOUDY,
|
||||
|
@ -12,13 +10,13 @@ from homeassistant.components.weather import (
|
|||
ATTR_CONDITION_SNOWY_RAINY,
|
||||
ATTR_CONDITION_SUNNY,
|
||||
ATTR_FORECAST_CONDITION,
|
||||
ATTR_FORECAST_NATIVE_PRESSURE,
|
||||
ATTR_FORECAST_NATIVE_TEMP,
|
||||
ATTR_FORECAST_NATIVE_TEMP_LOW,
|
||||
ATTR_FORECAST_NATIVE_WIND_SPEED,
|
||||
ATTR_FORECAST_PRECIPITATION,
|
||||
ATTR_FORECAST_PRESSURE,
|
||||
ATTR_FORECAST_TEMP,
|
||||
ATTR_FORECAST_TEMP_LOW,
|
||||
ATTR_FORECAST_TIME,
|
||||
ATTR_FORECAST_WIND_BEARING,
|
||||
ATTR_FORECAST_WIND_SPEED,
|
||||
DOMAIN as WEATHER_DOMAIN,
|
||||
)
|
||||
|
||||
|
@ -32,17 +30,15 @@ HOME_LOCATION_NAME = "Home"
|
|||
|
||||
ENTITY_ID_SENSOR_FORMAT_HOME = f"{WEATHER_DOMAIN}.met_eireann_{HOME_LOCATION_NAME}"
|
||||
|
||||
_LOGGER = logging.getLogger(".")
|
||||
|
||||
FORECAST_MAP = {
|
||||
ATTR_FORECAST_CONDITION: "condition",
|
||||
ATTR_FORECAST_PRESSURE: "pressure",
|
||||
ATTR_FORECAST_NATIVE_PRESSURE: "pressure",
|
||||
ATTR_FORECAST_PRECIPITATION: "precipitation",
|
||||
ATTR_FORECAST_TEMP: "temperature",
|
||||
ATTR_FORECAST_TEMP_LOW: "templow",
|
||||
ATTR_FORECAST_NATIVE_TEMP: "temperature",
|
||||
ATTR_FORECAST_NATIVE_TEMP_LOW: "templow",
|
||||
ATTR_FORECAST_TIME: "datetime",
|
||||
ATTR_FORECAST_WIND_BEARING: "wind_bearing",
|
||||
ATTR_FORECAST_WIND_SPEED: "wind_speed",
|
||||
ATTR_FORECAST_NATIVE_WIND_SPEED: "wind_speed",
|
||||
}
|
||||
|
||||
CONDITION_MAP = {
|
||||
|
|
|
@ -3,8 +3,6 @@ import logging
|
|||
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_FORECAST_CONDITION,
|
||||
ATTR_FORECAST_PRECIPITATION,
|
||||
ATTR_FORECAST_TEMP,
|
||||
ATTR_FORECAST_TIME,
|
||||
WeatherEntity,
|
||||
)
|
||||
|
@ -13,12 +11,9 @@ from homeassistant.const import (
|
|||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_NAME,
|
||||
LENGTH_INCHES,
|
||||
LENGTH_MILLIMETERS,
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_INHG,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -27,9 +22,6 @@ from homeassistant.helpers.entity import DeviceInfo
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.distance import convert as convert_distance
|
||||
from homeassistant.util.pressure import convert as convert_pressure
|
||||
from homeassistant.util.speed import convert as convert_speed
|
||||
|
||||
from .const import ATTRIBUTION, CONDITION_MAP, DEFAULT_NAME, DOMAIN, FORECAST_MAP
|
||||
|
||||
|
@ -54,12 +46,8 @@ async def async_setup_entry(
|
|||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
async_add_entities(
|
||||
[
|
||||
MetEireannWeather(
|
||||
coordinator, config_entry.data, hass.config.units.is_metric, False
|
||||
),
|
||||
MetEireannWeather(
|
||||
coordinator, config_entry.data, hass.config.units.is_metric, True
|
||||
),
|
||||
MetEireannWeather(coordinator, config_entry.data, False),
|
||||
MetEireannWeather(coordinator, config_entry.data, True),
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -67,11 +55,15 @@ async def async_setup_entry(
|
|||
class MetEireannWeather(CoordinatorEntity, WeatherEntity):
|
||||
"""Implementation of a Met Éireann weather condition."""
|
||||
|
||||
def __init__(self, coordinator, config, is_metric, hourly):
|
||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
||||
_attr_native_pressure_unit = PRESSURE_HPA
|
||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
||||
|
||||
def __init__(self, coordinator, config, hourly):
|
||||
"""Initialise the platform with a data instance and site."""
|
||||
super().__init__(coordinator)
|
||||
self._config = config
|
||||
self._is_metric = is_metric
|
||||
self._hourly = hourly
|
||||
|
||||
@property
|
||||
|
@ -109,23 +101,14 @@ class MetEireannWeather(CoordinatorEntity, WeatherEntity):
|
|||
)
|
||||
|
||||
@property
|
||||
def temperature(self):
|
||||
def native_temperature(self):
|
||||
"""Return the temperature."""
|
||||
return self.coordinator.data.current_weather_data.get("temperature")
|
||||
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
"""Return the unit of measurement."""
|
||||
return TEMP_CELSIUS
|
||||
|
||||
@property
|
||||
def pressure(self):
|
||||
def native_pressure(self):
|
||||
"""Return the pressure."""
|
||||
pressure_hpa = self.coordinator.data.current_weather_data.get("pressure")
|
||||
if self._is_metric or pressure_hpa is None:
|
||||
return pressure_hpa
|
||||
|
||||
return round(convert_pressure(pressure_hpa, PRESSURE_HPA, PRESSURE_INHG), 2)
|
||||
return self.coordinator.data.current_weather_data.get("pressure")
|
||||
|
||||
@property
|
||||
def humidity(self):
|
||||
|
@ -133,16 +116,9 @@ class MetEireannWeather(CoordinatorEntity, WeatherEntity):
|
|||
return self.coordinator.data.current_weather_data.get("humidity")
|
||||
|
||||
@property
|
||||
def wind_speed(self):
|
||||
def native_wind_speed(self):
|
||||
"""Return the wind speed."""
|
||||
speed_m_s = self.coordinator.data.current_weather_data.get("wind_speed")
|
||||
if self._is_metric or speed_m_s is None:
|
||||
return speed_m_s
|
||||
|
||||
speed_mi_h = convert_speed(
|
||||
speed_m_s, SPEED_METERS_PER_SECOND, SPEED_MILES_PER_HOUR
|
||||
)
|
||||
return int(round(speed_mi_h))
|
||||
return self.coordinator.data.current_weather_data.get("wind_speed")
|
||||
|
||||
@property
|
||||
def wind_bearing(self):
|
||||
|
@ -161,7 +137,7 @@ class MetEireannWeather(CoordinatorEntity, WeatherEntity):
|
|||
me_forecast = self.coordinator.data.hourly_forecast
|
||||
else:
|
||||
me_forecast = self.coordinator.data.daily_forecast
|
||||
required_keys = {ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME}
|
||||
required_keys = {"temperature", "datetime"}
|
||||
|
||||
ha_forecast = []
|
||||
|
||||
|
@ -171,13 +147,6 @@ class MetEireannWeather(CoordinatorEntity, WeatherEntity):
|
|||
ha_item = {
|
||||
k: item[v] for k, v in FORECAST_MAP.items() if item.get(v) is not None
|
||||
}
|
||||
if not self._is_metric and ATTR_FORECAST_PRECIPITATION in ha_item:
|
||||
precip_inches = convert_distance(
|
||||
ha_item[ATTR_FORECAST_PRECIPITATION],
|
||||
LENGTH_MILLIMETERS,
|
||||
LENGTH_INCHES,
|
||||
)
|
||||
ha_item[ATTR_FORECAST_PRECIPITATION] = round(precip_inches, 2)
|
||||
if ha_item.get(ATTR_FORECAST_CONDITION):
|
||||
ha_item[ATTR_FORECAST_CONDITION] = format_condition(
|
||||
ha_item[ATTR_FORECAST_CONDITION]
|
||||
|
|
Loading…
Reference in New Issue