-
Notifications
You must be signed in to change notification settings - Fork 1
/
yolinkTHsensorV2.py
81 lines (63 loc) · 2.27 KB
/
yolinkTHsensorV2.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import time
from yolink_mqtt_classV3 import YoLinkMQTTDevice
try:
import udi_interface
logging = udi_interface.LOGGER
Custom = udi_interface.Custom
except ImportError:
import logging
logging.basicConfig(level=logging.DEBUG)
class YoLinkTHSen(YoLinkMQTTDevice):
def __init__(yolink, yoAccess, deviceInfo, callback):
super().__init__( yoAccess, deviceInfo, callback)
yolink.methodList = ['getState' ]
yolink.eventList = ['Report']
yolink.tempName = 'THEvent'
yolink.temperature = 'Temperature'
yolink.humidity = 'Humidity'
yolink.eventTime = 'Time'
yolink.type = 'THSensor'
#time.sleep(2)
'''
def initNode(yolink):
yolink.refreshSensor()
time.sleep(2)
#yolink.online = yolink.getOnlineStatus()
if not yolink.online:
logging.error('THsensor not online')
'''
def updateStatus(self, data):
logging.debug('updataStatus THsensor : {}'.format(data))
self.updateCallbackStatus(data, False)
def refreshSensor(yolink):
logging.debug(yolink.type+ ' - refreshSensor')
return(yolink.refreshDevice( ))
#def onlineStatus(yolink):
# logging.debug(yolink.type+ ' - getOnlineStatus')
# return(yolink.getOnlineStatus( ))
def getTempValueF(yolink):
return(yolink.getStateValue('temperature')*9/5+32)
def getTempValueC(yolink):
return(yolink.getStateValue('temperature'))
def getHumidityValue(yolink):
return(yolink.getStateValue('humidity'))
'''
def getAlarms(yolink):
return(yolink.getStateValue('alarm'))
def getBattery(yolink):
return(yolink.getStateValue('battery'))
'''
#def probeState(yolink):
# return(yolink.getState() )
#def probeData(yolink):
# return(yolink.getData() )
'''
Stand-Alone Operation of THsensor (no call back to live update data - pooling data in upper APP)
'''
class YoLinkTHSensor(YoLinkTHSen):
def __init__(yolink, yoAccess, deviceInfo):
super().__init__( yoAccess, deviceInfo, yolink.updateStatus)
yolink.initNode()
# Enable Event Support (True below)
def updateStatus(yolink, data):
yolink.updateCallbackStatus(data, True)