2016-03-09 10:25:50 +01:00
|
|
|
"""The tests for the Demo lock platform."""
|
2020-04-06 19:09:44 +02:00
|
|
|
import pytest
|
2015-11-29 11:44:27 -08:00
|
|
|
|
|
|
|
from homeassistant.components import lock
|
2020-04-06 19:09:44 +02:00
|
|
|
from homeassistant.setup import async_setup_component
|
2015-11-29 11:44:27 -08:00
|
|
|
|
2020-04-06 19:09:44 +02:00
|
|
|
from tests.common import async_mock_service
|
2018-09-26 18:02:05 +02:00
|
|
|
from tests.components.lock import common
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
FRONT = "lock.front_door"
|
|
|
|
KITCHEN = "lock.kitchen_door"
|
|
|
|
OPENABLE_LOCK = "lock.openable_lock"
|
2015-11-29 11:44:27 -08:00
|
|
|
|
|
|
|
|
2020-04-06 19:09:44 +02:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def setup_comp(hass):
|
|
|
|
"""Set up demo component."""
|
|
|
|
hass.loop.run_until_complete(
|
|
|
|
async_setup_component(hass, lock.DOMAIN, {lock.DOMAIN: {"platform": "demo"}})
|
|
|
|
)
|
2015-11-29 11:44:27 -08:00
|
|
|
|
|
|
|
|
2020-04-06 19:09:44 +02:00
|
|
|
async def test_is_locked(hass):
|
|
|
|
"""Test if lock is locked."""
|
|
|
|
assert lock.is_locked(hass, FRONT)
|
|
|
|
assert hass.states.is_state(FRONT, "locked")
|
2015-11-29 11:44:27 -08:00
|
|
|
|
2020-04-06 19:09:44 +02:00
|
|
|
assert not lock.is_locked(hass, KITCHEN)
|
|
|
|
assert hass.states.is_state(KITCHEN, "unlocked")
|
2015-11-29 11:44:27 -08:00
|
|
|
|
|
|
|
|
2020-04-06 19:09:44 +02:00
|
|
|
async def test_locking(hass):
|
|
|
|
"""Test the locking of a lock."""
|
|
|
|
await common.async_lock(hass, KITCHEN)
|
|
|
|
assert lock.is_locked(hass, KITCHEN)
|
2015-11-29 11:44:27 -08:00
|
|
|
|
|
|
|
|
2020-04-06 19:09:44 +02:00
|
|
|
async def test_unlocking(hass):
|
|
|
|
"""Test the unlocking of a lock."""
|
|
|
|
await common.async_unlock(hass, FRONT)
|
|
|
|
assert not lock.is_locked(hass, FRONT)
|
2015-11-29 11:44:27 -08:00
|
|
|
|
2018-03-25 23:25:28 +02:00
|
|
|
|
2020-04-06 19:09:44 +02:00
|
|
|
async def test_opening(hass):
|
|
|
|
"""Test the opening of a lock."""
|
|
|
|
calls = async_mock_service(hass, lock.DOMAIN, lock.SERVICE_OPEN)
|
|
|
|
await common.async_open_lock(hass, OPENABLE_LOCK)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(calls) == 1
|