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:
1 parent
6b85e23408
commit
f09a9abc1c
19 files changed
+444
No files matched your search
@@ -406,3 +406,48 @@ async def test_invalid_availability_template_keeps_component_available(hass, cap
|
||||
|
||||
assert hass.states.get("lock.template_lock").state != STATE_UNAVAILABLE
|
||||
assert ("UndefinedError: 'x' is undefined") in caplog.text
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
"""Test unique_id option only creates one lock per id."""
|
||||
await setup.async_setup_component(
|
||||
hass,
|
||||
"lock",
|
||||
{
|
||||
"lock": {
|
||||
"platform": "template",
|
||||
"name": "test_template_lock_01",
|
||||
"unique_id": "not-so-unique-anymore",
|
||||
"value_template": "{{ true }}",
|
||||
"lock": {"service": "switch.turn_on", "entity_id": "switch.test_state"},
|
||||
"unlock": {
|
||||
"service": "switch.turn_off",
|
||||
"entity_id": "switch.test_state",
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
await setup.async_setup_component(
|
||||
hass,
|
||||
"lock",
|
||||
{
|
||||
"lock": {
|
||||
"platform": "template",
|
||||
"name": "test_template_lock_02",
|
||||
"unique_id": "not-so-unique-anymore",
|
||||
"value_template": "{{ false }}",
|
||||
"lock": {"service": "switch.turn_on", "entity_id": "switch.test_state"},
|
||||
"unlock": {
|
||||
"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
|
||||
Reference in new issue
Block a user