Fix error in homekit_controller causing some entities to get an incorrect unique id (#53848)

This commit is contained in:
Jc2k 2021-08-02 04:59:32 +01:00 committed by GitHub
parent 8c5620e74b
commit 73bc62949b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 354 additions and 10 deletions

View file

@ -189,11 +189,16 @@ class CharacteristicEntity(HomeKitEntity):
the service entity.
"""
def __init__(self, accessory, devinfo, char):
"""Initialise a generic single characteristic HomeKit entity."""
self._char = char
super().__init__(accessory, devinfo)
@property
def unique_id(self) -> str:
"""Return the ID of this device."""
serial = self.accessory_info.value(CharacteristicsTypes.SERIAL_NUMBER)
return f"homekit-{serial}-aid:{self._aid}-sid:{self._iid}-cid:{self._iid}"
return f"homekit-{serial}-aid:{self._aid}-sid:{self._char.service.iid}-cid:{self._char.iid}"
async def async_setup_entry(hass, entry):

View file

@ -53,9 +53,8 @@ class HomeKitNumber(CharacteristicEntity, NumberEntity):
self._device_class = device_class
self._icon = icon
self._name = name
self._char = char
super().__init__(conn, info)
super().__init__(conn, info, char)
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""

View file

@ -254,9 +254,8 @@ class SimpleSensor(CharacteristicEntity, SensorEntity):
self._unit = unit
self._icon = icon
self._name = name
self._char = char
super().__init__(conn, info)
super().__init__(conn, info, char)
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""