1 """Support for Met Éireann weather service."""
4 from types
import MappingProxyType
5 from typing
import Any, cast
8 ATTR_FORECAST_CONDITION,
10 DOMAIN
as WEATHER_DOMAIN,
12 SingleCoordinatorWeatherEntity,
20 UnitOfPrecipitationDepth,
32 from .
import MetEireannWeatherData
33 from .const
import CONDITION_MAP, DEFAULT_NAME, DOMAIN, FORECAST_MAP
35 _LOGGER = logging.getLogger(__name__)
39 """Map the conditions provided by the weather API to those supported by the frontend."""
40 if condition
is not None:
41 for key, value
in CONDITION_MAP.items():
42 if condition
in value:
49 config_entry: ConfigEntry,
50 async_add_entities: AddEntitiesCallback,
52 """Add a weather entity from a config_entry."""
53 coordinator = hass.data[DOMAIN][config_entry.entry_id]
54 entity_registry = er.async_get(hass)
57 if entity_id := entity_registry.async_get_entity_id(
62 entity_registry.async_remove(entity_id)
68 """Calculate unique ID."""
71 name_appendix =
"-hourly"
73 return f
"{config[CONF_LATITUDE]}-{config[CONF_LONGITUDE]}{name_appendix}"
77 SingleCoordinatorWeatherEntity[DataUpdateCoordinator[MetEireannWeatherData]]
79 """Implementation of a Met Éireann weather condition."""
81 _attr_attribution =
"Data provided by Met Éireann"
82 _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
83 _attr_native_pressure_unit = UnitOfPressure.HPA
84 _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
85 _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
86 _attr_supported_features = (
87 WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY
92 coordinator: DataUpdateCoordinator[MetEireannWeatherData],
93 config: MappingProxyType[str, Any],
95 """Initialise the platform with a data instance and site."""
99 if (name := self.
_config_config.
get(CONF_NAME))
is not None:
105 entry_type=DeviceEntryType.SERVICE,
106 identifiers={(DOMAIN,)},
107 manufacturer=
"Met Éireann",
109 configuration_url=
"https://www.met.ie",
114 """Return the current condition."""
116 self.coordinator.data.current_weather_data.get(
"condition")
121 """Return the temperature."""
122 return self.coordinator.data.current_weather_data.get(
"temperature")
126 """Return the pressure."""
127 return self.coordinator.data.current_weather_data.get(
"pressure")
131 """Return the humidity."""
132 return self.coordinator.data.current_weather_data.get(
"humidity")
136 """Return the wind speed."""
137 return self.coordinator.data.current_weather_data.get(
"wind_speed")
141 """Return the wind direction."""
142 return self.coordinator.data.current_weather_data.get(
"wind_bearing")
145 """Return the forecast array."""
147 me_forecast = self.coordinator.data.hourly_forecast
149 me_forecast = self.coordinator.data.daily_forecast
150 required_keys = {
"temperature",
"datetime"}
152 ha_forecast: list[Forecast] = []
154 for item
in me_forecast:
155 if not set(item).issuperset(required_keys):
157 ha_item: Forecast = cast(
161 for k, v
in FORECAST_MAP.items()
162 if item.get(v)
is not None
166 if item.get(
"condition"):
169 if item.get(
"datetime"):
170 ha_item[ATTR_FORECAST_TIME] = dt_util.as_utc(
173 ha_forecast.append(ha_item)
178 """Return the daily forecast in native units."""
183 """Return the hourly forecast in native units."""
list[Forecast] _async_forecast_daily(self)
list[Forecast] _forecast(self, bool hourly)
float|None wind_bearing(self)
float|None native_wind_speed(self)
float|None humidity(self)
float|None native_pressure(self)
list[Forecast] _async_forecast_hourly(self)
float|None native_temperature(self)
None __init__(self, DataUpdateCoordinator[MetEireannWeatherData] coordinator, MappingProxyType[str, Any] config)
web.Response get(self, web.Request request, str config_key)
str _calculate_unique_id(MappingProxyType[str, Any] config, bool hourly)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
str|None format_condition(str|None condition)