Migrate open_meteo to native_* (#73910)

This commit is contained in:
Erik Montnemery 2022-06-25 01:05:31 +02:00 committed by GitHub
parent 9b88b77b66
commit a267045a31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,11 @@ from open_meteo import Forecast as OpenMeteoForecast
from homeassistant.components.weather import Forecast, WeatherEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS
from homeassistant.const import (
LENGTH_MILLIMETERS,
SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
@ -33,7 +37,9 @@ class OpenMeteoWeatherEntity(
):
"""Defines an Open-Meteo weather entity."""
_attr_temperature_unit = TEMP_CELSIUS
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
_attr_native_temperature_unit = TEMP_CELSIUS
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
def __init__(
self,
@ -63,14 +69,14 @@ class OpenMeteoWeatherEntity(
)
@property
def temperature(self) -> float | None:
def native_temperature(self) -> float | None:
"""Return the platform temperature."""
if not self.coordinator.data.current_weather:
return None
return self.coordinator.data.current_weather.temperature
@property
def wind_speed(self) -> float | None:
def native_wind_speed(self) -> float | None:
"""Return the wind speed."""
if not self.coordinator.data.current_weather:
return None
@ -103,19 +109,19 @@ class OpenMeteoWeatherEntity(
)
if daily.precipitation_sum is not None:
forecast["precipitation"] = daily.precipitation_sum[index]
forecast["native_precipitation"] = daily.precipitation_sum[index]
if daily.temperature_2m_max is not None:
forecast["temperature"] = daily.temperature_2m_max[index]
forecast["native_temperature"] = daily.temperature_2m_max[index]
if daily.temperature_2m_min is not None:
forecast["templow"] = daily.temperature_2m_min[index]
forecast["native_templow"] = daily.temperature_2m_min[index]
if daily.wind_direction_10m_dominant is not None:
forecast["wind_bearing"] = daily.wind_direction_10m_dominant[index]
if daily.wind_speed_10m_max is not None:
forecast["wind_speed"] = daily.wind_speed_10m_max[index]
forecast["native_wind_speed"] = daily.wind_speed_10m_max[index]
forecasts.append(forecast)