Handle accessories without a serial number in homekit_controller (#58498)
This commit is contained in:
parent
3b7f620aad
commit
5581f58aad
5 changed files with 726 additions and 19 deletions
|
@ -12,7 +12,7 @@ from aiohomekit.model import Accessories
|
|||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
from homeassistant.const import ATTR_IDENTIFIERS, ATTR_VIA_DEVICE
|
||||
from homeassistant.const import ATTR_VIA_DEVICE
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
@ -24,6 +24,8 @@ from .const import (
|
|||
DOMAIN,
|
||||
ENTITY_MAP,
|
||||
HOMEKIT_ACCESSORY_DISPATCH,
|
||||
IDENTIFIER_ACCESSORY_ID,
|
||||
IDENTIFIER_SERIAL_NUMBER,
|
||||
)
|
||||
from .device_trigger import async_fire_triggers, async_setup_triggers_for_entry
|
||||
|
||||
|
@ -207,33 +209,40 @@ class HKDevice:
|
|||
service_type=ServicesTypes.ACCESSORY_INFORMATION,
|
||||
)
|
||||
|
||||
device_info = DeviceInfo(
|
||||
identifiers={
|
||||
serial_number = info.value(CharacteristicsTypes.SERIAL_NUMBER)
|
||||
|
||||
if serial_number:
|
||||
identifiers = {(DOMAIN, IDENTIFIER_SERIAL_NUMBER, serial_number)}
|
||||
else:
|
||||
# Some accessories do not have a serial number
|
||||
identifiers = {
|
||||
(
|
||||
DOMAIN,
|
||||
"serial-number",
|
||||
info.value(CharacteristicsTypes.SERIAL_NUMBER),
|
||||
IDENTIFIER_ACCESSORY_ID,
|
||||
f"{self.unique_id}_{accessory.aid}",
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
if accessory.aid == 1:
|
||||
# Accessory 1 is the root device (sometimes the only device, sometimes a bridge)
|
||||
# Link the root device to the pairing id for the connection.
|
||||
identifiers.add((DOMAIN, IDENTIFIER_ACCESSORY_ID, self.unique_id))
|
||||
|
||||
device_info = DeviceInfo(
|
||||
identifiers=identifiers,
|
||||
name=info.value(CharacteristicsTypes.NAME),
|
||||
manufacturer=info.value(CharacteristicsTypes.MANUFACTURER, ""),
|
||||
model=info.value(CharacteristicsTypes.MODEL, ""),
|
||||
sw_version=info.value(CharacteristicsTypes.FIRMWARE_REVISION, ""),
|
||||
)
|
||||
|
||||
if accessory.aid == 1:
|
||||
# Accessory 1 is the root device (sometimes the only device, sometimes a bridge)
|
||||
# Link the root device to the pairing id for the connection.
|
||||
device_info[ATTR_IDENTIFIERS].add(
|
||||
(DOMAIN, "accessory-id", self.unique_id)
|
||||
)
|
||||
else:
|
||||
if accessory.aid != 1:
|
||||
# Every pairing has an accessory 1
|
||||
# It *doesn't* have a via_device, as it is the device we are connecting to
|
||||
# Every other accessory should use it as its via device.
|
||||
device_info[ATTR_VIA_DEVICE] = (
|
||||
DOMAIN,
|
||||
"serial-number",
|
||||
IDENTIFIER_SERIAL_NUMBER,
|
||||
self.connection_info["serial-number"],
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue