Mercurial > code > home > repos > homeauto
diff service/shuttlepro/shuttlepro.py @ 130:57ae7dc0f417
new shuttlepro web service with /graph
Ignore-this: 1c8e71aad6ab24fa24532f4e5e01d2d9
author | drewp@bigasterisk.com |
---|---|
date | Fri, 11 Oct 2013 22:36:41 -0700 |
parents | 06ad4a0f42c0 |
children |
line wrap: on
line diff
--- a/service/shuttlepro/shuttlepro.py Tue Oct 08 21:42:24 2013 -0700 +++ b/service/shuttlepro/shuttlepro.py Fri Oct 11 22:36:41 2013 -0700 @@ -25,7 +25,6 @@ modified by drewp@bigasterisk.com """ - import os, time, logging import sys import struct @@ -354,43 +353,10 @@ return event -import restkit -reasoning = restkit.Resource("http://bang:9071/", timeout=1) - -from rdflib import Namespace, Graph, Literal -SHUTTLEPRO = Namespace("http://bigasterisk.com/room/livingRoom/shuttlepro/") -ROOM = Namespace("http://projects.bigasterisk.com/room/") if __name__ == '__main__': - import restkit - reasoning = restkit.Resource("http://bang:9071/", timeout=1) - - # this should serve a graph of the current state as well, not just all oneshots - def ev(what): print 'ev', what - g = Graph() - if 'key' in what: - g.add((SHUTTLEPRO['button%s' % what['key']['button']], - ROOM['state'], - ROOM['press'] if what['key']['press'] else ROOM['release'])) - elif 'shuttle' in what: - # this will send lots of repeats. It's really not a one-shot at all. - g.add((SHUTTLEPRO['shuttle'], ROOM['position'], - Literal(what['shuttle']))) - elif 'dial' in what: - g.add((SHUTTLEPRO['dial'], ROOM['change'], - ROOM['clockwise'] if what['dial'] == 1 else - ROOM['counterclockwise'])) - try: - nt = g.serialize(format='nt') - reasoning.post( - "oneShot", - payload=nt, - headers={'Content-Type': 'text/n3'}, - ).body_string() - except restkit.errors.RequestTimeout, e: - log.error(e) p = powermate("/dev/input/by-id/usb-Contour_Design_ShuttlePRO-event-if00", ev) while True: