forked from platypush/platypush
Implemented retry+sleep mechanism in Switchbot plugin in case of errors
This should prevent race conditions in case of command timeout+quick disconnection and retry that can result in race conditions and double free corruptions.
This commit is contained in:
parent
99fee9ce20
commit
26f6feebb7
1 changed files with 12 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import enum
|
import enum
|
||||||
|
import time
|
||||||
|
|
||||||
from platypush.message.response.bluetooth import BluetoothScanResponse
|
from platypush.message.response.bluetooth import BluetoothScanResponse
|
||||||
from platypush.plugins import action
|
from platypush.plugins import action
|
||||||
|
@ -65,8 +66,18 @@ class SwitchSwitchbotPlugin(SwitchPlugin, BluetoothBlePlugin):
|
||||||
def _run(self, device: str, command: Command):
|
def _run(self, device: str, command: Command):
|
||||||
if device in self.configured_devices_by_name:
|
if device in self.configured_devices_by_name:
|
||||||
device = self.configured_devices_by_name[device]
|
device = self.configured_devices_by_name[device]
|
||||||
|
n_tries = 1
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.write(device, command.value, handle=self.handle, channel_type='random', binary=True)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.exception(e)
|
||||||
|
n_tries -= 1
|
||||||
|
|
||||||
|
if n_tries == 0:
|
||||||
|
raise e
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
self.write(device, command.value, handle=self.handle, channel_type='random', binary=True)
|
|
||||||
return self.status(device)
|
return self.status(device)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
Loading…
Reference in a new issue