Add support for HomeKit (#12488)
* Basic Homekit support * Added Temperatur Sensor * Added Window Cover * Code refactored * Added class HomeAccessory(Accessory) * Added class HomeBridge(Bridge) * Changed homekit imports to relative, to enable use in custom_components * Updated requirements * Added docs * Other smaller changes * Changed Homekit from entity to class * Changes based on feedback * Updated config schema * Add only covers that support set_cover_position * Addressed comments, updated to pyhap==1.1.5 * For lint: added files to gen_requirements_all * Added codeowner * Small change to Wrapper classes * Moved imports to import_types, small changes * Small changes, added tests * Homekit class: removed add_accessory since it's already covered by pyhap * Added test requirement: HAP-python * Added test suit for homekit setup and interaction between HA and pyhap * Added test suit for get_accessories function * Test bugfix * Added validate pincode, tests for cover and sensor types
This commit is contained in:
1 parent
dc21c61a44
commit
eec3bad94f
14 files changed
+642
No files matched your search
@@ -0,0 +1,83 @@
|
||||
"""Test different accessory types: Covers."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_POSITION, ATTR_CURRENT_POSITION)
|
||||
from homeassistant.components.homekit.covers import Window
|
||||
from homeassistant.const import (
|
||||
STATE_UNKNOWN, STATE_OPEN,
|
||||
ATTR_SERVICE, ATTR_SERVICE_DATA, EVENT_CALL_SERVICE)
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestHomekitSensors(unittest.TestCase):
|
||||
"""Test class for all accessory types regarding covers."""
|
||||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.events = []
|
||||
|
||||
@callback
|
||||
def record_event(event):
|
||||
"""Track called event."""
|
||||
self.events.append(event)
|
||||
|
||||
self.hass.bus.listen(EVENT_CALL_SERVICE, record_event)
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop down everthing that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_window_set_cover_position(self):
|
||||
"""Test if accessory and HA are updated accordingly."""
|
||||
window_cover = 'cover.window'
|
||||
|
||||
acc = Window(self.hass, window_cover, 'Cover')
|
||||
acc.run()
|
||||
|
||||
self.assertEqual(acc.char_current_position.value, 0)
|
||||
self.assertEqual(acc.char_target_position.value, 0)
|
||||
self.assertEqual(acc.char_position_state.value, 0)
|
||||
|
||||
self.hass.states.set(window_cover, STATE_UNKNOWN,
|
||||
{ATTR_CURRENT_POSITION: None})
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(acc.char_current_position.value, 0)
|
||||
self.assertEqual(acc.char_target_position.value, 0)
|
||||
self.assertEqual(acc.char_position_state.value, 0)
|
||||
|
||||
self.hass.states.set(window_cover, STATE_OPEN,
|
||||
{ATTR_CURRENT_POSITION: 50})
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(acc.char_current_position.value, 50)
|
||||
self.assertEqual(acc.char_target_position.value, 50)
|
||||
self.assertEqual(acc.char_position_state.value, 2)
|
||||
|
||||
# Set from HomeKit
|
||||
acc.char_target_position.set_value(25)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(
|
||||
self.events[0].data[ATTR_SERVICE], 'set_cover_position')
|
||||
self.assertEqual(
|
||||
self.events[0].data[ATTR_SERVICE_DATA][ATTR_POSITION], 25)
|
||||
|
||||
self.assertEqual(acc.char_current_position.value, 50)
|
||||
self.assertEqual(acc.char_target_position.value, 25)
|
||||
self.assertEqual(acc.char_position_state.value, 0)
|
||||
|
||||
# Set from HomeKit
|
||||
acc.char_target_position.set_value(75)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(
|
||||
self.events[0].data[ATTR_SERVICE], 'set_cover_position')
|
||||
self.assertEqual(
|
||||
self.events[1].data[ATTR_SERVICE_DATA][ATTR_POSITION], 75)
|
||||
|
||||
self.assertEqual(acc.char_current_position.value, 50)
|
||||
self.assertEqual(acc.char_target_position.value, 75)
|
||||
self.assertEqual(acc.char_position_state.value, 1)
|
||||
Reference in new issue
Block a user