2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-21 17:11:58 +00:00

Script to walk identify light along a noderange

This commit is contained in:
Jarrod Johnson 2021-11-10 15:19:37 -05:00
parent 9a6d422fd8
commit 2b6418bc33

41
misc/snakeidentify.py Normal file
View File

@ -0,0 +1,41 @@
import argparse
import confluent.client as cli
import sys
import time
c = cli.Command()
nodes = []
ap = argparse.ArgumentParser(description='Snake identify light through nodes')
ap.add_argument('noderange', help='Noderange to iterate through')
ap.add_argument('-d', '--duration', type=float, help='How long to have each system illuminated')
args = ap.parse_args()
def runit(itera):
for rsp in itera:
if 'error' in rsp:
sys.stderr.write('{0}\n'.format(repr(rsp)))
for ret in c.read('/noderange/{0}/nodes/'.format(args.noderange)):
node = ret.get('item', {}).get('href', None)
if node:
node = node.replace('/', '')
nodes.append(node)
else:
print(repr(ret))
if not nodes:
sys.exit(1)
lastnode = None
interval = args.duration
if interval:
interval = interval / 2
else:
interval = 0.25
while True:
for node in nodes:
print('Lighting {0}'.format(node))
runit(c.update('/nodes/{0}/identify'.format(node), {'identify': 'on'}))
time.sleep(interval)
if lastnode:
runit(c.update('/nodes/{0}/identify'.format(lastnode), {'identify': 'off'}))
lastnode = node
time.sleep(interval)