-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
FromVehicleCharacteristic.py
44 lines (37 loc) · 1.53 KB
/
FromVehicleCharacteristic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import threading
from time import sleep
from pybleno import *
from Tesla import bcolors, getOutputStringFV
class FromVehicleCharacteristic(Characteristic):
def __init__(self, tesla):
Characteristic.__init__(self, {
'uuid': '00000213b2d143f09b88960cebf8b91e',
'properties': ['indicate'],
'descriptors': [
Descriptor({
'uuid': '2901',
'value': bytes('From Vehicle','ascii')
})],
'value': None
})
self.tesla = tesla
threading.Thread(None,self.watchMessage).start()
self._updateValueCallback = None
def watchMessage(self):
sleep(0.5)
if (len(self.tesla.messagelist)>0):
try:
msg = self.tesla.messagelist.pop(0)
self._updateValueCallback(msg)
print(bcolors.OKGREEN+"Sent Message:\n"+getOutputStringFV(msg,self.tesla.human)+bcolors.ENDC)
except Exception as e:
print('... '+str(e))
if threading.main_thread().isAlive():
threading.Thread(None,self.watchMessage).start()
def onSubscribe(self, maxValueSize, updateValueCallback):
print("onSubscribe")
self._updateValueCallback = updateValueCallback
return super().onSubscribe(maxValueSize, updateValueCallback)
def onUnsubscribe(self):
print('EchoCharacteristic - onUnsubscribe');
self._updateValueCallback = None