Mercurial > code > home > repos > homeauto
changeset 55:0cffbf171a97
frontdoorarduino can return an rdf graph
Ignore-this: 4593075f2f7b5b3387b578b0a4fba207
author | drewp@bigasterisk.com |
---|---|
date | Sun, 27 Jan 2013 23:48:50 -0800 |
parents | 42411726a7ca |
children | 517bd1407ed6 |
files | service/frontDoorArduino/frontDoorArduino.py |
diffstat | 1 files changed, 30 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/service/frontDoorArduino/frontDoorArduino.py Sun Jan 27 23:48:30 2013 -0800 +++ b/service/frontDoorArduino/frontDoorArduino.py Sun Jan 27 23:48:50 2013 -0800 @@ -17,6 +17,7 @@ from twisted.python import log from twisted.internet import reactor, task from twisted.web.client import getPage +from rdflib import Namespace, Literal, URIRef sys.path.append("/my/proj/house/frontdoor") from loggingserial import LoggingSerial @@ -24,6 +25,12 @@ sys.path.append("/my/proj/homeauto/lib") from cycloneerr import PrettyErrorHandler +sys.path.append("/my/site/magma") +from stategraph import StateGraph + +DEV = Namespace("http://projects.bigasterisk.com/device/") +ROOM = Namespace("http://projects.bigasterisk.com/room/") + class Board(object): """ arduino board actions, plus the last values we wrote to it @@ -88,6 +95,26 @@ self.set_header("Content-Type", "application/xhtml+xml") self.write(open("index.html").read()) +class GraphResource(PrettyErrorHandler, cyclone.web.RequestHandler): + def get(self): + g = StateGraph(ctx=DEV['frontDoorArduino']) + + board = self.settings.board + g.add((DEV['frontDoorOpen'], ROOM['state'], + ROOM['open'] if board.getDoor() else ROOM['closed'])) + g.add((DEV['frontYardLight'], ROOM['state'], + ROOM['on'] if board.getYardLight() else ROOM['off'])) + g.add((DEV['frontDoorLcd'], ROOM['text'], + Literal(board.getLcd()))) + g.add((DEV['frontDoorLcd'], ROOM['brightness'], + Literal(board.getLcdBrightness()))) + + # not temperature yet because it's slow and should be cached from + # the last poll + + self.set_header('Content-type', 'application/x-trig') + self.write(g.asTrig()) + class Lcd(PrettyErrorHandler, cyclone.web.RequestHandler): def get(self): self.set_header("Content-Type", "text/plain") @@ -140,6 +167,7 @@ def __init__(self, board): handlers = [ (r"/", index), + (r"/graph", GraphResource), (r'/lcd', Lcd), (r'/door', Door), (r'/temperature', Temperature), @@ -159,6 +187,8 @@ def poll(self): try: + # this should be fetching everything and pinging reasoning + # if anything is new new = self.board.getDoor() if new != self.last: msg = json.dumps(dict(board=self.boardName,