mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Migrate Meteo_france to native_* (#74297)
This commit is contained in:
parent
40ed44cbea
commit
5bd9c5aee8
@ -4,16 +4,22 @@ import time
|
|||||||
|
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
ATTR_FORECAST_CONDITION,
|
ATTR_FORECAST_CONDITION,
|
||||||
ATTR_FORECAST_PRECIPITATION,
|
ATTR_FORECAST_NATIVE_PRECIPITATION,
|
||||||
ATTR_FORECAST_TEMP,
|
ATTR_FORECAST_NATIVE_TEMP,
|
||||||
ATTR_FORECAST_TEMP_LOW,
|
ATTR_FORECAST_NATIVE_TEMP_LOW,
|
||||||
|
ATTR_FORECAST_NATIVE_WIND_SPEED,
|
||||||
ATTR_FORECAST_TIME,
|
ATTR_FORECAST_TIME,
|
||||||
ATTR_FORECAST_WIND_BEARING,
|
ATTR_FORECAST_WIND_BEARING,
|
||||||
ATTR_FORECAST_WIND_SPEED,
|
|
||||||
WeatherEntity,
|
WeatherEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_MODE, TEMP_CELSIUS
|
from homeassistant.const import (
|
||||||
|
CONF_MODE,
|
||||||
|
LENGTH_MILLIMETERS,
|
||||||
|
PRESSURE_HPA,
|
||||||
|
SPEED_METERS_PER_SECOND,
|
||||||
|
TEMP_CELSIUS,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
@ -71,6 +77,11 @@ async def async_setup_entry(
|
|||||||
class MeteoFranceWeather(CoordinatorEntity, WeatherEntity):
|
class MeteoFranceWeather(CoordinatorEntity, WeatherEntity):
|
||||||
"""Representation of a weather condition."""
|
"""Representation of a weather condition."""
|
||||||
|
|
||||||
|
_attr_native_temperature_unit = TEMP_CELSIUS
|
||||||
|
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
||||||
|
_attr_native_pressure_unit = PRESSURE_HPA
|
||||||
|
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
||||||
|
|
||||||
def __init__(self, coordinator: DataUpdateCoordinator, mode: str) -> None:
|
def __init__(self, coordinator: DataUpdateCoordinator, mode: str) -> None:
|
||||||
"""Initialise the platform with a data instance and station name."""
|
"""Initialise the platform with a data instance and station name."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
@ -107,17 +118,12 @@ class MeteoFranceWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature(self):
|
def native_temperature(self):
|
||||||
"""Return the temperature."""
|
"""Return the temperature."""
|
||||||
return self.coordinator.data.current_forecast["T"]["value"]
|
return self.coordinator.data.current_forecast["T"]["value"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self):
|
def native_pressure(self):
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return TEMP_CELSIUS
|
|
||||||
|
|
||||||
@property
|
|
||||||
def pressure(self):
|
|
||||||
"""Return the pressure."""
|
"""Return the pressure."""
|
||||||
return self.coordinator.data.current_forecast["sea_level"]
|
return self.coordinator.data.current_forecast["sea_level"]
|
||||||
|
|
||||||
@ -127,10 +133,9 @@ class MeteoFranceWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
return self.coordinator.data.current_forecast["humidity"]
|
return self.coordinator.data.current_forecast["humidity"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_speed(self):
|
def native_wind_speed(self):
|
||||||
"""Return the wind speed."""
|
"""Return the wind speed."""
|
||||||
# convert from API m/s to km/h
|
return self.coordinator.data.current_forecast["wind"]["speed"]
|
||||||
return round(self.coordinator.data.current_forecast["wind"]["speed"] * 3.6)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_bearing(self):
|
def wind_bearing(self):
|
||||||
@ -158,9 +163,9 @@ class MeteoFranceWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
ATTR_FORECAST_CONDITION: format_condition(
|
ATTR_FORECAST_CONDITION: format_condition(
|
||||||
forecast["weather"]["desc"]
|
forecast["weather"]["desc"]
|
||||||
),
|
),
|
||||||
ATTR_FORECAST_TEMP: forecast["T"]["value"],
|
ATTR_FORECAST_NATIVE_TEMP: forecast["T"]["value"],
|
||||||
ATTR_FORECAST_PRECIPITATION: forecast["rain"].get("1h"),
|
ATTR_FORECAST_NATIVE_PRECIPITATION: forecast["rain"].get("1h"),
|
||||||
ATTR_FORECAST_WIND_SPEED: forecast["wind"]["speed"],
|
ATTR_FORECAST_NATIVE_WIND_SPEED: forecast["wind"]["speed"],
|
||||||
ATTR_FORECAST_WIND_BEARING: forecast["wind"]["direction"]
|
ATTR_FORECAST_WIND_BEARING: forecast["wind"]["direction"]
|
||||||
if forecast["wind"]["direction"] != -1
|
if forecast["wind"]["direction"] != -1
|
||||||
else None,
|
else None,
|
||||||
@ -179,9 +184,11 @@ class MeteoFranceWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
ATTR_FORECAST_CONDITION: format_condition(
|
ATTR_FORECAST_CONDITION: format_condition(
|
||||||
forecast["weather12H"]["desc"]
|
forecast["weather12H"]["desc"]
|
||||||
),
|
),
|
||||||
ATTR_FORECAST_TEMP: forecast["T"]["max"],
|
ATTR_FORECAST_NATIVE_TEMP: forecast["T"]["max"],
|
||||||
ATTR_FORECAST_TEMP_LOW: forecast["T"]["min"],
|
ATTR_FORECAST_NATIVE_TEMP_LOW: forecast["T"]["min"],
|
||||||
ATTR_FORECAST_PRECIPITATION: forecast["precipitation"]["24h"],
|
ATTR_FORECAST_NATIVE_PRECIPITATION: forecast["precipitation"][
|
||||||
|
"24h"
|
||||||
|
],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return forecast_data
|
return forecast_data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user