Add template support for remaining attributes of weather entity (#47736)
* added template support for remaining attributes of weather entity * wind bearing is now angle (number)
This commit is contained in:
parent
388815b81a
commit
955804bf58
2 changed files with 88 additions and 3 deletions
|
@ -49,8 +49,12 @@ CONF_WEATHER = "weather"
|
|||
CONF_TEMPERATURE_TEMPLATE = "temperature_template"
|
||||
CONF_HUMIDITY_TEMPLATE = "humidity_template"
|
||||
CONF_CONDITION_TEMPLATE = "condition_template"
|
||||
CONF_ATTRIBUTION_TEMPLATE = "attribution_template"
|
||||
CONF_PRESSURE_TEMPLATE = "pressure_template"
|
||||
CONF_WIND_SPEED_TEMPLATE = "wind_speed_template"
|
||||
CONF_WIND_BEARING_TEMPLATE = "wind_bearing_template"
|
||||
CONF_OZONE_TEMPLATE = "ozone_template"
|
||||
CONF_VISIBILITY_TEMPLATE = "visibility_template"
|
||||
CONF_FORECAST_TEMPLATE = "forecast_template"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
@ -59,8 +63,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
vol.Required(CONF_CONDITION_TEMPLATE): cv.template,
|
||||
vol.Required(CONF_TEMPERATURE_TEMPLATE): cv.template,
|
||||
vol.Required(CONF_HUMIDITY_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_ATTRIBUTION_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_PRESSURE_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_WIND_SPEED_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_WIND_BEARING_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_OZONE_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_VISIBILITY_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_FORECAST_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
}
|
||||
|
@ -74,8 +82,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
condition_template = config[CONF_CONDITION_TEMPLATE]
|
||||
temperature_template = config[CONF_TEMPERATURE_TEMPLATE]
|
||||
humidity_template = config[CONF_HUMIDITY_TEMPLATE]
|
||||
attribution_template = config.get(CONF_ATTRIBUTION_TEMPLATE)
|
||||
pressure_template = config.get(CONF_PRESSURE_TEMPLATE)
|
||||
wind_speed_template = config.get(CONF_WIND_SPEED_TEMPLATE)
|
||||
wind_bearing_template = config.get(CONF_WIND_BEARING_TEMPLATE)
|
||||
ozone_template = config.get(CONF_OZONE_TEMPLATE)
|
||||
visibility_template = config.get(CONF_VISIBILITY_TEMPLATE)
|
||||
forecast_template = config.get(CONF_FORECAST_TEMPLATE)
|
||||
unique_id = config.get(CONF_UNIQUE_ID)
|
||||
|
||||
|
@ -87,8 +99,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
condition_template,
|
||||
temperature_template,
|
||||
humidity_template,
|
||||
attribution_template,
|
||||
pressure_template,
|
||||
wind_speed_template,
|
||||
wind_bearing_template,
|
||||
ozone_template,
|
||||
visibility_template,
|
||||
forecast_template,
|
||||
unique_id,
|
||||
)
|
||||
|
@ -106,8 +122,12 @@ class WeatherTemplate(TemplateEntity, WeatherEntity):
|
|||
condition_template,
|
||||
temperature_template,
|
||||
humidity_template,
|
||||
attribution_template,
|
||||
pressure_template,
|
||||
wind_speed_template,
|
||||
wind_bearing_template,
|
||||
ozone_template,
|
||||
visibility_template,
|
||||
forecast_template,
|
||||
unique_id,
|
||||
):
|
||||
|
@ -118,8 +138,12 @@ class WeatherTemplate(TemplateEntity, WeatherEntity):
|
|||
self._condition_template = condition_template
|
||||
self._temperature_template = temperature_template
|
||||
self._humidity_template = humidity_template
|
||||
self._attribution_template = attribution_template
|
||||
self._pressure_template = pressure_template
|
||||
self._wind_speed_template = wind_speed_template
|
||||
self._wind_bearing_template = wind_bearing_template
|
||||
self._ozone_template = ozone_template
|
||||
self._visibility_template = visibility_template
|
||||
self._forecast_template = forecast_template
|
||||
self._unique_id = unique_id
|
||||
|
||||
|
@ -128,8 +152,12 @@ class WeatherTemplate(TemplateEntity, WeatherEntity):
|
|||
self._condition = None
|
||||
self._temperature = None
|
||||
self._humidity = None
|
||||
self._attribution = None
|
||||
self._pressure = None
|
||||
self._wind_speed = None
|
||||
self._wind_bearing = None
|
||||
self._ozone = None
|
||||
self._visibility = None
|
||||
self._forecast = []
|
||||
|
||||
@property
|
||||
|
@ -162,9 +190,24 @@ class WeatherTemplate(TemplateEntity, WeatherEntity):
|
|||
"""Return the wind speed."""
|
||||
return self._wind_speed
|
||||
|
||||
@property
|
||||
def wind_bearing(self):
|
||||
"""Return the wind bearing."""
|
||||
return self._wind_bearing
|
||||
|
||||
@property
|
||||
def ozone(self):
|
||||
"""Return the ozone level."""
|
||||
return self._ozone
|
||||
|
||||
@property
|
||||
def visibility(self):
|
||||
"""Return the visibility."""
|
||||
return self._visibility
|
||||
|
||||
@property
|
||||
def pressure(self):
|
||||
"""Return the pressure."""
|
||||
"""Return the air pressure."""
|
||||
return self._pressure
|
||||
|
||||
@property
|
||||
|
@ -175,11 +218,13 @@ class WeatherTemplate(TemplateEntity, WeatherEntity):
|
|||
@property
|
||||
def attribution(self):
|
||||
"""Return the attribution."""
|
||||
return "Powered by Home Assistant"
|
||||
if self._attribution is None:
|
||||
return "Powered by Home Assistant"
|
||||
return self._attribution
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique id of this light."""
|
||||
"""Return the unique id of this weather instance."""
|
||||
return self._unique_id
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
|
@ -201,6 +246,11 @@ class WeatherTemplate(TemplateEntity, WeatherEntity):
|
|||
"_humidity",
|
||||
self._humidity_template,
|
||||
)
|
||||
if self._attribution_template:
|
||||
self.add_template_attribute(
|
||||
"_attribution",
|
||||
self._attribution_template,
|
||||
)
|
||||
if self._pressure_template:
|
||||
self.add_template_attribute(
|
||||
"_pressure",
|
||||
|
@ -211,6 +261,21 @@ class WeatherTemplate(TemplateEntity, WeatherEntity):
|
|||
"_wind_speed",
|
||||
self._wind_speed_template,
|
||||
)
|
||||
if self._wind_bearing_template:
|
||||
self.add_template_attribute(
|
||||
"_wind_bearing",
|
||||
self._wind_bearing_template,
|
||||
)
|
||||
if self._ozone_template:
|
||||
self.add_template_attribute(
|
||||
"_ozone",
|
||||
self._ozone_template,
|
||||
)
|
||||
if self._visibility_template:
|
||||
self.add_template_attribute(
|
||||
"_visibility",
|
||||
self._visibility_template,
|
||||
)
|
||||
if self._forecast_template:
|
||||
self.add_template_attribute(
|
||||
"_forecast",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue