From b25acad5705a813c5caaccbb004c579701e9573c Mon Sep 17 00:00:00 2001 From: Luke Bonaccorsi Date: Thu, 17 Aug 2023 13:34:05 +0100 Subject: [PATCH] Use most recent version of entry --- custom_components/robovac/__init__.py | 12 ++++++------ custom_components/robovac/tuyalocaldiscovery.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/custom_components/robovac/__init__.py b/custom_components/robovac/__init__.py index 9b4cfd7..03fbe88 100644 --- a/custom_components/robovac/__init__.py +++ b/custom_components/robovac/__init__.py @@ -31,14 +31,14 @@ _LOGGER = logging.getLogger(__name__) async def async_setup(hass, entry) -> bool: hass.data.setdefault(DOMAIN, {}) - current_entries = hass.config_entries.async_entries(DOMAIN) - hass_data = dict(current_entries[0].data) - def update_device(device): + current_entry = hass.config_entries.async_entries(DOMAIN)[0] + hass_data = current_entry.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(entry, data=hass_data) + 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"])) tuyalocaldiscovery = TuyaLocalDiscovery(update_device) try: diff --git a/custom_components/robovac/tuyalocaldiscovery.py b/custom_components/robovac/tuyalocaldiscovery.py index c47e97e..dfe9890 100644 --- a/custom_components/robovac/tuyalocaldiscovery.py +++ b/custom_components/robovac/tuyalocaldiscovery.py @@ -28,7 +28,7 @@ class TuyaLocalDiscovery(asyncio.DatagramProtocol): self._listeners = await asyncio.gather(listener, encrypted_listener) _LOGGER.debug("Listening to broadcasts on UDP port 6666 and 6667") - def close(self): + def close(self, *args, **kwargs): for transport, _ in self._listeners: transport.close()