-
Notifications
You must be signed in to change notification settings - Fork 1
/
udiYoGarageDoorCtrlV2.py
135 lines (98 loc) · 3.54 KB
/
udiYoGarageDoorCtrlV2.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
"""
Polyglot TEST v3 node server
MIT License
"""
from os import truncate
try:
import udi_interface
logging = udi_interface.LOGGER
Custom = udi_interface.Custom
except ImportError:
import logging
logging.basicConfig(level=logging.INFO)
#import sys
import time
from yolinkGarageDoorToggleV2 import YoLinkGarageDoorCtrl
class udiYoGarageDoor(udi_interface.Node):
id = 'yogarage'
'''
drivers = [
'ST' = Online
]
'''
drivers = [
{'driver': 'ST', 'value': 0, 'uom': 25},
{'driver': 'GV20', 'value': 99, 'uom': 25},
#{'driver': 'ST', 'value': 1, 'uom': 25},
]
def __init__(self, polyglot, primary, address, name, yoAccess, deviceInfo):
super().__init__( polyglot, primary, address, name)
self.yoAccess=yoAccess
self.devInfo = deviceInfo
self.yoDoorControl = None
self.node_ready = False
logging.debug('udiYoGarageDoor INIT - {}'.format(deviceInfo['name']))
self.n_queue = []
#polyglot.subscribe(polyglot.POLL, self.poll)
polyglot.subscribe(polyglot.START, self.start, self.address)
polyglot.subscribe(polyglot.STOP, self.stop)
self.poly.subscribe(self.poly.ADDNODEDONE, self.node_queue)
# start processing events and create add our controller node
polyglot.ready()
self.poly.addNode(self, conn_status = None, rename = True)
self.wait_for_node_done()
self.node = self.poly.getNode(address)
self.adr_list = []
self.adr_list.append(address)
def node_queue(self, data):
self.n_queue.append(data['address'])
def wait_for_node_done(self):
while len(self.n_queue) == 0:
time.sleep(0.1)
self.n_queue.pop()
def start(self):
logging.info('start - udiYoGarageDoor')
self.node.setDriver('ST', 0, True, True)
self.yoDoorControl = YoLinkGarageDoorCtrl(self.yoAccess, self.devInfo, self.updateStatus)
time.sleep(2)
self.node.setDriver('ST', 1, True, True)
#time.sleep(3)
self.node_ready = True
def initNode(self):
self.yoDoorControl.online = True
#self.node.setDriver('ST', 1, True, True)
def checkOnline(self):
pass
def checkDataUpdate(self):
pass
def stop (self):
logging.info('Stop udiYoGarageDoor')
self.node.setDriver('ST', 0, True, True)
self.yoDoorControl.shut_down()
def updateStatus(self, data):
logging.debug('updateStatus - udiYoGarageDoor')
self.yoDoorControl.updateCallbackStatus(data)
if self.yoDoorControl.suspended:
self.node.setDriver('GV20', 1, True, True)
else:
self.node.setDriver('GV20', 0)
if self.yoDoorControl.online:
self.node.setDriver('ST', 1)
else:
self.node.setDriver('GV20', 2, True, True)
#self.node.setDriver('ST', 0, True, True)
#logging.debug(data)
#if self.node is not None:
# self.node.setDriver('ST',1, True, True)
def toggleDoor(self, command = None):
logging.info('GarageDoor Toggle Door')
self.yoDoorControl.toggleDevice()
self.node.reportCmd('DON')
time.sleep(1.5)
self.node.reportCmd('DOF')
commands = {
'TOGGLE': toggleDoor,
'DON' : toggleDoor,
'DOF' : toggleDoor,
}