From edd93b1469506cd0a73d302429f77b10f4dffc5c Mon Sep 17 00:00:00 2001 From: Luke Bonaccorsi Date: Thu, 17 Aug 2023 17:10:41 +0100 Subject: [PATCH] Early return if current entries is empty --- custom_components/robovac/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/custom_components/robovac/__init__.py b/custom_components/robovac/__init__.py index 03fbe88..6d80551 100644 --- a/custom_components/robovac/__init__.py +++ b/custom_components/robovac/__init__.py @@ -32,13 +32,22 @@ async def async_setup(hass, entry) -> bool: hass.data.setdefault(DOMAIN, {}) def update_device(device): - current_entry = hass.config_entries.async_entries(DOMAIN)[0] - hass_data = current_entry.data.copy() + current_entries = hass.config_entries.async_entries(DOMAIN) + if len(current_entries) == 0: + return + + hass_data = current_entries[0].data.copy() if device["gwId"] in hass_data[CONF_VACS]: if hass_data[CONF_VACS][device["gwId"]]["ip_address"] != device["ip"]: hass_data[CONF_VACS][device["gwId"]]["ip_address"] = device["ip"] - hass.config_entries.async_update_entry(current_entry, data=hass_data) - _LOGGER.debug("Updated ip address of {} to {}".format(device["gwId"], device["ip"])) + hass.config_entries.async_update_entry( + current_entries[0], data=hass_data + ) + _LOGGER.debug( + "Updated ip address of {} to {}".format( + device["gwId"], device["ip"] + ) + ) tuyalocaldiscovery = TuyaLocalDiscovery(update_device) try: