changeset 1534:df80deeef113

serve current usage as a graph Ignore-this: 76d210d576784acb639762cd6c6e6f13 darcs-hash:263305875758810b8beb38ed8b7dada825f9c4ce
author drewp <drewp@bigasterisk.com>
date Mon, 10 Feb 2020 00:01:39 -0800
parents a598d2141587
children 44bf18ee9555
files service/powerEagle/reader.py
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/service/powerEagle/reader.py	Sat Feb 08 04:02:22 2020 -0800
+++ b/service/powerEagle/reader.py	Mon Feb 10 00:01:39 2020 -0800
@@ -9,10 +9,13 @@
 from twisted.internet import reactor
 from twisted.internet.defer import inlineCallbacks
 import cyclone.web
+from rdflib import Namespace, Literal
 
 from standardservice.logsetup import log, verboseLogging
+from patchablegraph import PatchableGraph, CycloneGraphHandler, CycloneGraphEventsHandler
 
 from private_config import deviceIp, cloudId, installId, macId, periodSec
+ROOM = Namespace("http://projects.bigasterisk.com/room/")
 
 STATS = scales.collection('/root',
                           scales.PmfStat('poll'),
@@ -22,8 +25,9 @@
 auth = binascii.b2a_base64(authPlain.encode('ascii')).strip(b'=\n')
 
 class Poller(object):
-    def __init__(self, influx):
+    def __init__(self, influx, graph):
         self.influx = influx
+        self.graph = graph
         reactor.callLater(0, self.poll)
 
     @STATS.poll.time()
@@ -73,6 +77,11 @@
                 ))
 
             self.influx.write_points(pts, time_precision='s')
+
+            self.graph.patchObject(context=ROOM['powerEagle'],
+                                         subject=ROOM['housePower'],
+                                         predicate=ROOM['instantDemandWatts'],
+                                         newObject=Literal(float(ret['demand']) * 1000))
         except Exception as e:
             traceback.print_exc()
             log.error("failed: %r", e)
@@ -94,7 +103,8 @@
     verboseLogging(arg['-v'])
 
     influx = InfluxDBClient('bang', 9060, 'root', 'root', 'main')
-    p = Poller(influx)
+    masterGraph = PatchableGraph()
+    p = Poller(influx, masterGraph)
 
     reactor.listenTCP(
         int(arg['--port']),