1 """Support for displaying weather info from Ecobee API."""
3 from __future__
import annotations
5 from datetime
import timedelta
7 from pyecobee.const
import ECOBEE_STATE_UNKNOWN
10 ATTR_FORECAST_CONDITION,
11 ATTR_FORECAST_NATIVE_TEMP,
12 ATTR_FORECAST_NATIVE_TEMP_LOW,
13 ATTR_FORECAST_NATIVE_WIND_SPEED,
15 ATTR_FORECAST_WIND_BEARING,
35 ECOBEE_WEATHER_SYMBOL_TO_HASS,
42 config_entry: ConfigEntry,
43 async_add_entities: AddEntitiesCallback,
45 """Set up the ecobee weather platform."""
46 data = hass.data[DOMAIN]
48 for index
in range(len(data.ecobee.thermostats)):
49 thermostat = data.ecobee.get_thermostat(index)
50 if "weather" in thermostat:
57 """Representation of Ecobee weather data."""
59 _attr_native_pressure_unit = UnitOfPressure.HPA
60 _attr_native_temperature_unit = UnitOfTemperature.FAHRENHEIT
61 _attr_native_visibility_unit = UnitOfLength.METERS
62 _attr_native_wind_speed_unit = UnitOfSpeed.MILES_PER_HOUR
63 _attr_has_entity_name =
True
65 _attr_supported_features = WeatherEntityFeature.FORECAST_DAILY
68 """Initialize the Ecobee weather platform."""
76 """Retrieve forecast parameter."""
78 forecast = self.
weatherweather[
"forecasts"][index]
79 return forecast[param]
80 except (IndexError, KeyError)
as err:
81 raise ValueError
from err
85 """Return device information for the ecobee weather platform."""
86 thermostat = self.
datadata.ecobee.get_thermostat(self.
_index_index)
89 model = f
"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat"
95 identifiers={(DOMAIN, thermostat[
"identifier"])},
96 manufacturer=MANUFACTURER,
103 """Return the current condition."""
105 return ECOBEE_WEATHER_SYMBOL_TO_HASS[self.
get_forecastget_forecast(0,
"weatherSymbol")]
111 """Return the temperature."""
119 """Return the pressure."""
122 return round(pressure)
128 """Return the humidity."""
136 """Return the visibility."""
144 """Return the wind speed."""
152 """Return the wind direction."""
160 """Return the attribution."""
164 station = self.
weatherweather.
get(
"weatherStation",
"UNKNOWN")
165 time = self.
weatherweather.
get(
"timestamp",
"UNKNOWN")
166 return f
"Ecobee weather provided by {station} at {time} UTC"
169 """Return the forecast array."""
170 if "forecasts" not in self.
weatherweather:
173 forecasts: list[Forecast] = []
174 date = dt_util.utcnow()
179 forecast[ATTR_FORECAST_TIME] = date.isoformat()
181 forecasts.append(forecast)
188 """Return the daily forecast in native units."""
192 """Get the latest weather data."""
194 thermostat = self.
datadata.ecobee.get_thermostat(self.
_index_index)
195 self.
weatherweather = thermostat.get(
"weather")
200 """Process a single ecobee API forecast to return expected values."""
203 forecast[ATTR_FORECAST_CONDITION] = ECOBEE_WEATHER_SYMBOL_TO_HASS[
204 json[
"weatherSymbol"]
206 if json[
"tempHigh"] != ECOBEE_STATE_UNKNOWN:
207 forecast[ATTR_FORECAST_NATIVE_TEMP] =
float(json[
"tempHigh"]) / 10
208 if json[
"tempLow"] != ECOBEE_STATE_UNKNOWN:
209 forecast[ATTR_FORECAST_NATIVE_TEMP_LOW] =
float(json[
"tempLow"]) / 10
210 if json[
"windBearing"] != ECOBEE_STATE_UNKNOWN:
211 forecast[ATTR_FORECAST_WIND_BEARING] =
int(json[
"windBearing"])
212 if json[
"windSpeed"] != ECOBEE_STATE_UNKNOWN:
213 forecast[ATTR_FORECAST_NATIVE_WIND_SPEED] =
int(json[
"windSpeed"])
215 except (ValueError, IndexError, KeyError):
def native_temperature(self)
DeviceInfo device_info(self)
list[Forecast]|None async_forecast_daily(self)
def native_pressure(self)
def get_forecast(self, index, param)
def native_wind_speed(self)
def native_visibility(self)
def __init__(self, data, name, index)
list[Forecast]|None _forecast(self)
None async_update_listeners(self, Iterable[Literal["daily", "hourly", "twice_daily"]]|None forecast_types)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
def _process_forecast(json)
IssData update(pyiss.ISS iss)