2016-03-09 09:25:50 +00:00
|
|
|
"""The tests for the Demo lock platform."""
|
2015-11-29 19:44:27 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from homeassistant.components import lock
|
2019-12-08 16:59:27 +00:00
|
|
|
from homeassistant.setup import setup_component
|
2015-11-29 19:44:27 +00:00
|
|
|
|
2018-03-25 21:25:28 +00:00
|
|
|
from tests.common import get_test_home_assistant, mock_service
|
2018-09-26 16:02:05 +00:00
|
|
|
from tests.components.lock import common
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
FRONT = "lock.front_door"
|
|
|
|
KITCHEN = "lock.kitchen_door"
|
|
|
|
OPENABLE_LOCK = "lock.openable_lock"
|
2015-11-29 19:44:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestLockDemo(unittest.TestCase):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the demo lock."""
|
2015-11-29 19:44:27 +00:00
|
|
|
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
2016-02-14 23:08:23 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(self.hass, lock.DOMAIN, {"lock": {"platform": "demo"}})
|
2015-11-29 19:44:27 +00:00
|
|
|
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Stop everything that was started."""
|
2015-11-29 19:44:27 +00:00
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
def test_is_locked(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test if lock is locked."""
|
2018-10-24 10:10:05 +00:00
|
|
|
assert lock.is_locked(self.hass, FRONT)
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.is_state(FRONT, "locked")
|
2015-11-29 19:44:27 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert not lock.is_locked(self.hass, KITCHEN)
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.is_state(KITCHEN, "unlocked")
|
2015-11-29 19:44:27 +00:00
|
|
|
|
|
|
|
def test_locking(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the locking of a lock."""
|
2018-09-26 16:02:05 +00:00
|
|
|
common.lock(self.hass, KITCHEN)
|
2016-09-13 02:16:14 +00:00
|
|
|
self.hass.block_till_done()
|
2015-11-29 19:44:27 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert lock.is_locked(self.hass, KITCHEN)
|
2015-11-29 19:44:27 +00:00
|
|
|
|
|
|
|
def test_unlocking(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the unlocking of a lock."""
|
2018-09-26 16:02:05 +00:00
|
|
|
common.unlock(self.hass, FRONT)
|
2016-09-13 02:16:14 +00:00
|
|
|
self.hass.block_till_done()
|
2015-11-29 19:44:27 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert not lock.is_locked(self.hass, FRONT)
|
2018-03-25 21:25:28 +00:00
|
|
|
|
|
|
|
def test_opening(self):
|
|
|
|
"""Test the opening of a lock."""
|
|
|
|
calls = mock_service(self.hass, lock.DOMAIN, lock.SERVICE_OPEN)
|
2018-09-26 16:02:05 +00:00
|
|
|
common.open_lock(self.hass, OPENABLE_LOCK)
|
2018-03-25 21:25:28 +00:00
|
|
|
self.hass.block_till_done()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert 1 == len(calls)
|