Add optional unique_id attribute to the template platforms (#38011)

* Add unique_id to template platforms

* Update test_binary_sensor.py

* Update test_binary_sensor.py
This commit is contained in:
Michaël Arnauts authored and GitHub committed 2020-08-01 12:45:55 -10:00
1 parent 6b85e23408
commit f09a9abc1c
19 files changed
+444

No files matched your search

+29
View File
@@ -639,3 +639,32 @@ async def test_no_template_match_all(hass, caplog):
assert hass.states.get("sensor.invalid_entity_picture").state == "hello"
assert hass.states.get("sensor.invalid_friendly_name").state == "hello"
assert hass.states.get("sensor.invalid_attribute").state == "hello"
async def test_unique_id(hass):
"""Test unique_id option only creates one sensor per id."""
await async_setup_component(
hass,
"sensor",
{
"sensor": {
"platform": "template",
"sensors": {
"test_template_sensor_01": {
"unique_id": "not-so-unique-anymore",
"value_template": "{{ true }}",
},
"test_template_sensor_02": {
"unique_id": "not-so-unique-anymore",
"value_template": "{{ false }}",
},
},
}
},
)
await hass.async_block_till_done()
await hass.async_start()
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1