Skip to content

Commit 6d386c6

Browse files
author
Mike Stegeman
committed
Start a thread when an IPC message is received.
1 parent da085e9 commit 6d386c6

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

gateway_addon/addon_manager_proxy.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,21 @@ def recv(self):
148148

149149
# High-level adapter messages
150150
if msg_type == 'startPairing':
151-
self.adapter.start_pairing(msg['data']['timeout'])
151+
self.make_thread(self.adapter.start_pairing,
152+
args=(msg['data']['timeout'],))
152153
continue
153154

154155
if msg_type == 'cancelPairing':
155-
self.adapter.cancel_pairing()
156+
self.make_thread(self.adapter.cancel_pairing)
156157
continue
157158

158159
if msg_type == 'unloadAdapter':
159-
self.adapter.unload()
160-
self.send('adapterUnloaded', {'adapterId', self.adapter.id})
160+
def unload_fn(proxy):
161+
proxy.adapter.unload()
162+
proxy.send('adapterUnloaded',
163+
{'adapterId', proxy.adapter.id})
164+
165+
self.make_thread(unload_fn, args=(self,))
161166
continue
162167

163168
if msg_type == 'unloadPlugin':
@@ -170,19 +175,29 @@ def recv(self):
170175
'ignoring.')
171176
continue
172177

173-
device_id = msg['data']['device_id']
178+
device_id = msg['data']['deviceId']
174179
if msg_type == 'removeThing':
175-
self.adapter.remove_thing(device_id)
180+
self.make_thread(self.adapter.remove_thing, args=(device_id,))
176181
continue
177182

178183
if msg_type == 'cancelRemoveThing':
179-
self.adapter.cancel_remove_thing(device_id)
184+
self.make_thread(self.adapter.cancel_remove_thing,
185+
args=(device_id,))
180186
continue
181187

182188
if msg_type == 'setProperty':
183-
dev = self.adapter.get_device(device_id)
184-
if dev:
185-
prop = dev.get_property(msg['data']['propertyName'])
186-
if prop:
187-
prop.set_value(msg['data']['propertyValue'])
188-
continue
189+
def set_prop_fn(proxy):
190+
dev = proxy.adapter.get_device(device_id)
191+
if dev:
192+
prop = dev.find_property(msg['data']['propertyName'])
193+
if prop:
194+
prop.set_value(msg['data']['propertyValue'])
195+
196+
self.make_thread(set_prop_fn, args=(self,))
197+
continue
198+
199+
@staticmethod
200+
def make_thread(target, args=()):
201+
t = threading.Thread(target=target, args=args)
202+
t.daemon = True
203+
t.start()

gateway_addon/property.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, device, name, description):
2020
fields = ['type', 'unit', 'description', 'min', 'max']
2121
for field in fields:
2222
if field in description:
23-
self.description['field'] = description['field']
23+
self.description[field] = description[field]
2424

2525
def as_dict(self):
2626
"""
@@ -51,7 +51,8 @@ def set_cached_value(self, value):
5151
5252
Returns the value that was set.
5353
"""
54-
if self.type == 'boolean':
54+
if 'type' in self.description and \
55+
self.description['type'] == 'boolean':
5556
self.value = bool(value)
5657
else:
5758
self.value = value

0 commit comments

Comments
 (0)