core/tests/components/lock/test_demo.py

51 lines
1.4 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
2016-02-14 23:08:23 +00:00
from tests.common import get_test_home_assistant
2015-11-29 19:44:27 +00:00
FRONT = 'lock.front_door'
KITCHEN = 'lock.kitchen_door'
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
2016-03-09 09:25:50 +00:00
"""Setup things to be run when tests are started."""
2016-02-14 23:08:23 +00:00
self.hass = get_test_home_assistant()
self.assertTrue(setup_component(self.hass, lock.DOMAIN, {
2015-11-29 19:44:27 +00:00
'lock': {
'platform': 'demo'
}
}))
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."""
2015-11-29 19:44:27 +00:00
self.assertTrue(lock.is_locked(self.hass, FRONT))
self.hass.states.is_state(FRONT, 'locked')
self.assertFalse(lock.is_locked(self.hass, KITCHEN))
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."""
2015-11-29 19:44:27 +00:00
lock.lock(self.hass, KITCHEN)
self.hass.block_till_done()
2015-11-29 19:44:27 +00:00
self.assertTrue(lock.is_locked(self.hass, KITCHEN))
def test_unlocking(self):
2016-03-09 09:25:50 +00:00
"""Test the unlocking of a lock."""
2015-11-29 19:44:27 +00:00
lock.unlock(self.hass, FRONT)
self.hass.block_till_done()
2015-11-29 19:44:27 +00:00
self.assertFalse(lock.is_locked(self.hass, FRONT))