changeset 1542:60e559cb1a5e

collector now runs the device function even on devs that have no settings, in case they have some fixed output values (e.g. light mode) Ignore-this: f13d891964f1a3274f63a52684b4c896
author Drew Perttula <drewp@bigasterisk.com>
date Wed, 17 May 2017 08:02:58 +0000
parents c1bf296b0a74
children c8cffe82b537
files light9/collector/collector.py light9/collector/collector_test.py light9/collector/web/index.html
diffstat 3 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/light9/collector/collector.py	Wed May 17 07:39:21 2017 +0000
+++ b/light9/collector/collector.py	Wed May 17 08:02:58 2017 +0000
@@ -54,6 +54,8 @@
         self.outputs = outputs
         self.listeners = listeners
         self.clientTimeoutSec = clientTimeoutSec
+        self.initTime = time.time()
+        self.allDevices = set()
 
         self.graph.addHandler(self.rebuildOutputMap)
 
@@ -69,6 +71,7 @@
         self.remapOut = {} # (device, deviceAttr) : (start, end)
         for dc in self.graph.subjects(RDF.type, L9['DeviceClass']):
             for dev in self.graph.subjects(RDF.type, dc):
+                self.allDevices.add(dev)
                 self.deviceType[dev] = dc
 
                 for remap in self.graph.objects(dev, L9['outputAttrRange']):
@@ -99,7 +102,7 @@
 
     def _warnOnLateRequests(self, client, now, sendTime):
         requestLag = now - sendTime
-        if requestLag > .1:
+        if requestLag > .1 and now > self.initTime + 5:
             log.warn('collector.setAttrs from %s is running %.1fms after the request was made',
                      client, requestLag * 1000)
         
@@ -145,13 +148,13 @@
                 daDict[da] = v
                     
         outputAttrs = {} # device: {outputAttr: value}
-        for d in deviceAttrs:
+        for d in self.allDevices:
             try:
                 devType = self.deviceType[d]
             except KeyError:
                 log.warn("request for output to unconfigured device %s" % d)
                 continue
-            outputAttrs[d] = toOutputAttrs(devType, deviceAttrs[d])
+            outputAttrs[d] = toOutputAttrs(devType, deviceAttrs.get(d, {}))
             if self.listeners:
                 self.listeners.outputAttrsSet(d, outputAttrs[d], self.outputMap)
         
--- a/light9/collector/collector_test.py	Wed May 17 07:39:21 2017 +0000
+++ b/light9/collector/collector_test.py	Wed May 17 08:02:58 2017 +0000
@@ -219,8 +219,8 @@
         c.setAttrs('client1', 'sess1', [(DEV['inst1'], L9['brightness'], 1)], t0)
         c.setAttrs('client1', 'sess1', [(DEV['colorStrip'], L9['color'], '#00ff00')], t0)
 
-        self.assertEqual([[0, 0, 0, 0], 'flush',
-                          [0, 0, 0, 0], 'flush',
+        self.assertEqual([[215, 0, 0, 0], 'flush',
+                          [215, 0, 0, 0], 'flush',
                           [215, 0, 255, 0], 'flush'],
                          self.udmx.updates)
         self.assertEqual([[127, 0, 0, 0], 'flush',
--- a/light9/collector/web/index.html	Wed May 17 07:39:21 2017 +0000
+++ b/light9/collector/web/index.html	Wed May 17 08:02:58 2017 +0000
@@ -56,6 +56,7 @@
                    graph: {type: Object, notify: true},
                    uri: {type: String, notify: true},
                    label: {type: String, notify: true},
+                   attrs: {type: Array, notify: true},
                },
                observers: [
                    "setLabel(graph, uri)",
@@ -64,7 +65,7 @@
                initUpdates: function(updates) {
                    updates.addListener(function(msg) {
                        if (msg.outputAttrsSet && msg.outputAttrsSet.dev == this.uri) {
-                           this.attrs = msg.outputAttrsSet.attrs;
+                           this.set('attrs', msg.outputAttrsSet.attrs);
                            this.attrs.forEach(function(row) {
                                row.valClass = row.val == 255 ? 'full' : (row.val ? 'nonzero' : '');
                            });
@@ -72,7 +73,6 @@
                    }.bind(this));
                },
                setLabel: function(graph, uri) {
-                   console.log('setlab', uri);
                    this.label = uri.replace(/.*\//, '');
                    graph.runHandler(function() {
                        this.label = graph.stringValue(uri, graph.Uri('rdfs:label'));