hass-core/tests/components/demo/test_lock.py

50 lines
1.3 KiB
Python
Raw Normal View History

2016-03-09 10:25:50 +01:00
"""The tests for the Demo lock platform."""
import pytest
2015-11-29 11:44:27 -08:00
from homeassistant.components import lock
from homeassistant.setup import async_setup_component
2015-11-29 11:44:27 -08:00
from tests.common import async_mock_service
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
@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
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
assert not lock.is_locked(hass, KITCHEN)
assert hass.states.is_state(KITCHEN, "unlocked")
2015-11-29 11:44:27 -08: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
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
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