More robust logic in case of Tplink device not available
This commit is contained in:
parent
526bca847b
commit
9d6375f381
1 changed files with 7 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
from typing import Union, Dict, List
|
from typing import Union, Dict, List
|
||||||
|
|
||||||
from pyHS100 import SmartDevice, SmartPlug, SmartBulb, SmartStrip, Discover
|
from pyHS100 import SmartDevice, SmartPlug, SmartBulb, SmartStrip, Discover, SmartDeviceException
|
||||||
|
|
||||||
from platypush.plugins import action
|
from platypush.plugins import action
|
||||||
from platypush.plugins.switch import SwitchPlugin
|
from platypush.plugins.switch import SwitchPlugin
|
||||||
|
@ -64,9 +64,12 @@ class SwitchTplinkPlugin(SwitchPlugin):
|
||||||
|
|
||||||
def _update_devices(self, devices: Dict[str, SmartDevice] = None):
|
def _update_devices(self, devices: Dict[str, SmartDevice] = None):
|
||||||
for (addr, info) in self._static_devices.items():
|
for (addr, info) in self._static_devices.items():
|
||||||
|
try:
|
||||||
dev = info['type'](addr)
|
dev = info['type'](addr)
|
||||||
self._ip_to_dev[addr] = dev
|
|
||||||
self._alias_to_dev[info.get('name', dev.alias)] = dev
|
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 {}: {}'.format(addr, str(e)))
|
||||||
|
|
||||||
for (ip, dev) in (devices or {}).items():
|
for (ip, dev) in (devices or {}).items():
|
||||||
self._ip_to_dev[ip] = dev
|
self._ip_to_dev[ip] = dev
|
||||||
|
|
Loading…
Reference in a new issue