Fix Hue homekit discovery (#37694)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
1 parent
405c1cdc86
commit
67b18aef5b
4 files changed
+96
-58
No files matched your search
@@ -161,11 +161,37 @@ async def async_setup_entry(
|
||||
config = bridge.api.config
|
||||
|
||||
# For backwards compat
|
||||
unique_id = normalize_bridge_id(config.bridgeid)
|
||||
if entry.unique_id is None:
|
||||
hass.config_entries.async_update_entry(
|
||||
entry, unique_id=normalize_bridge_id(config.bridgeid)
|
||||
hass.config_entries.async_update_entry(entry, unique_id=unique_id)
|
||||
|
||||
# For recovering from bug where we incorrectly assumed homekit ID = bridge ID
|
||||
elif entry.unique_id != unique_id:
|
||||
# Find entries with this unique ID
|
||||
other_entry = next(
|
||||
(
|
||||
entry
|
||||
for entry in hass.config_entries.async_entries(DOMAIN)
|
||||
if entry.unique_id == unique_id
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
if other_entry is None:
|
||||
# If no other entry, update unique ID of this entry ID.
|
||||
hass.config_entries.async_update_entry(entry, unique_id=unique_id)
|
||||
|
||||
elif other_entry.source == config_entries.SOURCE_IGNORE:
|
||||
# There is another entry but it is ignored, delete that one and update this one
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_remove(other_entry.entry_id)
|
||||
)
|
||||
hass.config_entries.async_update_entry(entry, unique_id=unique_id)
|
||||
else:
|
||||
# There is another entry that already has the right unique ID. Delete this entry
|
||||
hass.async_create_task(hass.config_entries.async_remove(entry.entry_id))
|
||||
return False
|
||||
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
|
||||
@@ -203,18 +203,6 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self.bridge = bridge
|
||||
return await self.async_step_link()
|
||||
|
||||
async def async_step_homekit(self, homekit_info):
|
||||
"""Handle HomeKit discovery."""
|
||||
bridge = self._async_get_bridge(
|
||||
homekit_info["host"], homekit_info["properties"]["id"]
|
||||
)
|
||||
|
||||
await self.async_set_unique_id(bridge.id)
|
||||
self._abort_if_unique_id_configured(updates={CONF_HOST: bridge.host})
|
||||
|
||||
self.bridge = bridge
|
||||
return await self.async_step_link()
|
||||
|
||||
async def async_step_import(self, import_info):
|
||||
"""Import a new bridge as a config entry.
|
||||
|
||||
|
||||
Reference in new issue
Block a user