added dict get() instead of assuming keys exist; now handles config_flow setup failures without crashing

This commit is contained in:
hello@theauthtoken.com
2022-10-09 19:54:31 -07:00
committed by rospogrigio
parent 7b37f07fd0
commit d2fa4dc2a0
2 changed files with 11 additions and 8 deletions

View File

@@ -124,8 +124,10 @@ def async_config_entry_by_device_id(hass, device_id):
"""Look up config entry by device id."""
current_entries = hass.config_entries.async_entries(DOMAIN)
for entry in current_entries:
if device_id in entry.data[CONF_DEVICES]:
if device_id in entry.data.get(CONF_DEVICES, []):
return entry
else:
_LOGGER.warning(f"Missing device configuration for device_id {device_id}")
return None