Include unit_of_measurement in sensor device trigger capabilities (#27265)
* Expose unit_of_measurement in sensor device trigger * Update test
This commit is contained in:
1 parent
071476343c
commit
7f20210e93
2 files changed
+41
-6
No files matched your search
@@ -11,6 +11,7 @@ from homeassistant.const import (
|
||||
CONF_ENTITY_ID,
|
||||
CONF_FOR,
|
||||
CONF_TYPE,
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
@@ -149,11 +150,22 @@ async def async_get_triggers(hass, device_id):
|
||||
|
||||
async def async_get_trigger_capabilities(hass, config):
|
||||
"""List trigger capabilities."""
|
||||
state = hass.states.get(config[CONF_ENTITY_ID])
|
||||
unit_of_measurement = (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) if state else ""
|
||||
)
|
||||
|
||||
return {
|
||||
"extra_fields": vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_ABOVE): vol.Coerce(float),
|
||||
vol.Optional(CONF_BELOW): vol.Coerce(float),
|
||||
vol.Optional(
|
||||
CONF_ABOVE,
|
||||
description={CONF_UNIT_OF_MEASUREMENT: unit_of_measurement},
|
||||
): vol.Coerce(float),
|
||||
vol.Optional(
|
||||
CONF_BELOW,
|
||||
description={CONF_UNIT_OF_MEASUREMENT: unit_of_measurement},
|
||||
): vol.Coerce(float),
|
||||
vol.Optional(CONF_FOR): cv.positive_time_period_dict,
|
||||
}
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user