mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Fix homekit error when the bridge has been ignored. (#40082)
This commit is contained in:
parent
d0f4b23063
commit
938e06c00e
@ -118,7 +118,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self.entry_title = title
|
self.entry_title = title
|
||||||
return await self.async_step_pairing()
|
return await self.async_step_pairing()
|
||||||
|
|
||||||
default_domains = [] if self._async_current_entries() else DEFAULT_DOMAINS
|
default_domains = [] if self._async_current_names() else DEFAULT_DOMAINS
|
||||||
setup_schema = vol.Schema(
|
setup_schema = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional(CONF_AUTO_START, default=DEFAULT_AUTO_START): bool,
|
vol.Optional(CONF_AUTO_START, default=DEFAULT_AUTO_START): bool,
|
||||||
@ -146,17 +146,27 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
find_next_available_port, DEFAULT_CONFIG_FLOW_PORT
|
find_next_available_port, DEFAULT_CONFIG_FLOW_PORT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _async_current_names(self):
|
||||||
|
"""Return a set of bridge names."""
|
||||||
|
current_entries = self._async_current_entries()
|
||||||
|
|
||||||
|
return {
|
||||||
|
entry.data[CONF_NAME]
|
||||||
|
for entry in current_entries
|
||||||
|
if CONF_NAME in entry.data
|
||||||
|
}
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_available_name(self):
|
def _async_available_name(self):
|
||||||
"""Return an available for the bridge."""
|
"""Return an available for the bridge."""
|
||||||
current_entries = self._async_current_entries()
|
|
||||||
|
|
||||||
# We always pick a RANDOM name to avoid Zeroconf
|
# We always pick a RANDOM name to avoid Zeroconf
|
||||||
# name collisions. If the name has been seen before
|
# name collisions. If the name has been seen before
|
||||||
# pairing will probably fail.
|
# pairing will probably fail.
|
||||||
acceptable_chars = string.ascii_uppercase + string.digits
|
acceptable_chars = string.ascii_uppercase + string.digits
|
||||||
trailer = "".join(random.choices(acceptable_chars, k=4))
|
trailer = "".join(random.choices(acceptable_chars, k=4))
|
||||||
all_names = {entry.data[CONF_NAME] for entry in current_entries}
|
all_names = self._async_current_names()
|
||||||
suggested_name = f"{SHORT_BRIDGE_NAME} {trailer}"
|
suggested_name = f"{SHORT_BRIDGE_NAME} {trailer}"
|
||||||
while suggested_name in all_names:
|
while suggested_name in all_names:
|
||||||
trailer = "".join(random.choices(acceptable_chars, k=4))
|
trailer = "".join(random.choices(acceptable_chars, k=4))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user