Fix incorrect unique_id for BLE HomeKit devices (#87550)

This commit is contained in:
Jc2k 2023-02-08 01:10:51 +00:00 committed by GitHub
parent 79f385afde
commit d829a2045a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 7 deletions

View file

@ -27,6 +27,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.event import async_track_time_interval
from .config_flow import normalize_hkid
from .const import (
CHARACTERISTIC_PLATFORMS,
CONTROLLER,
@ -463,6 +464,20 @@ class HKDevice:
device_registry.async_update_device(device.id, new_identifiers=identifiers)
@callback
def async_migrate_ble_unique_id(self) -> None:
"""Config entries from step_bluetooth used incorrect identifier for unique_id."""
unique_id = normalize_hkid(self.unique_id)
if unique_id != self.config_entry.unique_id:
_LOGGER.debug(
"Fixing incorrect unique_id: %s -> %s",
self.config_entry.unique_id,
unique_id,
)
self.hass.config_entries.async_update_entry(
self.config_entry, unique_id=unique_id
)
@callback
def async_create_devices(self) -> None:
"""Build device registry entries for all accessories paired with the bridge.
@ -551,6 +566,8 @@ class HKDevice:
# Remove any of the legacy serial numbers from the device registry
self.async_remove_legacy_device_serial_numbers()
self.async_migrate_ble_unique_id()
self.async_create_devices()
# Load any triggers for this config entry