Only generate device trigger for sensor with unit (#27152)

This commit is contained in:
Erik Montnemery 2019-10-03 22:30:59 +02:00 committed by Paulus Schoutsen
parent cda7692f24
commit 89ebc17fb1
3 changed files with 33 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import homeassistant.components.automation.numeric_state as numeric_state_automa
from homeassistant.components.device_automation import TRIGGER_BASE_SCHEMA
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_UNIT_OF_MEASUREMENT,
CONF_ABOVE,
CONF_BELOW,
CONF_ENTITY_ID,
@ -113,8 +114,14 @@ async def async_get_triggers(hass, device_id):
for entry in entries:
device_class = DEVICE_CLASS_NONE
state = hass.states.get(entry.entity_id)
if state:
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
unit_of_measurement = (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) if state else None
)
if not state or not unit_of_measurement:
continue
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
templates = ENTITY_TRIGGERS.get(
device_class, ENTITY_TRIGGERS[DEVICE_CLASS_NONE]