From a3061ebd8db5302496ff5bef629ede4131db3f57 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 19 Nov 2020 01:10:23 -1000 Subject: [PATCH] Fix homekit bridges when no name was provided (#43364) --- homeassistant/components/homekit/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 2a0638642ed..1155d3ef18e 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -146,6 +146,14 @@ RESET_ACCESSORY_SERVICE_SCHEMA = vol.Schema( ) +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, {}) @@ -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): @@ -384,7 +391,7 @@ def _async_register_events_and_services(hass: HomeAssistant): 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)