1 """Support for Meteo-France weather service."""
6 from meteofrance_api.model.forecast
import Forecast
as MeteoFranceForecast
9 ATTR_FORECAST_CONDITION,
10 ATTR_FORECAST_HUMIDITY,
11 ATTR_FORECAST_NATIVE_PRECIPITATION,
12 ATTR_FORECAST_NATIVE_TEMP,
13 ATTR_FORECAST_NATIVE_TEMP_LOW,
14 ATTR_FORECAST_NATIVE_WIND_SPEED,
16 ATTR_FORECAST_WIND_BEARING,
24 UnitOfPrecipitationDepth,
34 DataUpdateCoordinator,
49 _LOGGER = logging.getLogger(__name__)
53 """Return condition from dict CONDITION_MAP."""
54 return CONDITION_MAP.get(condition, condition)
58 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
60 """Set up the Meteo-France weather platform."""
61 coordinator: DataUpdateCoordinator[MeteoFranceForecast] = hass.data[DOMAIN][
63 ][COORDINATOR_FORECAST]
69 entry.options.get(CONF_MODE, FORECAST_MODE_DAILY),
75 "Weather entity (%s) added for %s",
76 entry.options.get(CONF_MODE, FORECAST_MODE_DAILY),
77 coordinator.data.position[
"name"],
82 CoordinatorEntity[DataUpdateCoordinator[MeteoFranceForecast]], WeatherEntity
84 """Representation of a weather condition."""
86 _attr_attribution = ATTRIBUTION
87 _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
88 _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
89 _attr_native_pressure_unit = UnitOfPressure.HPA
90 _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
91 _attr_supported_features = (
92 WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY
96 self, coordinator: DataUpdateCoordinator[MeteoFranceForecast], mode: str
98 """Initialise the platform with a data instance and station name."""
100 self.
_city_name_city_name = self.coordinator.data.position[
"name"]
102 self.
_unique_id_unique_id = f
"{self.coordinator.data.position['lat']},{self.coordinator.data.position['lon']}"
106 """Handle updated data from the coordinator."""
108 assert self.
platformplatform.config_entry
109 self.
platformplatform.config_entry.async_create_task(
115 """Return the unique id of the sensor."""
120 """Return the name of the sensor."""
125 """Return the device info."""
126 assert self.
platformplatform.config_entry
and self.
platformplatform.config_entry.unique_id
128 entry_type=DeviceEntryType.SERVICE,
129 identifiers={(DOMAIN, self.
platformplatform.config_entry.unique_id)},
130 manufacturer=MANUFACTURER,
132 name=self.coordinator.name,
137 """Return the current condition."""
139 self.coordinator.data.current_forecast[
"weather"][
"desc"]
144 """Return the temperature."""
145 return self.coordinator.data.current_forecast[
"T"][
"value"]
149 """Return the pressure."""
150 return self.coordinator.data.current_forecast[
"sea_level"]
154 """Return the humidity."""
155 return self.coordinator.data.current_forecast[
"humidity"]
159 """Return the wind speed."""
160 return self.coordinator.data.current_forecast[
"wind"][
"speed"]
164 """Return the wind bearing."""
165 wind_bearing = self.coordinator.data.current_forecast[
"wind"][
"direction"]
166 if wind_bearing != -1:
171 """Return the forecast."""
172 forecast_data: list[Forecast] = []
174 if mode == FORECAST_MODE_HOURLY:
176 for forecast
in self.coordinator.data.forecast:
178 if forecast[
"dt"] < today:
180 forecast_data.append(
182 ATTR_FORECAST_TIME: dt_util.utc_from_timestamp(
186 forecast[
"weather"][
"desc"]
188 ATTR_FORECAST_HUMIDITY: forecast[
"humidity"],
189 ATTR_FORECAST_NATIVE_TEMP: forecast[
"T"][
"value"],
190 ATTR_FORECAST_NATIVE_PRECIPITATION: forecast[
"rain"].
get(
"1h"),
191 ATTR_FORECAST_NATIVE_WIND_SPEED: forecast[
"wind"][
"speed"],
192 ATTR_FORECAST_WIND_BEARING: forecast[
"wind"][
"direction"]
193 if forecast[
"wind"][
"direction"] != -1
198 for forecast
in self.coordinator.data.daily_forecast:
200 if not forecast.get(
"weather12H"):
202 forecast_data.append(
204 ATTR_FORECAST_TIME: dt_util.utc_from_timestamp(
208 forecast[
"weather12H"][
"desc"]
210 ATTR_FORECAST_HUMIDITY: forecast[
"humidity"][
"max"],
211 ATTR_FORECAST_NATIVE_TEMP: forecast[
"T"][
"max"],
212 ATTR_FORECAST_NATIVE_TEMP_LOW: forecast[
"T"][
"min"],
213 ATTR_FORECAST_NATIVE_PRECIPITATION: forecast[
"precipitation"][
221 """Return the daily forecast in native units."""
222 return self.
_forecast_forecast(FORECAST_MODE_DAILY)
225 """Return the hourly forecast in native units."""
226 return self.
_forecast_forecast(FORECAST_MODE_HOURLY)
def native_wind_speed(self)
None _handle_coordinator_update(self)
None __init__(self, DataUpdateCoordinator[MeteoFranceForecast] coordinator, str mode)
def native_pressure(self)
list[Forecast] async_forecast_hourly(self)
list[Forecast] async_forecast_daily(self)
def native_temperature(self)
list[Forecast] _forecast(self, str mode)
DeviceInfo device_info(self)
None async_update_listeners(self, Iterable[Literal["daily", "hourly", "twice_daily"]]|None forecast_types)
None async_update_listeners(self)
web.Response get(self, web.Request request, str config_key)
def format_condition(str condition)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)