Make command timeout for workers configurable (#62)

This commit is contained in:
Dennis Keitzel
2019-03-10 09:51:50 +01:00
committed by zewelor
parent bc681fd85f
commit a655504f78
7 changed files with 37 additions and 23 deletions
+4 -1
View File
@@ -6,6 +6,9 @@ from workers.base import BaseWorker
REQUIREMENTS = ['git+https://github.com/zewelor/linak_bt_desk.git@aa9412f98b3044be34c70e89d02721e6813ea731#egg=linak_bt_desk']
class LinakdeskWorker(BaseWorker):
SCAN_TIMEOUT = 20
def _setup(self):
from linak_dpg_bt import LinakDesk
@@ -15,7 +18,7 @@ class LinakdeskWorker(BaseWorker):
return [MqttMessage(topic=self.format_topic('height/cm'), payload=self._get_height())]
def _get_height(self):
with timeout(20, exception=TimeoutError):
with timeout(SCAN_TIMEOUT, exception=TimeoutError('Retrieving the height from {} device {} timed out after {} seconds'.format(repr(self), self.mac, SCAN_TIMEOUT))):
self.desk.read_dpg_data()
return self.desk.current_height_with_offset.cm