Support basic covers with open/close/stop services HomeKit (#13819)

* Support basic covers with open/close/stop services
* Support optional stop
* Tests
This commit is contained in:
Nick Whyte authored and cdce8p committed 2018-04-18 14:39:58 +02:00
1 parent 23b97b9105
commit b589dbf26c
5 files changed
+189 -8

No files matched your search

@@ -154,6 +154,13 @@ class TestGetAccessories(unittest.TestCase):
{ATTR_SUPPORTED_FEATURES: 4})
get_accessory(None, state, 2, {})
def test_cover_open_close(self):
"""Test cover with support for open and close."""
with patch.dict(TYPES, {'WindowCoveringBasic': self.mock_type}):
state = State('cover.open_window', 'open',
{ATTR_SUPPORTED_FEATURES: 3})
get_accessory(None, state, 2, {})
def test_alarm_control_panel(self):
"""Test alarm control panel."""
config = {ATTR_CODE: '1234'}
+113 -4
View File
@@ -3,12 +3,13 @@ import unittest
from homeassistant.core import callback
from homeassistant.components.cover import (
ATTR_POSITION, ATTR_CURRENT_POSITION)
ATTR_POSITION, ATTR_CURRENT_POSITION, SUPPORT_STOP)
from homeassistant.components.homekit.type_covers import (
GarageDoorOpener, WindowCovering)
GarageDoorOpener, WindowCovering, WindowCoveringBasic)
from homeassistant.const import (
STATE_CLOSED, STATE_UNAVAILABLE, STATE_UNKNOWN, STATE_OPEN,
ATTR_SERVICE, ATTR_SERVICE_DATA, EVENT_CALL_SERVICE)
ATTR_SERVICE, ATTR_SERVICE_DATA, EVENT_CALL_SERVICE,
ATTR_SUPPORTED_FEATURES)
from tests.common import get_test_home_assistant
@@ -132,9 +133,117 @@ class TestHomekitSensors(unittest.TestCase):
acc.char_target_position.client_update_value(75)
self.hass.block_till_done()
self.assertEqual(
self.events[0].data[ATTR_SERVICE], 'set_cover_position')
self.events[1].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)
def test_window_open_close(self):
"""Test if accessory and HA are updated accordingly."""
window_cover = 'cover.window'
self.hass.states.set(window_cover, STATE_UNKNOWN,
{ATTR_SUPPORTED_FEATURES: 0})
acc = WindowCoveringBasic(self.hass, 'Cover', window_cover, 2,
config=None)
acc.run()
self.assertEqual(acc.aid, 2)
self.assertEqual(acc.category, 14) # WindowCovering
self.assertEqual(acc.char_current_position.value, 0)
self.assertEqual(acc.char_target_position.value, 0)
self.assertEqual(acc.char_position_state.value, 2)
self.hass.states.set(window_cover, STATE_UNKNOWN)
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, 2)
self.hass.states.set(window_cover, STATE_OPEN)
self.hass.block_till_done()
self.assertEqual(acc.char_current_position.value, 100)
self.assertEqual(acc.char_target_position.value, 100)
self.assertEqual(acc.char_position_state.value, 2)
self.hass.states.set(window_cover, STATE_CLOSED)
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, 2)
# Set from HomeKit
acc.char_target_position.client_update_value(25)
self.hass.block_till_done()
self.assertEqual(
self.events[0].data[ATTR_SERVICE], 'close_cover')
self.assertEqual(acc.char_current_position.value, 0)
self.assertEqual(acc.char_target_position.value, 0)
self.assertEqual(acc.char_position_state.value, 2)
# Set from HomeKit
acc.char_target_position.client_update_value(90)
self.hass.block_till_done()
self.assertEqual(
self.events[1].data[ATTR_SERVICE], 'open_cover')
self.assertEqual(acc.char_current_position.value, 100)
self.assertEqual(acc.char_target_position.value, 100)
self.assertEqual(acc.char_position_state.value, 2)
# Set from HomeKit
acc.char_target_position.client_update_value(55)
self.hass.block_till_done()
self.assertEqual(
self.events[2].data[ATTR_SERVICE], 'open_cover')
self.assertEqual(acc.char_current_position.value, 100)
self.assertEqual(acc.char_target_position.value, 100)
self.assertEqual(acc.char_position_state.value, 2)
def test_window_open_close_stop(self):
"""Test if accessory and HA are updated accordingly."""
window_cover = 'cover.window'
self.hass.states.set(window_cover, STATE_UNKNOWN,
{ATTR_SUPPORTED_FEATURES: SUPPORT_STOP})
acc = WindowCoveringBasic(self.hass, 'Cover', window_cover, 2,
config=None)
acc.run()
# Set from HomeKit
acc.char_target_position.client_update_value(25)
self.hass.block_till_done()
self.assertEqual(
self.events[0].data[ATTR_SERVICE], 'close_cover')
self.assertEqual(acc.char_current_position.value, 0)
self.assertEqual(acc.char_target_position.value, 0)
self.assertEqual(acc.char_position_state.value, 2)
# Set from HomeKit
acc.char_target_position.client_update_value(90)
self.hass.block_till_done()
self.assertEqual(
self.events[1].data[ATTR_SERVICE], 'open_cover')
self.assertEqual(acc.char_current_position.value, 100)
self.assertEqual(acc.char_target_position.value, 100)
self.assertEqual(acc.char_position_state.value, 2)
# Set from HomeKit
acc.char_target_position.client_update_value(55)
self.hass.block_till_done()
self.assertEqual(
self.events[2].data[ATTR_SERVICE], 'stop_cover')
self.assertEqual(acc.char_current_position.value, 50)
self.assertEqual(acc.char_target_position.value, 50)
self.assertEqual(acc.char_position_state.value, 2)