Skip to content

Commit 9cc274e

Browse files
committed
Version 1.16 Dimmable seems to be broken in latest PyISY. Start adding code to keep HueID the same whenrebooted and devices come in different order
1 parent a5b144d commit 9cc274e

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2+
# My stuff
3+
config.yaml
4+
15
# Emacs backup files
26
*~
37
# Byte-compiled / optimized / DLL files
@@ -57,3 +61,6 @@ docs/_build/
5761

5862
# PyBuilder
5963
target/
64+
65+
# Apple crap
66+
.AppleDouble

ISYHelper/Helpers/PyHue.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class pyhue_isy_node_handler(hue_upnp_super_handler):
1616

1717
def __init__(self, parent, name, node, scene):
1818
self.parent = parent
19+
self.hid = 0
1920
self.name = name
2021
self.node = node
2122
self.scene = scene
@@ -62,7 +63,8 @@ def set_off(self):
6263
def set_bri(self,value):
6364
self.parent.parent.logger.info('pyhue:isy_handler.set_bri: %s on val=%d' % (self.name, value));
6465
# Only set directly on the node when it's dimmable and value is not 0 or 254
65-
if self.node.dimmable and value > 0 and value < 254:
66+
# TODO: node.dimmable broken in current PyISY?
67+
if value > 0 and value < 254:
6668
# val=bri does not work?
6769
ret = self.node.on(value)
6870
self.parent.parent.logger.info('pyhue:isy_handler.set_bri: %s node.on(%d) = %s' % (self.name, value, str(ret)));
@@ -185,15 +187,16 @@ def start(self):
185187
cnode = mnode
186188
if len(mnode.controllers) > 0:
187189
mnode = self.parent.isy.nodes[mnode.controllers[0]]
188-
self.pdevices.append(pyhue_isy_node_handler(self,spoken,mnode,cnode))
189-
190+
self.insert_device(pyhue_isy_node_handler(self,spoken,mnode,cnode))
191+
192+
190193
for var in self.parent.isy.variables.children:
191194
# var is a tuple of type, name, number
192195
# TODO: Use ([^\/]+) instead of (.*) ?
193196
match_obj = re.match( r'.*\.Spoken\.(.*)', var[1], re.I)
194197
if match_obj:
195198
var_obj = self.parent.isy.variables[var[0]][var[2]]
196-
self.pdevices.append(pyhue_isy_var_handler(self,match_obj.group(1),var))
199+
self.insert_device(pyhue_isy_var_handler(self,match_obj.group(1),var))
197200
#errors += 1
198201
if errors > 0:
199202
raise ValueError("See Log")
@@ -208,6 +211,12 @@ def start(self):
208211
self.hue_upnp = hue_upnp(hueUpnp_config)
209212
self.parent.sched.add_job(partial(self.hue_upnp.run,0), misfire_grace_time=360, id=self.name)
210213

214+
def insert_device(self,device):
215+
# TODO: See if we have an id with this name and use it
216+
# TODO: This is so ID's never change.
217+
device.bid = len(self.pdevices)
218+
self.pdevices.insert(device.bid,device)
219+
211220
def add_device(self,config):
212221
self.parent.logger.info(self.lpfx + ' ' + str(config))
213222
if not 'name' in config:
@@ -226,21 +235,21 @@ def add_device(self,config):
226235
if node is None:
227236
raise ValueError("Unknown device name or address '" + dname + "'")
228237
else:
229-
self.pdevices.append([ config['name'], device_isy_onoff(self,node)])
238+
self.insert_device([ config['name'], device_isy_onoff(self,node)])
230239
elif config['type'] == 'Maker':
231240
#if self.config in 'ifttt':
232241
# if not self.config['ifttt'] in 'maker_secret_key':
233242
# raise ValueError("Missing maker_secret_key in ifttt from config file")
234243
#else:
235244
# raise ValueError("Missing ifttt with maker_secret_key in config file")
236245

237-
self.pdevices.append([ config['name'], device_maker_onoff(self,config['on_event'],config['off_event'])])
246+
self.insert_device([ config['name'], device_maker_onoff(self,config['on_event'],config['off_event'])])
238247

239248
else:
240249
raise ValueError("Unknown PyHue device type " + config['type'])
241250

242251
def rest_get(self,webapp,request,path):
243-
command = path.split("/")
252+
command = path.split("/")
244253
self.parent.logger.debug("%s rest_get: command=%s" % (self.lpfx,str(command)))
245254
if command[0] == "listen":
246255
if command[1] == "stop":
@@ -257,6 +266,16 @@ def get_index(self):
257266
msg += "<li>Listening: %s\n" % (self.listening)
258267
msg += "<li><a href='%s/listen/start'>Start Listening</a>\n" % (self.name)
259268
msg += "<li><a href='%s/listen/stop'>Stop Listening</a>\n" % (self.name)
269+
msg += "<li>ISY Spoken Devices"
270+
msg += "\n<ul><table border=1><tr><th>HueId<th>Spoken<th>Node<th>Scene<th>On<th>Off<th>50%</tr>"
271+
for device in self.pdevices:
272+
msg += "<tr><td>{0}<td>{1}<td>{2}<td>{3}<tr>".format(device.bid,device.name,device.node,device.scene)
273+
#msg += "<td><A HREF='{0}'>on</a><td><A HREF='{1}'>off</a><td><A HREF='{2}'>50%</a>".format(device.isy_on,device.isy_off,device.isy_bri.format('128'))
274+
#if device.scene is False:
275+
# msg += "<td>{0}<td>&nbsp;".format(device.scene)
276+
#else:
277+
# msg += "<td>{0}<td>{1}".format(device.scene._id,device.scene.name)
278+
msg += "</table></ul>"
260279
msg += "</ul>\n"
261280
return msg
262281

ISYHelper/REST.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
from flask import Flask
66
from flask import request
7+
from traceback import format_exception
78

89
debug = False
910

@@ -44,15 +45,19 @@ def __init__(self,config,helpers,mylogger):
4445
def run(self):
4546
arg = "%s:%s" % (self.config['this_host']['host'],self.config['this_host']['port'])
4647
print "REST: %s" % (arg)
47-
self.app.run(host=self.config['this_host']['host'], port=int(self.config['this_host']['port']))
48+
self.app.run(host=self.config['this_host']['host'], port=int(self.config['this_host']['port']), use_reloader=False)
4849

4950
def get_ip(self):
5051
return request.remote_addr
5152

5253
@app.route("/")
5354
def top():
5455
app.logger.info("REST:top")
55-
return "ISYHelper Web Interface version %s<br>Requestor: %s<br>%s" % (CONFIG['isyhelper_version'], request.remote_addr, isyhelperRESTObj.helpers.get_index())
56+
try:
57+
return "ISYHelper Web Interface version %s<br>Requestor: %s<br>%s" % (CONFIG['isyhelper_version'], request.remote_addr, isyhelperRESTObj.helpers.get_index())
58+
except:
59+
exc_type, exc_value, exc_traceback = sys.exc_info()
60+
return "<pre>Top Error: %s</pre>" % ''.join(format_exception(exc_type, exc_value, exc_traceback))
5661

5762
#
5863
# This translates a REST setvar command to pass to the appropriate Helper

isyhelper.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
# - Need to pass current host and port to devices, which is used in foscam1
77
#
88

9-
VERSION = "1.15"
9+
VERSION = "1.16"
1010

1111
# When run in directory containing downloaded PyIsy
12-
import sys
12+
import sys,time,threading,subprocess,re,os
1313
sys.path.insert(0,"../PyISY")
1414
sys.path.insert(0,"../VarEvents")
1515

@@ -82,11 +82,23 @@
8282
print("ERROR: Helper ISY Setup " + str(e))
8383
exit()
8484

85+
sched.add_job(rest.run, misfire_grace_time=360, id="ISYHREST")
86+
8587
# Let the scheduler start jobs
8688
sched.start()
8789

8890
# Start the REST interface
8991
# TODO: I'm not really happy with having the rest be an object, since auto-reload does not work
90-
print "Starting REST interface..."
91-
logger.info("Starting REST interface...")
92-
rest.run()
92+
#print "Starting REST interface..."
93+
#logger.info("Starting REST interface...")
94+
#rest.run()
95+
96+
print "Initialization complete..."
97+
98+
try:
99+
while True:
100+
time.sleep(60)
101+
except KeyboardInterrupt:
102+
print "Exiting from interrupt"
103+
except:
104+
raise

0 commit comments

Comments
 (0)