mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
homekit_controller: Support cover stop (#23046)
This commit is contained in:
parent
7d4083cdd3
commit
88455a8a8b
@ -3,7 +3,7 @@ import logging
|
|||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION, ATTR_TILT_POSITION, SUPPORT_CLOSE, SUPPORT_CLOSE_TILT,
|
ATTR_POSITION, ATTR_TILT_POSITION, SUPPORT_CLOSE, SUPPORT_CLOSE_TILT,
|
||||||
SUPPORT_OPEN, SUPPORT_OPEN_TILT, SUPPORT_SET_POSITION,
|
SUPPORT_OPEN, SUPPORT_OPEN_TILT, SUPPORT_SET_POSITION, SUPPORT_STOP,
|
||||||
SUPPORT_SET_TILT_POSITION, CoverDevice)
|
SUPPORT_SET_TILT_POSITION, CoverDevice)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING)
|
STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING)
|
||||||
@ -135,9 +135,10 @@ class HomeKitWindowCover(HomeKitEntity, CoverDevice):
|
|||||||
self._state = None
|
self._state = None
|
||||||
self._position = None
|
self._position = None
|
||||||
self._tilt_position = None
|
self._tilt_position = None
|
||||||
self._hold = None
|
|
||||||
self._obstruction_detected = None
|
self._obstruction_detected = None
|
||||||
self.lock_state = None
|
self.lock_state = None
|
||||||
|
self._features = (
|
||||||
|
SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION)
|
||||||
|
|
||||||
def get_characteristic_types(self):
|
def get_characteristic_types(self):
|
||||||
"""Define the homekit characteristics the entity cares about."""
|
"""Define the homekit characteristics the entity cares about."""
|
||||||
@ -155,15 +156,25 @@ class HomeKitWindowCover(HomeKitEntity, CoverDevice):
|
|||||||
CharacteristicsTypes.OBSTRUCTION_DETECTED,
|
CharacteristicsTypes.OBSTRUCTION_DETECTED,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def _setup_position_hold(self, char):
|
||||||
|
self._features |= SUPPORT_STOP
|
||||||
|
|
||||||
|
def _setup_vertical_tilt_current(self, char):
|
||||||
|
self._features |= (
|
||||||
|
SUPPORT_OPEN_TILT | SUPPORT_CLOSE_TILT |
|
||||||
|
SUPPORT_SET_TILT_POSITION)
|
||||||
|
|
||||||
|
def _setup_horizontal_tilt_current(self, char):
|
||||||
|
self._features |= (
|
||||||
|
SUPPORT_OPEN_TILT | SUPPORT_CLOSE_TILT |
|
||||||
|
SUPPORT_SET_TILT_POSITION)
|
||||||
|
|
||||||
def _update_position_state(self, value):
|
def _update_position_state(self, value):
|
||||||
self._state = CURRENT_WINDOW_STATE_MAP[value]
|
self._state = CURRENT_WINDOW_STATE_MAP[value]
|
||||||
|
|
||||||
def _update_position_current(self, value):
|
def _update_position_current(self, value):
|
||||||
self._position = value
|
self._position = value
|
||||||
|
|
||||||
def _update_position_hold(self, value):
|
|
||||||
self._hold = value
|
|
||||||
|
|
||||||
def _update_vertical_tilt_current(self, value):
|
def _update_vertical_tilt_current(self, value):
|
||||||
self._tilt_position = value
|
self._tilt_position = value
|
||||||
|
|
||||||
@ -173,21 +184,10 @@ class HomeKitWindowCover(HomeKitEntity, CoverDevice):
|
|||||||
def _update_obstruction_detected(self, value):
|
def _update_obstruction_detected(self, value):
|
||||||
self._obstruction_detected = value
|
self._obstruction_detected = value
|
||||||
|
|
||||||
def _update_name(self, value):
|
|
||||||
self._hold = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
supported_features = (
|
return self._features
|
||||||
SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION)
|
|
||||||
|
|
||||||
if self._tilt_position is not None:
|
|
||||||
supported_features |= (
|
|
||||||
SUPPORT_OPEN_TILT | SUPPORT_CLOSE_TILT |
|
|
||||||
SUPPORT_SET_TILT_POSITION)
|
|
||||||
|
|
||||||
return supported_features
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_cover_position(self):
|
def current_cover_position(self):
|
||||||
@ -209,6 +209,13 @@ class HomeKitWindowCover(HomeKitEntity, CoverDevice):
|
|||||||
"""Return if the cover is opening or not."""
|
"""Return if the cover is opening or not."""
|
||||||
return self._state == STATE_OPENING
|
return self._state == STATE_OPENING
|
||||||
|
|
||||||
|
async def async_stop_cover(self, **kwargs):
|
||||||
|
"""Send hold command."""
|
||||||
|
characteristics = [{'aid': self._aid,
|
||||||
|
'iid': self._chars['position.hold'],
|
||||||
|
'value': 1}]
|
||||||
|
await self._accessory.put_characteristics(characteristics)
|
||||||
|
|
||||||
async def async_open_cover(self, **kwargs):
|
async def async_open_cover(self, **kwargs):
|
||||||
"""Send open command."""
|
"""Send open command."""
|
||||||
await self.async_set_cover_position(position=100)
|
await self.async_set_cover_position(position=100)
|
||||||
@ -253,8 +260,4 @@ class HomeKitWindowCover(HomeKitEntity, CoverDevice):
|
|||||||
state_attributes['obstruction-detected'] = \
|
state_attributes['obstruction-detected'] = \
|
||||||
self._obstruction_detected
|
self._obstruction_detected
|
||||||
|
|
||||||
if self._hold is not None:
|
|
||||||
state_attributes['hold-position'] = \
|
|
||||||
self._hold
|
|
||||||
|
|
||||||
return state_attributes
|
return state_attributes
|
||||||
|
@ -5,6 +5,7 @@ from tests.components.homekit_controller.common import (
|
|||||||
POSITION_STATE = ('window-covering', 'position.state')
|
POSITION_STATE = ('window-covering', 'position.state')
|
||||||
POSITION_CURRENT = ('window-covering', 'position.current')
|
POSITION_CURRENT = ('window-covering', 'position.current')
|
||||||
POSITION_TARGET = ('window-covering', 'position.target')
|
POSITION_TARGET = ('window-covering', 'position.target')
|
||||||
|
POSITION_HOLD = ('window-covering', 'position.hold')
|
||||||
|
|
||||||
H_TILT_CURRENT = ('window-covering', 'horizontal-tilt.current')
|
H_TILT_CURRENT = ('window-covering', 'horizontal-tilt.current')
|
||||||
H_TILT_TARGET = ('window-covering', 'horizontal-tilt.target')
|
H_TILT_TARGET = ('window-covering', 'horizontal-tilt.target')
|
||||||
@ -166,6 +167,17 @@ async def test_write_window_cover_tilt_vertical(hass, utcnow):
|
|||||||
assert helper.characteristics[V_TILT_TARGET].value == 90
|
assert helper.characteristics[V_TILT_TARGET].value == 90
|
||||||
|
|
||||||
|
|
||||||
|
async def test_window_cover_stop(hass, utcnow):
|
||||||
|
"""Test that vertical tilt is written correctly."""
|
||||||
|
window_cover = create_window_covering_service_with_v_tilt()
|
||||||
|
helper = await setup_test_component(hass, [window_cover])
|
||||||
|
|
||||||
|
await hass.services.async_call('cover', 'stop_cover', {
|
||||||
|
'entity_id': helper.entity_id,
|
||||||
|
}, blocking=True)
|
||||||
|
assert helper.characteristics[POSITION_HOLD].value == 1
|
||||||
|
|
||||||
|
|
||||||
def create_garage_door_opener_service():
|
def create_garage_door_opener_service():
|
||||||
"""Define a garage-door-opener chars as per page 217 of HAP spec."""
|
"""Define a garage-door-opener chars as per page 217 of HAP spec."""
|
||||||
service = FakeService('public.hap.service.garage-door-opener')
|
service = FakeService('public.hap.service.garage-door-opener')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user