Migrate meteoclimatic weather to native_* (#74392)

This commit is contained in:
Erik Montnemery 2022-07-04 13:38:53 +02:00 committed by GitHub
parent b5387ed769
commit ab37f59345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ from meteoclimatic import Condition
from homeassistant.components.weather import WeatherEntity from homeassistant.components.weather import WeatherEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import PRESSURE_HPA, SPEED_KILOMETERS_PER_HOUR, 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
@ -38,6 +38,10 @@ async def async_setup_entry(
class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity): class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity):
"""Representation of a weather condition.""" """Representation of a weather condition."""
_attr_native_pressure_unit = PRESSURE_HPA
_attr_native_temperature_unit = TEMP_CELSIUS
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
def __init__(self, coordinator: DataUpdateCoordinator) -> None: def __init__(self, coordinator: DataUpdateCoordinator) -> None:
"""Initialise the weather platform.""" """Initialise the weather platform."""
super().__init__(coordinator) super().__init__(coordinator)
@ -71,27 +75,22 @@ class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity):
return format_condition(self.coordinator.data["weather"].condition) return format_condition(self.coordinator.data["weather"].condition)
@property @property
def temperature(self): def native_temperature(self):
"""Return the temperature.""" """Return the temperature."""
return self.coordinator.data["weather"].temp_current return self.coordinator.data["weather"].temp_current
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property @property
def humidity(self): def humidity(self):
"""Return the humidity.""" """Return the humidity."""
return self.coordinator.data["weather"].humidity_current return self.coordinator.data["weather"].humidity_current
@property @property
def pressure(self): def native_pressure(self):
"""Return the pressure.""" """Return the pressure."""
return self.coordinator.data["weather"].pressure_current return self.coordinator.data["weather"].pressure_current
@property @property
def wind_speed(self): def native_wind_speed(self):
"""Return the wind speed.""" """Return the wind speed."""
return self.coordinator.data["weather"].wind_current return self.coordinator.data["weather"].wind_current