1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Update template lock to support locking, unlocking, jammed (#52817)

This commit is contained in:
J. Nick Koston
2021-07-20 18:50:21 -10:00
committed by GitHub
parent 5d85983b09
commit ee242764a1
2 changed files with 106 additions and 5 deletions

View File

@@ -325,6 +325,84 @@ async def test_unlock_action(hass, calls):
assert len(calls) == 1
async def test_unlocking(hass, calls):
"""Test unlocking."""
assert await setup.async_setup_component(
hass,
lock.DOMAIN,
{
"lock": {
"platform": "template",
"value_template": "{{ states.input_select.test_state.state }}",
"lock": {"service": "test.automation"},
"unlock": {"service": "test.automation"},
}
},
)
await hass.async_block_till_done()
await hass.async_start()
await hass.async_block_till_done()
hass.states.async_set("input_select.test_state", lock.STATE_UNLOCKING)
await hass.async_block_till_done()
state = hass.states.get("lock.template_lock")
assert state.state == lock.STATE_UNLOCKING
async def test_locking(hass, calls):
"""Test unlocking."""
assert await setup.async_setup_component(
hass,
lock.DOMAIN,
{
"lock": {
"platform": "template",
"value_template": "{{ states.input_select.test_state.state }}",
"lock": {"service": "test.automation"},
"unlock": {"service": "test.automation"},
}
},
)
await hass.async_block_till_done()
await hass.async_start()
await hass.async_block_till_done()
hass.states.async_set("input_select.test_state", lock.STATE_LOCKING)
await hass.async_block_till_done()
state = hass.states.get("lock.template_lock")
assert state.state == lock.STATE_LOCKING
async def test_jammed(hass, calls):
"""Test jammed."""
assert await setup.async_setup_component(
hass,
lock.DOMAIN,
{
"lock": {
"platform": "template",
"value_template": "{{ states.input_select.test_state.state }}",
"lock": {"service": "test.automation"},
"unlock": {"service": "test.automation"},
}
},
)
await hass.async_block_till_done()
await hass.async_start()
await hass.async_block_till_done()
hass.states.async_set("input_select.test_state", lock.STATE_JAMMED)
await hass.async_block_till_done()
state = hass.states.get("lock.template_lock")
assert state.state == lock.STATE_JAMMED
async def test_available_template_with_entities(hass):
"""Test availability templates with values from other entities."""