changeset 1923:feafbe49ca0b

type fixes Ignore-this: 7f9003a6097a2b56c6767ded3360d8ec
author Drew Perttula <drewp@bigasterisk.com>
date Sat, 01 Jun 2019 23:45:25 +0000
parents 11e2f63bb2f2
children 91bcc6c76934
files light9/collector/collector_client.py light9/effect/sequencer.py
diffstat 2 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/light9/collector/collector_client.py	Sat Jun 01 23:43:44 2019 +0000
+++ b/light9/collector/collector_client.py	Sat Jun 01 23:45:25 2019 +0000
@@ -41,10 +41,10 @@
     if _zmqClient is None:
         _zmqClient = TwistedZmqClient(networking.collectorZmq)
     _zmqClient.send(msg)
-    return defer.succeed(0)
+    return defer.succeed(0.0)
 
 
-def sendToCollector(client, session, settings: DeviceSettings, useZmq=False):
+def sendToCollector(client, session, settings: DeviceSettings, useZmq=False) -> defer.Deferred:
     """deferred to the time in seconds it took to get a response from collector"""
     sendTime = time.time()
     msg = toCollectorJson(client, session, settings).encode('utf8')
--- a/light9/effect/sequencer.py	Sat Jun 01 23:43:44 2019 +0000
+++ b/light9/effect/sequencer.py	Sat Jun 01 23:45:25 2019 +0000
@@ -11,7 +11,7 @@
 import cyclone.sse
 import logging, bisect, time
 import traceback
-from typing import Any, Callable, Dict, List, Tuple, cast
+from typing import Any, Callable, Dict, List, Tuple, cast, Union
 
 from light9.namespaces import L9, RDF
 from light9.newtypes import DeviceUri, DeviceAttr, NoteUri, Curve, Song
@@ -109,11 +109,16 @@
             'note': str(self.uri),
             'effectClass': self.effectEval.effect,
         }
-        effectSettings = self.baseEffectSettings.copy()
+        effectSettings: Dict[DeviceAttr, Union[float, str]] = dict(
+            (DeviceAttr(da), v.toPython()) for da, v in self.baseEffectSettings.items())
         effectSettings[L9['strength']] = self.evalCurve(t)
+        def prettyFormat(x: Union[float, str]):
+            if isinstance(x, float):
+                return round(x, 4)
+            return x
         report['effectSettings'] = dict(
-            (str(k), str(round(v, 4))) for k, v in sorted(effectSettings.items()))
-        report['nonZero'] = effectSettings[L9['strength']] > 0
+            (str(k), prettyFormat(v)) for k, v in sorted(effectSettings.items()))
+        report['nonZero'] = cast(float, effectSettings[L9['strength']]) > 0
         out, evalReport = self.effectEval.outputFromEffect(
             list(effectSettings.items()),
             songTime=t,
@@ -149,7 +154,7 @@
 
     def __init__(self,
                  graph: SyncedGraph,
-                 sendToCollector: Callable[[DeviceSettings], None],
+                 sendToCollector: Callable[[DeviceSettings], defer.Deferred[float]],
                  fps=40):
         self.graph = graph
         self.fps = fps
@@ -161,7 +166,7 @@
         self.recentUpdateTimes: List[float] = []
         self.lastStatLog = 0.0
         self._compileGraphCall = None
-        self.notes: Dict[URIRef, List[Note]] = {}  # song: [notes]
+        self.notes: Dict[Song, List[Note]] = {}  # song: [notes]
         self.simpleOutputs = SimpleOutputs(self.graph)
         self.graph.addHandler(self.compileGraph)
         self.updateLoop()
@@ -172,10 +177,7 @@
     @compileStats.graph.time()
     def compileGraph(self) -> None:
         """rebuild our data from the graph"""
-        t1 = time.time()
-        g = self.graph
-
-        for song in g.subjects(RDF.type, L9['Song']):
+        for song in self.graph.subjects(RDF.type, L9['Song']):
             def compileSong(song: Song = cast(Song, song)) -> None:
                 self.compileSong(song)
             self.graph.addHandler(compileSong)
@@ -210,8 +212,7 @@
         def err(e):
             log.warn('updateLoop: %r', e)
             reactor.callLater(2, self.updateLoop)
-
-        d = self.update()
+        
         d.addCallbacks(done, err)
 
     @updateStats.updateFps.rate()