Skip to content

Commit

Permalink
[switch.tplink] Better error handling.
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
blacklight committed Nov 3, 2024
1 parent 2883c4f commit 71bafec
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions platypush/plugins/switch/tplink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def _update_devices(
dev = info['type'](addr)
self._alias_to_dev[info.get('name', dev.alias)] = dev
self._ip_to_dev[addr] = dev
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
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())
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)

def transform_entities(self, entities: Collection[SmartDevice]):
from platypush.entities.switches import Switch
Expand Down

0 comments on commit 71bafec

Please sign in to comment.