1 """Support for the AEMET OpenData service."""
3 from aemet_opendata.const
import (
18 SingleCoordinatorWeatherEntity,
22 UnitOfPrecipitationDepth,
30 from .const
import CONDITIONS_MAP
31 from .coordinator
import AemetConfigEntry, WeatherUpdateCoordinator
32 from .entity
import AemetEntity
37 config_entry: AemetConfigEntry,
38 async_add_entities: AddEntitiesCallback,
40 """Set up AEMET OpenData weather entity based on a config entry."""
41 domain_data = config_entry.runtime_data
42 name = domain_data.name
43 weather_coordinator = domain_data.coordinator
45 unique_id = config_entry.unique_id
46 assert unique_id
is not None
53 SingleCoordinatorWeatherEntity[WeatherUpdateCoordinator],
55 """Implementation of an AEMET OpenData weather."""
57 _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
58 _attr_native_pressure_unit = UnitOfPressure.HPA
59 _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
60 _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
61 _attr_supported_features = (
62 WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY
70 coordinator: WeatherUpdateCoordinator,
72 """Initialize the sensor."""
73 super().
__init__(coordinator, name, unique_id)
78 """Return the current condition."""
79 cond = self.
get_aemet_valueget_aemet_value([AOD_WEATHER, AOD_CONDITION])
80 return CONDITIONS_MAP.get(cond)
84 """Return the daily forecast in native units."""
89 """Return the hourly forecast in native units."""
94 """Return the humidity."""
99 """Return the pressure."""
100 return self.
get_aemet_valueget_aemet_value([AOD_WEATHER, AOD_PRESSURE])
104 """Return the temperature."""
109 """Return the wind bearing."""
110 return self.
get_aemet_valueget_aemet_value([AOD_WEATHER, AOD_WIND_DIRECTION])
114 """Return the wind gust speed in native units."""
115 return self.
get_aemet_valueget_aemet_value([AOD_WEATHER, AOD_WIND_SPEED_MAX])
119 """Return the wind speed."""
120 return self.
get_aemet_valueget_aemet_value([AOD_WEATHER, AOD_WIND_SPEED])
list[Forecast] get_aemet_forecast(self, str forecast_mode)
Any get_aemet_value(self, list[str] keys)
def native_wind_speed(self)
list[Forecast] _async_forecast_daily(self)
def native_wind_gust_speed(self)
None __init__(self, str name, str unique_id, WeatherUpdateCoordinator coordinator)
list[Forecast] _async_forecast_hourly(self)
def native_pressure(self)
def native_temperature(self)
None async_setup_entry(HomeAssistant hass, AemetConfigEntry config_entry, AddEntitiesCallback async_add_entities)