mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Migrate ecobee to native_* (#74043)
This commit is contained in:
parent
81f74d2053
commit
6e1cd4c48a
@ -7,20 +7,24 @@ from pyecobee.const import ECOBEE_STATE_UNKNOWN
|
|||||||
|
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
ATTR_FORECAST_CONDITION,
|
ATTR_FORECAST_CONDITION,
|
||||||
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 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.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
from homeassistant.util.pressure import convert as pressure_convert
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -49,6 +53,11 @@ async def async_setup_entry(
|
|||||||
class EcobeeWeather(WeatherEntity):
|
class EcobeeWeather(WeatherEntity):
|
||||||
"""Representation of Ecobee weather data."""
|
"""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):
|
def __init__(self, data, name, index):
|
||||||
"""Initialize the Ecobee weather platform."""
|
"""Initialize the Ecobee weather platform."""
|
||||||
self.data = data
|
self.data = data
|
||||||
@ -101,7 +110,7 @@ class EcobeeWeather(WeatherEntity):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature(self):
|
def native_temperature(self):
|
||||||
"""Return the temperature."""
|
"""Return the temperature."""
|
||||||
try:
|
try:
|
||||||
return float(self.get_forecast(0, "temperature")) / 10
|
return float(self.get_forecast(0, "temperature")) / 10
|
||||||
@ -109,18 +118,10 @@ class EcobeeWeather(WeatherEntity):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self):
|
def native_pressure(self):
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return TEMP_FAHRENHEIT
|
|
||||||
|
|
||||||
@property
|
|
||||||
def pressure(self):
|
|
||||||
"""Return the pressure."""
|
"""Return the pressure."""
|
||||||
try:
|
try:
|
||||||
pressure = self.get_forecast(0, "pressure")
|
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)
|
return round(pressure)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
@ -134,15 +135,15 @@ class EcobeeWeather(WeatherEntity):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def visibility(self):
|
def native_visibility(self):
|
||||||
"""Return the visibility."""
|
"""Return the visibility."""
|
||||||
try:
|
try:
|
||||||
return int(self.get_forecast(0, "visibility")) / 1000
|
return int(self.get_forecast(0, "visibility"))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_speed(self):
|
def native_wind_speed(self):
|
||||||
"""Return the wind speed."""
|
"""Return the wind speed."""
|
||||||
try:
|
try:
|
||||||
return int(self.get_forecast(0, "windSpeed"))
|
return int(self.get_forecast(0, "windSpeed"))
|
||||||
@ -202,13 +203,13 @@ def _process_forecast(json):
|
|||||||
json["weatherSymbol"]
|
json["weatherSymbol"]
|
||||||
]
|
]
|
||||||
if json["tempHigh"] != ECOBEE_STATE_UNKNOWN:
|
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:
|
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:
|
if json["windBearing"] != ECOBEE_STATE_UNKNOWN:
|
||||||
forecast[ATTR_FORECAST_WIND_BEARING] = int(json["windBearing"])
|
forecast[ATTR_FORECAST_WIND_BEARING] = int(json["windBearing"])
|
||||||
if json["windSpeed"] != ECOBEE_STATE_UNKNOWN:
|
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):
|
except (ValueError, IndexError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user