Refactor and simplify homekit_controller entity setup (#32927)

This commit is contained in:
Jc2k 2020-03-18 15:12:55 +00:00 committed by GitHub
parent e0769f9ad4
commit 7c79adad8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 131 additions and 160 deletions

View file

@ -131,12 +131,6 @@ class HomeKitGarageDoorCover(HomeKitEntity, CoverDevice):
class HomeKitWindowCover(HomeKitEntity, CoverDevice):
"""Representation of a HomeKit Window or Window Covering."""
def __init__(self, accessory, discovery_info):
"""Initialise the Cover."""
super().__init__(accessory, discovery_info)
self._features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about."""
return [
@ -151,23 +145,27 @@ class HomeKitWindowCover(HomeKitEntity, CoverDevice):
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
)
@property
def supported_features(self):
"""Flag supported features."""
return self._features
features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
if self.service.has(CharacteristicsTypes.POSITION_HOLD):
features |= SUPPORT_STOP
supports_tilt = any(
(
self.service.has(CharacteristicsTypes.VERTICAL_TILT_CURRENT),
self.service.has(CharacteristicsTypes.HORIZONTAL_TILT_CURRENT),
)
)
if supports_tilt:
features |= (
SUPPORT_OPEN_TILT | SUPPORT_CLOSE_TILT | SUPPORT_SET_TILT_POSITION
)
return features
@property
def current_cover_position(self):