Add tests for lock component
parent
7d503e3f8b
commit
8841eef2b7
|
@ -36,10 +36,6 @@ DISCOVERY_PLATFORMS = {
|
|||
wink.DISCOVER_LOCKS: 'wink'
|
||||
}
|
||||
|
||||
PROP_TO_ATTR = {
|
||||
'locked': ATTR_LOCKED
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
|
|
@ -5,25 +5,23 @@ homeassistant.components.lock.demo
|
|||
Demo platform that has two fake locks.
|
||||
"""
|
||||
from homeassistant.components.lock import LockDevice
|
||||
from homeassistant.const import (
|
||||
DEVICE_DEFAULT_NAME, STATE_LOCKED, STATE_UNLOCKED)
|
||||
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
""" Find and return demo locks. """
|
||||
add_devices_callback([
|
||||
DemoLock('Left Door', STATE_LOCKED, None),
|
||||
DemoLock('Right Door', STATE_UNLOCKED, None)
|
||||
DemoLock('Front Door', STATE_LOCKED),
|
||||
DemoLock('Kitchen Door', STATE_UNLOCKED)
|
||||
])
|
||||
|
||||
|
||||
class DemoLock(LockDevice):
|
||||
""" Provides a demo lock. """
|
||||
def __init__(self, name, state, icon):
|
||||
self._name = name or DEVICE_DEFAULT_NAME
|
||||
def __init__(self, name, state):
|
||||
self._name = name
|
||||
self._state = state
|
||||
self._icon = icon
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
@ -35,18 +33,10 @@ class DemoLock(LockDevice):
|
|||
""" Returns the name of the device if any. """
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
""" Returns the icon to use for device if any. """
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
""" True if device is locked. """
|
||||
if self._state == STATE_LOCKED:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return self._state == STATE_LOCKED
|
||||
|
||||
def lock(self, **kwargs):
|
||||
""" Lock the device. """
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
"""
|
||||
tests.components.lock.test_demo
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests demo lock component.
|
||||
"""
|
||||
import unittest
|
||||
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.components import lock
|
||||
|
||||
|
||||
FRONT = 'lock.front_door'
|
||||
KITCHEN = 'lock.kitchen_door'
|
||||
|
||||
|
||||
class TestLockDemo(unittest.TestCase):
|
||||
""" Test the demo lock. """
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
self.hass = ha.HomeAssistant()
|
||||
self.assertTrue(lock.setup(self.hass, {
|
||||
'lock': {
|
||||
'platform': 'demo'
|
||||
}
|
||||
}))
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
""" Stop down stuff we started. """
|
||||
self.hass.stop()
|
||||
|
||||
def test_is_locked(self):
|
||||
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):
|
||||
lock.lock(self.hass, KITCHEN)
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertTrue(lock.is_locked(self.hass, KITCHEN))
|
||||
|
||||
def test_unlocking(self):
|
||||
lock.unlock(self.hass, FRONT)
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertFalse(lock.is_locked(self.hass, FRONT))
|
Loading…
Reference in New Issue