Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/homekit/type_covers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ATTR_SUPPORTED_FEATURES)

from . import TYPES
from .accessories import HomeAccessory
from .accessories import HomeAccessory, debounce
from .const import (
SERV_WINDOW_COVERING, CHAR_CURRENT_POSITION,
CHAR_TARGET_POSITION, CHAR_POSITION_STATE,
Expand Down Expand Up @@ -80,6 +80,7 @@ def __init__(self, *args, config):
self.char_target_position = serv_cover.configure_char(
CHAR_TARGET_POSITION, value=0, setter_callback=self.move_cover)

@debounce
def move_cover(self, value):
"""Move cover to value if call came from HomeKit."""
_LOGGER.debug('%s: Set position to %d', self.entity_id, value)
Expand Down Expand Up @@ -122,6 +123,7 @@ def __init__(self, *args, config):
self.char_position_state = serv_cover.configure_char(
CHAR_POSITION_STATE, value=2)

@debounce
def move_cover(self, value):
"""Move cover to value if call came from HomeKit."""
_LOGGER.debug('%s: Set position to %d', self.entity_id, value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def update_state(self, new_state):
_LOGGER.debug('%s: Updated current state to %s (%d)',
self.entity_id, hass_state, current_security_state)

# SecuritySystemTargetSTate does not support triggered
# SecuritySystemTargetState does not support triggered
if not self.flag_target_state and \
hass_state != STATE_ALARM_TRIGGERED:
self.char_target_state.set_value(current_security_state)
Expand Down
34 changes: 25 additions & 9 deletions tests/components/homekit/test_type_covers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@
from homeassistant.core import callback
from homeassistant.components.cover import (
ATTR_POSITION, ATTR_CURRENT_POSITION, SUPPORT_STOP)
from homeassistant.components.homekit.type_covers import (
GarageDoorOpener, WindowCovering, WindowCoveringBasic)
from homeassistant.const import (
STATE_CLOSED, STATE_UNAVAILABLE, STATE_UNKNOWN, STATE_OPEN,
ATTR_SERVICE, ATTR_SERVICE_DATA, EVENT_CALL_SERVICE,
ATTR_SUPPORTED_FEATURES)

from tests.common import get_test_home_assistant
from tests.components.homekit.test_accessories import patch_debounce


class TestHomekitSensors(unittest.TestCase):
class TestHomekitCovers(unittest.TestCase):
"""Test class for all accessory types regarding covers."""

@classmethod
def setUpClass(cls):
"""Setup Light class import and debounce patcher."""
cls.patcher = patch_debounce()
cls.patcher.start()
_import = __import__('homeassistant.components.homekit.type_covers',
fromlist=['GarageDoorOpener', 'WindowCovering,',
'WindowCoveringBasic'])
cls.garage_cls = _import.GarageDoorOpener
cls.window_cls = _import.WindowCovering
cls.window_basic_cls = _import.WindowCoveringBasic

@classmethod
def tearDownClass(cls):
"""Stop debounce patcher."""
cls.patcher.stop()

def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
Expand All @@ -37,7 +53,7 @@ def test_garage_door_open_close(self):
"""Test if accessory and HA are updated accordingly."""
garage_door = 'cover.garage_door'

acc = GarageDoorOpener(self.hass, 'Cover', garage_door, 2, config=None)
acc = self.garage_cls(self.hass, 'Cover', garage_door, 2, config=None)
acc.run()

self.assertEqual(acc.aid, 2)
Expand Down Expand Up @@ -95,7 +111,7 @@ def test_window_set_cover_position(self):
"""Test if accessory and HA are updated accordingly."""
window_cover = 'cover.window'

acc = WindowCovering(self.hass, 'Cover', window_cover, 2, config=None)
acc = self.window_cls(self.hass, 'Cover', window_cover, 2, config=None)
acc.run()

self.assertEqual(acc.aid, 2)
Expand Down Expand Up @@ -146,8 +162,8 @@ def test_window_open_close(self):

self.hass.states.set(window_cover, STATE_UNKNOWN,
{ATTR_SUPPORTED_FEATURES: 0})
acc = WindowCoveringBasic(self.hass, 'Cover', window_cover, 2,
config=None)
acc = self.window_basic_cls(self.hass, 'Cover', window_cover, 2,
config=None)
acc.run()

self.assertEqual(acc.aid, 2)
Expand Down Expand Up @@ -214,8 +230,8 @@ def test_window_open_close_stop(self):

self.hass.states.set(window_cover, STATE_UNKNOWN,
{ATTR_SUPPORTED_FEATURES: SUPPORT_STOP})
acc = WindowCoveringBasic(self.hass, 'Cover', window_cover, 2,
config=None)
acc = self.window_basic_cls(self.hass, 'Cover', window_cover, 2,
config=None)
acc.run()

# Set from HomeKit
Expand Down