diff --git a/light9/collector/collector.py b/light9/collector/collector.py --- a/light9/collector/collector.py +++ b/light9/collector/collector.py @@ -54,6 +54,8 @@ class Collector(Generic[ClientType, Clie 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 @@ class Collector(Generic[ClientType, Clie 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 @@ class Collector(Generic[ClientType, Clie 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 @@ class Collector(Generic[ClientType, Clie 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) diff --git a/light9/collector/collector_test.py b/light9/collector/collector_test.py --- a/light9/collector/collector_test.py +++ b/light9/collector/collector_test.py @@ -219,8 +219,8 @@ class TestCollector(unittest.TestCase): 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', diff --git a/light9/collector/web/index.html b/light9/collector/web/index.html --- a/light9/collector/web/index.html +++ b/light9/collector/web/index.html @@ -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'));