mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00
Add debounce to move_cover (#14314)
* Add debounce to move_cover * Fix spelling mistake
This commit is contained in:
parent
34727be5ac
commit
91fe6e4e56
@ -11,7 +11,7 @@ from homeassistant.const import (
|
||||
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,
|
||||
@ -80,6 +80,7 @@ class WindowCovering(HomeAccessory):
|
||||
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)
|
||||
@ -122,6 +123,7 @@ class WindowCoveringBasic(HomeAccessory):
|
||||
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)
|
||||
|
@ -67,7 +67,7 @@ class SecuritySystem(HomeAccessory):
|
||||
_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)
|
||||
|
@ -4,19 +4,35 @@ import unittest
|
||||
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()
|
||||
@ -37,7 +53,7 @@ class TestHomekitSensors(unittest.TestCase):
|
||||
"""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)
|
||||
@ -95,7 +111,7 @@ class TestHomekitSensors(unittest.TestCase):
|
||||
"""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)
|
||||
@ -146,8 +162,8 @@ class TestHomekitSensors(unittest.TestCase):
|
||||
|
||||
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)
|
||||
@ -214,8 +230,8 @@ class TestHomekitSensors(unittest.TestCase):
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user