Fix trigger template entities without a unique ID (#48631)

This commit is contained in:
Paulus Schoutsen 2021-04-02 10:24:38 -07:00 committed by GitHub
parent bdbb4f939f
commit 212d9aa748
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import voluptuous as vol
from homeassistant.components.sensor import (
DEVICE_CLASSES_SCHEMA,
DOMAIN as SENSOR_DOMAIN,
ENTITY_ID_FORMAT,
PLATFORM_SCHEMA,
SensorEntity,
@ -201,6 +202,7 @@ class SensorTemplate(TemplateEntity, SensorEntity):
class TriggerSensorEntity(TriggerEntity, SensorEntity):
"""Sensor entity based on trigger data."""
domain = SENSOR_DOMAIN
extra_template_keys = (CONF_VALUE_TEMPLATE,)
@property

View File

@ -1014,7 +1014,15 @@ async def test_trigger_entity(hass):
"attribute_templates": {
"plus_one": "{{ trigger.event.data.beer + 1 }}"
},
}
},
},
},
{
"trigger": [],
"sensors": {
"bare_minimum": {
"value_template": "{{ trigger.event.data.beer }}"
},
},
},
],
@ -1027,6 +1035,10 @@ async def test_trigger_entity(hass):
assert state is not None
assert state.state == STATE_UNKNOWN
state = hass.states.get("sensor.bare_minimum")
assert state is not None
assert state.state == STATE_UNKNOWN
context = Context()
hass.bus.async_fire("test_event", {"beer": 2}, context=context)
await hass.async_block_till_done()