Avoid duplicate search for existing config entries in homekit_controller (#107613)
This commit is contained in:
parent
7c98c1e544
commit
0458bd68d9
1 changed files with 4 additions and 17 deletions
|
@ -20,7 +20,7 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.data_entry_flow import AbortFlow, FlowResult
|
from homeassistant.data_entry_flow import AbortFlow, FlowResult
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
|
@ -79,17 +79,6 @@ def formatted_category(category: Categories) -> str:
|
||||||
return str(category.name).replace("_", " ").title()
|
return str(category.name).replace("_", " ").title()
|
||||||
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def find_existing_config_entry(
|
|
||||||
hass: HomeAssistant, upper_case_hkid: str
|
|
||||||
) -> config_entries.ConfigEntry | None:
|
|
||||||
"""Return a set of the configured hosts."""
|
|
||||||
for entry in hass.config_entries.async_entries(DOMAIN):
|
|
||||||
if entry.data.get("AccessoryPairingID") == upper_case_hkid:
|
|
||||||
return entry
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_pin_format(pin: str, allow_insecure_setup_codes: Any = None) -> str:
|
def ensure_pin_format(pin: str, allow_insecure_setup_codes: Any = None) -> str:
|
||||||
"""Ensure a pin code is correctly formatted.
|
"""Ensure a pin code is correctly formatted.
|
||||||
|
|
||||||
|
@ -284,9 +273,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
# Device isn't paired with us or anyone else.
|
# Device isn't paired with us or anyone else.
|
||||||
# But we have a 'complete' config entry for it - that is probably
|
# But we have a 'complete' config entry for it - that is probably
|
||||||
# invalid. Remove it automatically.
|
# invalid. Remove it automatically.
|
||||||
if not paired and (
|
if not paired and existing_entry:
|
||||||
existing := find_existing_config_entry(self.hass, upper_case_hkid)
|
|
||||||
):
|
|
||||||
if self.controller is None:
|
if self.controller is None:
|
||||||
await self._async_setup_controller()
|
await self._async_setup_controller()
|
||||||
|
|
||||||
|
@ -295,7 +282,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
assert self.controller
|
assert self.controller
|
||||||
|
|
||||||
pairing = self.controller.load_pairing(
|
pairing = self.controller.load_pairing(
|
||||||
existing.data["AccessoryPairingID"], dict(existing.data)
|
existing_entry.data["AccessoryPairingID"], dict(existing_entry.data)
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -310,7 +297,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
model,
|
model,
|
||||||
hkid,
|
hkid,
|
||||||
)
|
)
|
||||||
await self.hass.config_entries.async_remove(existing.entry_id)
|
await self.hass.config_entries.async_remove(existing_entry.entry_id)
|
||||||
else:
|
else:
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
(
|
(
|
||||||
|
|
Loading…
Add table
Reference in a new issue