Migrate HomeKit Controller to use stable identifiers (#80064)

This commit is contained in:
J. Nick Koston 2022-10-11 11:26:03 -10:00 committed by GitHub
parent e3a3f93441
commit f23b1750e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 781 additions and 234 deletions

View file

@ -121,8 +121,8 @@ class HomeKitEntity(Entity):
self._char_name = char.service.value(CharacteristicsTypes.NAME)
@property
def unique_id(self) -> str:
"""Return the ID of this device."""
def old_unique_id(self) -> str:
"""Return the OLD ID of this device."""
info = self.accessory_info
serial = info.value(CharacteristicsTypes.SERIAL_NUMBER)
if valid_serial_number(serial):
@ -130,6 +130,11 @@ class HomeKitEntity(Entity):
# Some accessories do not have a serial number
return f"homekit-{self._accessory.unique_id}-{self._aid}-{self._iid}"
@property
def unique_id(self) -> str:
"""Return the ID of this device."""
return f"{self._accessory.unique_id}_{self._aid}_{self._iid}"
@property
def default_name(self) -> str | None:
"""Return the default name of the device."""
@ -175,11 +180,16 @@ class AccessoryEntity(HomeKitEntity):
"""A HomeKit entity that is related to an entire accessory rather than a specific service or characteristic."""
@property
def unique_id(self) -> str:
"""Return the ID of this device."""
def old_unique_id(self) -> str:
"""Return the old ID of this device."""
serial = self.accessory_info.value(CharacteristicsTypes.SERIAL_NUMBER)
return f"homekit-{serial}-aid:{self._aid}"
@property
def unique_id(self) -> str:
"""Return the ID of this device."""
return f"{self._accessory.unique_id}_{self._aid}"
class CharacteristicEntity(HomeKitEntity):
"""
@ -197,7 +207,12 @@ class CharacteristicEntity(HomeKitEntity):
super().__init__(accessory, devinfo)
@property
def unique_id(self) -> str:
"""Return the ID of this device."""
def old_unique_id(self) -> str:
"""Return the old ID of this device."""
serial = self.accessory_info.value(CharacteristicsTypes.SERIAL_NUMBER)
return f"homekit-{serial}-aid:{self._aid}-sid:{self._char.service.iid}-cid:{self._char.iid}"
@property
def unique_id(self) -> str:
"""Return the ID of this device."""
return f"{self._accessory.unique_id}_{self._aid}_{self._char.service.iid}_{self._char.iid}"