Migrate ecobee to native_* (#74043)
parent
02452c7632
commit
8259ce9868
|
@ -7,20 +7,24 @@ from pyecobee.const import ECOBEE_STATE_UNKNOWN
|
|||
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_FORECAST_CONDITION,
|
||||
ATTR_FORECAST_TEMP,
|
||||
ATTR_FORECAST_TEMP_LOW,
|
||||
ATTR_FORECAST_NATIVE_TEMP,
|
||||
ATTR_FORECAST_NATIVE_TEMP_LOW,
|
||||
ATTR_FORECAST_NATIVE_WIND_SPEED,
|
||||
ATTR_FORECAST_TIME,
|
||||
ATTR_FORECAST_WIND_BEARING,
|
||||
ATTR_FORECAST_WIND_SPEED,
|
||||
WeatherEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PRESSURE_HPA, PRESSURE_INHG, TEMP_FAHRENHEIT
|
||||
from homeassistant.const import (
|
||||
LENGTH_METERS,
|
||||
PRESSURE_HPA,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.pressure import convert as pressure_convert
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
|
@ -49,6 +53,11 @@ async def async_setup_entry(
|
|||
class EcobeeWeather(WeatherEntity):
|
||||
"""Representation of Ecobee weather data."""
|
||||
|
||||
_attr_native_pressure_unit = PRESSURE_HPA
|
||||
_attr_native_temperature_unit = TEMP_FAHRENHEIT
|
||||
_attr_native_visibility_unit = LENGTH_METERS
|
||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
||||
|
||||
def __init__(self, data, name, index):
|
||||
"""Initialize the Ecobee weather platform."""
|
||||
self.data = data
|
||||
|
@ -101,7 +110,7 @@ class EcobeeWeather(WeatherEntity):
|
|||
return None
|
||||
|
||||
@property
|
||||
def temperature(self):
|
||||
def native_temperature(self):
|
||||
"""Return the temperature."""
|
||||
try:
|
||||
return float(self.get_forecast(0, "temperature")) / 10
|
||||
|
@ -109,18 +118,10 @@ class EcobeeWeather(WeatherEntity):
|
|||
return None
|
||||
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
"""Return the unit of measurement."""
|
||||
return TEMP_FAHRENHEIT
|
||||
|
||||
@property
|
||||
def pressure(self):
|
||||
def native_pressure(self):
|
||||
"""Return the pressure."""
|
||||
try:
|
||||
pressure = self.get_forecast(0, "pressure")
|
||||
if not self.hass.config.units.is_metric:
|
||||
pressure = pressure_convert(pressure, PRESSURE_HPA, PRESSURE_INHG)
|
||||
return round(pressure, 2)
|
||||
return round(pressure)
|
||||
except ValueError:
|
||||
return None
|
||||
|
@ -134,15 +135,15 @@ class EcobeeWeather(WeatherEntity):
|
|||
return None
|
||||
|
||||
@property
|
||||
def visibility(self):
|
||||
def native_visibility(self):
|
||||
"""Return the visibility."""
|
||||
try:
|
||||
return int(self.get_forecast(0, "visibility")) / 1000
|
||||
return int(self.get_forecast(0, "visibility"))
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
@property
|
||||
def wind_speed(self):
|
||||
def native_wind_speed(self):
|
||||
"""Return the wind speed."""
|
||||
try:
|
||||
return int(self.get_forecast(0, "windSpeed"))
|
||||
|
@ -202,13 +203,13 @@ def _process_forecast(json):
|
|||
json["weatherSymbol"]
|
||||
]
|
||||
if json["tempHigh"] != ECOBEE_STATE_UNKNOWN:
|
||||
forecast[ATTR_FORECAST_TEMP] = float(json["tempHigh"]) / 10
|
||||
forecast[ATTR_FORECAST_NATIVE_TEMP] = float(json["tempHigh"]) / 10
|
||||
if json["tempLow"] != ECOBEE_STATE_UNKNOWN:
|
||||
forecast[ATTR_FORECAST_TEMP_LOW] = float(json["tempLow"]) / 10
|
||||
forecast[ATTR_FORECAST_NATIVE_TEMP_LOW] = float(json["tempLow"]) / 10
|
||||
if json["windBearing"] != ECOBEE_STATE_UNKNOWN:
|
||||
forecast[ATTR_FORECAST_WIND_BEARING] = int(json["windBearing"])
|
||||
if json["windSpeed"] != ECOBEE_STATE_UNKNOWN:
|
||||
forecast[ATTR_FORECAST_WIND_SPEED] = int(json["windSpeed"])
|
||||
forecast[ATTR_FORECAST_NATIVE_WIND_SPEED] = int(json["windSpeed"])
|
||||
|
||||
except (ValueError, IndexError, KeyError):
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue