Skip to content

Commit

Permalink
Fix homekit bridges when no name was provided (home-assistant#43364)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 19, 2020
1 parent d61998e commit a3061eb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions homeassistant/components/homekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ def _has_all_unique_names_and_ports(bridges):
)


def _async_get_entries_by_name(current_entries):
"""Return a dict of the entries by name."""

# For backwards compat, its possible the first bridge is using the default
# name.
return {entry.data.get(CONF_NAME, BRIDGE_NAME): entry for entry in current_entries}


async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the HomeKit from yaml."""
hass.data.setdefault(DOMAIN, {})
Expand All @@ -156,8 +164,7 @@ async def async_setup(hass: HomeAssistant, config: dict):
return True

current_entries = hass.config_entries.async_entries(DOMAIN)

entries_by_name = {entry.data[CONF_NAME]: entry for entry in current_entries}
entries_by_name = _async_get_entries_by_name(current_entries)

for index, conf in enumerate(config[DOMAIN]):
if _async_update_config_entry_if_from_yaml(hass, entries_by_name, conf):
Expand Down Expand Up @@ -384,7 +391,7 @@ async def _handle_homekit_reload(service):
return

current_entries = hass.config_entries.async_entries(DOMAIN)
entries_by_name = {entry.data[CONF_NAME]: entry for entry in current_entries}
entries_by_name = _async_get_entries_by_name(current_entries)

for conf in config[DOMAIN]:
_async_update_config_entry_if_from_yaml(hass, entries_by_name, conf)
Expand Down

0 comments on commit a3061eb

Please sign in to comment.