Remove deprecated helper functions from homekit_controller pairing flow (#65270)
This commit is contained in:
parent
5999d08d72
commit
cc94af2872
3 changed files with 7 additions and 43 deletions
|
@ -4,6 +4,7 @@ import re
|
||||||
|
|
||||||
import aiohomekit
|
import aiohomekit
|
||||||
from aiohomekit.exceptions import AuthenticationError
|
from aiohomekit.exceptions import AuthenticationError
|
||||||
|
from aiohomekit.model import Accessories, CharacteristicsTypes, ServicesTypes
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
@ -15,7 +16,6 @@ from homeassistant.helpers.device_registry import (
|
||||||
async_get_registry as async_get_device_registry,
|
async_get_registry as async_get_device_registry,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .connection import get_accessory_name, get_bridge_information
|
|
||||||
from .const import DOMAIN, KNOWN_DEVICES
|
from .const import DOMAIN, KNOWN_DEVICES
|
||||||
|
|
||||||
HOMEKIT_DIR = ".homekit"
|
HOMEKIT_DIR = ".homekit"
|
||||||
|
@ -489,8 +489,11 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
if not (accessories := pairing_data.pop("accessories", None)):
|
if not (accessories := pairing_data.pop("accessories", None)):
|
||||||
accessories = await pairing.list_accessories_and_characteristics()
|
accessories = await pairing.list_accessories_and_characteristics()
|
||||||
|
|
||||||
bridge_info = get_bridge_information(accessories)
|
parsed = Accessories.from_list(accessories)
|
||||||
name = get_accessory_name(bridge_info)
|
accessory_info = parsed.aid(1).services.first(
|
||||||
|
service_type=ServicesTypes.ACCESSORY_INFORMATION
|
||||||
|
)
|
||||||
|
name = accessory_info.value(CharacteristicsTypes.NAME, "")
|
||||||
|
|
||||||
return self.async_create_entry(title=name, data=pairing_data)
|
return self.async_create_entry(title=name, data=pairing_data)
|
||||||
|
|
||||||
|
|
|
@ -48,36 +48,6 @@ def valid_serial_number(serial):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_accessory_information(accessory):
|
|
||||||
"""Obtain the accessory information service of a HomeKit device."""
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class HKDevice:
|
class HKDevice:
|
||||||
"""HomeKit device."""
|
"""HomeKit device."""
|
||||||
|
|
||||||
|
@ -642,13 +612,3 @@ class HKDevice:
|
||||||
This id is random and will change if a device undergoes a hard reset.
|
This id is random and will change if a device undergoes a hard reset.
|
||||||
"""
|
"""
|
||||||
return self.pairing_data["AccessoryPairingID"]
|
return self.pairing_data["AccessoryPairingID"]
|
||||||
|
|
||||||
@property
|
|
||||||
def connection_info(self):
|
|
||||||
"""Return accessory information for the main accessory."""
|
|
||||||
return get_bridge_information(self.accessories)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Name of the bridge accessory."""
|
|
||||||
return get_accessory_name(self.connection_info) or self.unique_id
|
|
||||||
|
|
|
@ -180,6 +180,7 @@ def setup_mock_accessory(controller):
|
||||||
serial_number="12345",
|
serial_number="12345",
|
||||||
firmware_revision="1.1",
|
firmware_revision="1.1",
|
||||||
)
|
)
|
||||||
|
accessory.aid = 1
|
||||||
|
|
||||||
service = accessory.add_service(ServicesTypes.LIGHTBULB)
|
service = accessory.add_service(ServicesTypes.LIGHTBULB)
|
||||||
on_char = service.add_char(CharacteristicsTypes.ON)
|
on_char = service.add_char(CharacteristicsTypes.ON)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue