Fix Hue config flow (#61028)

This commit is contained in:
Marcel van der Veldt 2021-12-05 18:46:48 +01:00 committed by GitHub
parent 86e8034ea0
commit 3eeb855679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -216,16 +216,17 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if not url.hostname: if not url.hostname:
return self.async_abort(reason="not_hue_bridge") return self.async_abort(reason="not_hue_bridge")
bridge = await self._get_bridge( # abort if we already have exactly this bridge id/host
# reload the integration if the host got updated
bridge_id = normalize_bridge_id(discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL])
await self.async_set_unique_id(bridge_id)
self._abort_if_unique_id_configured(
updates={CONF_HOST: url.hostname}, reload_on_update=True
)
self.bridge = await self._get_bridge(
url.hostname, discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL] url.hostname, discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL]
) )
await self.async_set_unique_id(bridge.id)
self._abort_if_unique_id_configured(
updates={CONF_HOST: bridge.host}, reload_on_update=False
)
self.bridge = bridge
return await self.async_step_link() return await self.async_step_link()
async def async_step_zeroconf( async def async_step_zeroconf(
@ -236,17 +237,18 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
This flow is triggered by the Zeroconf component. It will check if the This flow is triggered by the Zeroconf component. It will check if the
host is already configured and delegate to the import step if not. host is already configured and delegate to the import step if not.
""" """
bridge = await self._get_bridge( # abort if we already have exactly this bridge id/host
discovery_info.host, # reload the integration if the host got updated
discovery_info.properties["bridgeid"], bridge_id = normalize_bridge_id(discovery_info.properties["bridgeid"])
) await self.async_set_unique_id(bridge_id)
await self.async_set_unique_id(bridge.id)
self._abort_if_unique_id_configured( self._abort_if_unique_id_configured(
updates={CONF_HOST: bridge.host}, reload_on_update=False updates={CONF_HOST: discovery_info.host}, reload_on_update=True
) )
self.bridge = bridge # we need to query the other capabilities too
self.bridge = await self._get_bridge(
discovery_info.host, discovery_info.properties["bridgeid"]
)
return await self.async_step_link() return await self.async_step_link()
async def async_step_homekit( async def async_step_homekit(