core/tests/components/demo/test_lock.py

59 lines
1.8 KiB
Python
Raw Normal View History

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.setup import setup_component
2015-11-29 19:44:27 +00:00
from homeassistant.components import lock
from tests.common import get_test_home_assistant, mock_service
from tests.components.lock import common
2015-11-29 19:44:27 +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()
assert setup_component(self.hass, lock.DOMAIN, {
2015-11-29 19:44:27 +00:00
'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."""
assert lock.is_locked(self.hass, FRONT)
2015-11-29 19:44:27 +00:00
self.hass.states.is_state(FRONT, 'locked')
assert not lock.is_locked(self.hass, KITCHEN)
2015-11-29 19:44:27 +00:00
self.hass.states.is_state(KITCHEN, 'unlocked')
def test_locking(self):
2016-03-09 09:25:50 +00:00
"""Test the locking of a lock."""
common.lock(self.hass, KITCHEN)
self.hass.block_till_done()
2015-11-29 19:44:27 +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."""
common.unlock(self.hass, FRONT)
self.hass.block_till_done()
2015-11-29 19:44:27 +00:00
assert not lock.is_locked(self.hass, FRONT)
def test_opening(self):
"""Test the opening of a lock."""
calls = mock_service(self.hass, lock.DOMAIN, lock.SERVICE_OPEN)
common.open_lock(self.hass, OPENABLE_LOCK)
self.hass.block_till_done()
assert 1 == len(calls)