Skip to content

Commit

Permalink
Migrate open_meteo to native_* (home-assistant#73910)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Jun 24, 2022
1 parent 9b88b77 commit a267045
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions homeassistant/components/open_meteo/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -63,14 +69,14 @@ def condition(self) -> str | None:
)

@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
Expand Down Expand Up @@ -103,19 +109,19 @@ def forecast(self) -> list[Forecast] | None:
)

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)

Expand Down

0 comments on commit a267045

Please sign in to comment.