Early return if current entries is empty

This commit is contained in:
Luke Bonaccorsi 2023-08-17 17:10:41 +01:00
parent 26cbc26af1
commit edd93b1469
1 changed files with 13 additions and 4 deletions

View File

@ -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: