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