Better handling of HomeKit accessory-information service (#22171)
* HomeKit controller: Better handling of accessory-information service * Changes from review
This commit is contained in:
parent
6cb8806085
commit
0344c761fc
3 changed files with 10 additions and 20 deletions
|
@ -9,6 +9,7 @@ from homeassistant.helpers import discovery
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.event import call_later
|
from homeassistant.helpers.event import call_later
|
||||||
|
|
||||||
|
from .connection import get_accessory_information
|
||||||
from .const import (
|
from .const import (
|
||||||
CONTROLLER, DOMAIN, HOMEKIT_ACCESSORY_DISPATCH, KNOWN_ACCESSORIES,
|
CONTROLLER, DOMAIN, HOMEKIT_ACCESSORY_DISPATCH, KNOWN_ACCESSORIES,
|
||||||
KNOWN_DEVICES
|
KNOWN_DEVICES
|
||||||
|
@ -204,11 +205,9 @@ class HomeKitEntity(Entity):
|
||||||
def __init__(self, accessory, devinfo):
|
def __init__(self, accessory, devinfo):
|
||||||
"""Initialise a generic HomeKit device."""
|
"""Initialise a generic HomeKit device."""
|
||||||
self._available = True
|
self._available = True
|
||||||
self._name = accessory.model
|
|
||||||
self._accessory = accessory
|
self._accessory = accessory
|
||||||
self._aid = devinfo['aid']
|
self._aid = devinfo['aid']
|
||||||
self._iid = devinfo['iid']
|
self._iid = devinfo['iid']
|
||||||
self._address = "homekit-{}-{}".format(devinfo['serial'], self._iid)
|
|
||||||
self._features = 0
|
self._features = 0
|
||||||
self._chars = {}
|
self._chars = {}
|
||||||
self.setup()
|
self.setup()
|
||||||
|
@ -232,6 +231,7 @@ class HomeKitEntity(Entity):
|
||||||
for accessory in pairing_data.get('accessories', []):
|
for accessory in pairing_data.get('accessories', []):
|
||||||
if accessory['aid'] != self._aid:
|
if accessory['aid'] != self._aid:
|
||||||
continue
|
continue
|
||||||
|
self._accessory_info = get_accessory_information(accessory)
|
||||||
for service in accessory['services']:
|
for service in accessory['services']:
|
||||||
if service['iid'] != self._iid:
|
if service['iid'] != self._iid:
|
||||||
continue
|
continue
|
||||||
|
@ -304,12 +304,13 @@ class HomeKitEntity(Entity):
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the ID of this device."""
|
"""Return the ID of this device."""
|
||||||
return self._address
|
serial = self._accessory_info['serial-number']
|
||||||
|
return "homekit-{}-{}".format(serial, self._iid)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the device if any."""
|
"""Return the name of the device if any."""
|
||||||
return self._name
|
return self._accessory_info.get('name')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
|
|
@ -74,21 +74,14 @@ class HomeKitGarageDoorCover(HomeKitEntity, CoverDevice):
|
||||||
CharacteristicsTypes.DOOR_STATE_CURRENT,
|
CharacteristicsTypes.DOOR_STATE_CURRENT,
|
||||||
CharacteristicsTypes.DOOR_STATE_TARGET,
|
CharacteristicsTypes.DOOR_STATE_TARGET,
|
||||||
CharacteristicsTypes.OBSTRUCTION_DETECTED,
|
CharacteristicsTypes.OBSTRUCTION_DETECTED,
|
||||||
CharacteristicsTypes.NAME,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def _setup_name(self, char):
|
|
||||||
self._name = char['value']
|
|
||||||
|
|
||||||
def _update_door_state_current(self, value):
|
def _update_door_state_current(self, value):
|
||||||
self._state = CURRENT_GARAGE_STATE_MAP[value]
|
self._state = CURRENT_GARAGE_STATE_MAP[value]
|
||||||
|
|
||||||
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._name = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
|
@ -172,12 +165,8 @@ class HomeKitWindowCover(HomeKitEntity, CoverDevice):
|
||||||
CharacteristicsTypes.HORIZONTAL_TILT_CURRENT,
|
CharacteristicsTypes.HORIZONTAL_TILT_CURRENT,
|
||||||
CharacteristicsTypes.HORIZONTAL_TILT_TARGET,
|
CharacteristicsTypes.HORIZONTAL_TILT_TARGET,
|
||||||
CharacteristicsTypes.OBSTRUCTION_DETECTED,
|
CharacteristicsTypes.OBSTRUCTION_DETECTED,
|
||||||
CharacteristicsTypes.NAME,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def _setup_name(self, char):
|
|
||||||
self._name = char['value']
|
|
||||||
|
|
||||||
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]
|
||||||
|
|
||||||
|
|
|
@ -26,14 +26,14 @@ async def test_koogeek_ls1_setup(hass):
|
||||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||||
|
|
||||||
# Assert that the entity is correctly added to the entity registry
|
# Assert that the entity is correctly added to the entity registry
|
||||||
entity = entity_registry.async_get('light.testdevice')
|
entry = entity_registry.async_get('light.koogeek_ls1_20833f')
|
||||||
assert entity.unique_id == 'homekit-AAAA011111111111-7'
|
assert entry.unique_id == 'homekit-AAAA011111111111-7'
|
||||||
|
|
||||||
helper = Helper(hass, 'light.testdevice', pairing, accessories[0])
|
helper = Helper(hass, 'light.koogeek_ls1_20833f', pairing, accessories[0])
|
||||||
state = await helper.poll_and_get_state()
|
state = await helper.poll_and_get_state()
|
||||||
|
|
||||||
# Assert that the friendly name is detected correctly
|
# Assert that the friendly name is detected correctly
|
||||||
assert state.attributes['friendly_name'] == 'TestDevice'
|
assert state.attributes['friendly_name'] == 'Koogeek-LS1-20833F'
|
||||||
|
|
||||||
# Assert that all optional features the LS1 supports are detected
|
# Assert that all optional features the LS1 supports are detected
|
||||||
assert state.attributes['supported_features'] == (
|
assert state.attributes['supported_features'] == (
|
||||||
|
@ -54,7 +54,7 @@ async def test_recover_from_failure(hass, utcnow, failure_cls):
|
||||||
accessories = setup_accessories_from_file(profile_path)
|
accessories = setup_accessories_from_file(profile_path)
|
||||||
pairing = await setup_test_accessories(hass, accessories)
|
pairing = await setup_test_accessories(hass, accessories)
|
||||||
|
|
||||||
helper = Helper(hass, 'light.testdevice', pairing, accessories[0])
|
helper = Helper(hass, 'light.koogeek_ls1_20833f', pairing, accessories[0])
|
||||||
|
|
||||||
# Set light state on fake device to off
|
# Set light state on fake device to off
|
||||||
helper.characteristics[LIGHT_ON].set_value(False)
|
helper.characteristics[LIGHT_ON].set_value(False)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue