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
45 changes: 24 additions & 21 deletions homeassistant/components/homekit_controller/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from homeassistant.components.cover import (
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)
from homeassistant.const import (
STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING)
Expand Down Expand Up @@ -137,9 +137,10 @@ def __init__(self, accessory, discovery_info):
self._state = None
self._position = None
self._tilt_position = None
self._hold = None
self._obstruction_detected = None
self.lock_state = None
self._features = (
SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION)

def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about."""
Expand All @@ -157,15 +158,25 @@ def get_characteristic_types(self):
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):
self._state = CURRENT_WINDOW_STATE_MAP[value]

def _update_position_current(self, value):
self._position = value

def _update_position_hold(self, value):
self._hold = value

def _update_vertical_tilt_current(self, value):
self._tilt_position = value

Expand All @@ -175,21 +186,10 @@ def _update_horizontal_tilt_current(self, value):
def _update_obstruction_detected(self, value):
self._obstruction_detected = value

def _update_name(self, value):
self._hold = value

@property
def supported_features(self):
"""Flag supported features."""
supported_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
return self._features

@property
def current_cover_position(self):
Expand All @@ -211,6 +211,13 @@ def is_opening(self):
"""Return if the cover is opening or not."""
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):
"""Send open command."""
await self.async_set_cover_position(position=100)
Expand Down Expand Up @@ -255,8 +262,4 @@ def device_state_attributes(self):
state_attributes['obstruction-detected'] = \
self._obstruction_detected

if self._hold is not None:
state_attributes['hold-position'] = \
self._hold

return state_attributes
12 changes: 12 additions & 0 deletions tests/components/homekit_controller/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
POSITION_STATE = ('window-covering', 'position.state')
POSITION_CURRENT = ('window-covering', 'position.current')
POSITION_TARGET = ('window-covering', 'position.target')
POSITION_HOLD = ('window-covering', 'position.hold')

H_TILT_CURRENT = ('window-covering', 'horizontal-tilt.current')
H_TILT_TARGET = ('window-covering', 'horizontal-tilt.target')
Expand Down Expand Up @@ -166,6 +167,17 @@ async def test_write_window_cover_tilt_vertical(hass, utcnow):
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():
"""Define a garage-door-opener chars as per page 217 of HAP spec."""
service = FakeService('public.hap.service.garage-door-opener')
Expand Down