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

+45
View File
@@ -650,3 +650,48 @@ async def test_invalid_availability_template_keeps_component_available(hass, cap
assert hass.states.get("switch.test_template_switch").state != STATE_UNAVAILABLE
assert ("UndefinedError: 'x' is undefined") in caplog.text
async def test_unique_id(hass):
"""Test unique_id option only creates one switch per id."""
await setup.async_setup_component(
hass,
"switch",
{
"switch": {
"platform": "template",
"switches": {
"test_template_switch_01": {
"unique_id": "not-so-unique-anymore",
"value_template": "{{ true }}",
"turn_on": {
"service": "switch.turn_on",
"entity_id": "switch.test_state",
},
"turn_off": {
"service": "switch.turn_off",
"entity_id": "switch.test_state",
},
},
"test_template_switch_02": {
"unique_id": "not-so-unique-anymore",
"value_template": "{{ false }}",
"turn_on": {
"service": "switch.turn_on",
"entity_id": "switch.test_state",
},
"turn_off": {
"service": "switch.turn_off",
"entity_id": "switch.test_state",
},
},
},
}
},
)
await hass.async_block_till_done()
await hass.async_start()
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1