From 71bafec11eb636e3dd82a489a9f7de905f093e2a Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 4 Nov 2024 00:13:44 +0100 Subject: [PATCH] [switch.tplink] Better error handling. The whole `_update_devices` for loop should be covered by a try-except block. That's because custom attribute getters may be invoked also after expanding the results, resulting in unhandled `SmartDeviceException`. --- platypush/plugins/switch/tplink/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platypush/plugins/switch/tplink/__init__.py b/platypush/plugins/switch/tplink/__init__.py index 88a423de37..cf410ae175 100644 --- a/platypush/plugins/switch/tplink/__init__.py +++ b/platypush/plugins/switch/tplink/__init__.py @@ -86,16 +86,16 @@ class SwitchTplinkPlugin(RunnablePlugin, SwitchEntityManager): dev = info['type'](addr) self._alias_to_dev[info.get('name', dev.alias)] = dev self._ip_to_dev[addr] = dev + + for ip, dev in (devices or {}).items(): + self._ip_to_dev[ip] = dev + self._alias_to_dev[dev.alias] = dev + + if devices and publish_entities: + self.publish_entities(devices.values()) except SmartDeviceException as e: self.logger.warning('Could not communicate with device %s: %s', addr, e) - for ip, dev in (devices or {}).items(): - self._ip_to_dev[ip] = dev - self._alias_to_dev[dev.alias] = dev - - if devices and publish_entities: - self.publish_entities(devices.values()) - def transform_entities(self, entities: Collection[SmartDevice]): from platypush.entities.switches import Switch