[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`.
This commit is contained in:
Fabio Manganiello 2024-11-04 00:13:44 +01:00
parent 2883c4f086
commit 71bafec11e
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

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