Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of HomeKit accessory-information service #22171

Merged
merged 2 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions homeassistant/components/homekit_controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import call_later

from .connection import get_accessory_information
from .const import (
CONTROLLER, DOMAIN, HOMEKIT_ACCESSORY_DISPATCH, KNOWN_ACCESSORIES,
KNOWN_DEVICES
Expand Down Expand Up @@ -204,11 +205,9 @@ class HomeKitEntity(Entity):
def __init__(self, accessory, devinfo):
"""Initialise a generic HomeKit device."""
self._available = True
self._name = accessory.model
self._accessory = accessory
self._aid = devinfo['aid']
self._iid = devinfo['iid']
self._address = "homekit-{}-{}".format(devinfo['serial'], self._iid)
self._features = 0
self._chars = {}
self.setup()
Expand All @@ -232,6 +231,7 @@ def setup(self):
for accessory in pairing_data.get('accessories', []):
if accessory['aid'] != self._aid:
continue
self._accessory_info = get_accessory_information(accessory)
for service in accessory['services']:
if service['iid'] != self._iid:
continue
Expand Down Expand Up @@ -304,12 +304,13 @@ async def async_update(self):
@property
def unique_id(self):
"""Return the ID of this device."""
return self._address
serial = self._accessory_info.get('serial-number', 'unknown')
Jc2k marked this conversation as resolved.
Show resolved Hide resolved
return "homekit-{}-{}".format(serial, self._iid)

@property
def name(self):
"""Return the name of the device if any."""
return self._name
return self._accessory_info.get('name', None)
Jc2k marked this conversation as resolved.
Show resolved Hide resolved

@property
def available(self) -> bool:
Expand Down
11 changes: 0 additions & 11 deletions homeassistant/components/homekit_controller/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,14 @@ def get_characteristic_types(self):
CharacteristicsTypes.DOOR_STATE_CURRENT,
CharacteristicsTypes.DOOR_STATE_TARGET,
CharacteristicsTypes.OBSTRUCTION_DETECTED,
CharacteristicsTypes.NAME,
]

def _setup_name(self, char):
self._name = char['value']

def _update_door_state_current(self, value):
self._state = CURRENT_GARAGE_STATE_MAP[value]

def _update_obstruction_detected(self, value):
self._obstruction_detected = value

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

@property
def available(self):
"""Return True if entity is available."""
Expand Down Expand Up @@ -172,12 +165,8 @@ def get_characteristic_types(self):
CharacteristicsTypes.HORIZONTAL_TILT_CURRENT,
CharacteristicsTypes.HORIZONTAL_TILT_TARGET,
CharacteristicsTypes.OBSTRUCTION_DETECTED,
CharacteristicsTypes.NAME,
]

def _setup_name(self, char):
self._name = char['value']

def _update_position_state(self, value):
self._state = CURRENT_WINDOW_STATE_MAP[value]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ async def test_koogeek_ls1_setup(hass):
entity_registry = await hass.helpers.entity_registry.async_get_registry()

# Assert that the entity is correctly added to the entity registry
entity = entity_registry.async_get('light.testdevice')
assert entity.unique_id == 'homekit-AAAA011111111111-7'
entry = entity_registry.async_get('light.koogeek_ls1_20833f')
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()

# 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 state.attributes['supported_features'] == (
Expand All @@ -54,7 +54,7 @@ async def test_recover_from_failure(hass, utcnow, failure_cls):
accessories = setup_accessories_from_file(profile_path)
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
helper.characteristics[LIGHT_ON].set_value(False)
Expand Down