hass-core/homeassistant/components/homekit_controller/connection.py
Jc2k dbf129dfdd Start preparing for homekit_controller config entries (#21564)
* Start preparing for homekit_controller config entries

* Review feedback

* Review feedback

* Only use the vol.strip validator for pairing_code

* CV not required now

* Changes from review

* Changes after review
2019-03-06 19:44:52 -08:00

35 lines
1.3 KiB
Python

"""Helpers for managing a pairing with a HomeKit accessory or bridge."""
def get_accessory_information(accessory):
"""Obtain the accessory information service of a HomeKit device."""
# pylint: disable=import-error
from homekit.model.services import ServicesTypes
from homekit.model.characteristics import CharacteristicsTypes
result = {}
for service in accessory['services']:
stype = service['type'].upper()
if ServicesTypes.get_short(stype) != 'accessory-information':
continue
for characteristic in service['characteristics']:
ctype = CharacteristicsTypes.get_short(characteristic['type'])
if 'value' in characteristic:
result[ctype] = characteristic['value']
return result
def get_bridge_information(accessories):
"""Return the accessory info for the bridge."""
for accessory in accessories:
if accessory['aid'] == 1:
return get_accessory_information(accessory)
return get_accessory_information(accessories[0])
def get_accessory_name(accessory_info):
"""Return the name field of an accessory."""
for field in ('name', 'model', 'manufacturer'):
if field in accessory_info:
return accessory_info[field]
return None