changeset 1876:8da5b4edcb7e

type fixes, especially for collector_client Ignore-this: c4ad6f85a477fc034ceb6e996e701de8
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 27 May 2019 07:03:27 +0000
parents 382d3c747003
children d01e21621975
files bin/keyboardcomposer light9/collector/collector_client.py light9/networking.py
diffstat 3 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/bin/keyboardcomposer	Mon May 27 07:02:57 2019 +0000
+++ b/bin/keyboardcomposer	Mon May 27 07:03:27 2019 +0000
@@ -9,7 +9,7 @@
 from twisted.web import resource
 from rdflib import URIRef, Literal
 import tkinter.tix as tk
-from typing import Dict, Tuple, List
+from typing import Any, Dict, Tuple, List
 
 from light9.Fadable import Fadable
 from light9.subclient import SubClient
@@ -181,7 +181,7 @@
 
 class KeyboardComposer(tk.Frame, SubClient):
 
-    def __init__(self, root, graph, session, hw_sliders=True):
+    def __init__(self, root: tk.Tk, graph: SyncedGraph, session: URIRef, hw_sliders=True):
         tk.Frame.__init__(self, root, bg='black')
         SubClient.__init__(self)
         self.graph = graph
@@ -239,7 +239,7 @@
         self.sub_name = tk.Entry(self.buttonframe, bg='black', fg='white')
         self.sub_name.pack(side=tk.LEFT)
 
-    def redraw_sliders(self):
+    def redraw_sliders(self) -> None:
         self.draw_sliders()
         if len(self.rows):
             self.change_row(self.current_row)
@@ -372,7 +372,7 @@
             self.graph.value(self.session, L9['currentRow'], default=0)),
                         fromGraph=True)
 
-    def change_row(self, row, fromGraph=False):
+    def change_row(self, row: int, fromGraph=False) -> None:
         old_row = self.current_row
         self.current_row = row
         self.current_row = max(0, self.current_row)
@@ -633,7 +633,7 @@
             self.valueOut(name, 0)
 
 
-def launch(opts, root, graph, session):
+def launch(opts: Any, root: tk.Tk, graph: SyncedGraph, session: URIRef):
     tl = toplevelat("Keyboard Composer - %s" % opts.session,
                     existingtoplevel=root,
                     graph=graph,
--- a/light9/collector/collector_client.py	Mon May 27 07:02:57 2019 +0000
+++ b/light9/collector/collector_client.py	Mon May 27 07:03:27 2019 +0000
@@ -20,7 +20,7 @@
         self.conn.push(msg)
 
 
-def toCollectorJson(client, session, settings):
+def toCollectorJson(client, session, settings) -> str:
     assert isinstance(settings, DeviceSettings)
     return json.dumps({
         'settings': settings.asList(),
@@ -41,7 +41,7 @@
 def sendToCollector(client, session, settings, useZmq=False):
     """deferred to the time in seconds it took to get a response from collector"""
     sendTime = time.time()
-    msg = toCollectorJson(client, session, settings)
+    msg = toCollectorJson(client, session, settings).encode('utf8')
 
     if useZmq:
         d = sendToCollectorZmq(msg)
--- a/light9/networking.py	Mon May 27 07:02:57 2019 +0000
+++ b/light9/networking.py	Mon May 27 07:03:27 2019 +0000
@@ -1,3 +1,4 @@
+from rdflib import URIRef
 from urllib.parse import urlparse
 from .showconfig import getGraph, showUri
 from .namespaces import L9
@@ -8,14 +9,15 @@
     def __init__(self, service):
         self.service = service
 
-    def _url(self):
+    def _url(self) -> URIRef:
         graph = getGraph()
         net = graph.value(showUri(), L9['networking'])
         ret = graph.value(net, self.service)
         if ret is None:
             raise ValueError("no url for %s -> %s -> %s" %
                              (showUri(), L9['networking'], self.service))
-        return str(ret)
+        assert isinstance(ret, URIRef)
+        return ret
 
     @property
     def port(self):
@@ -26,7 +28,7 @@
         return urlparse(self._url()).hostname
 
     @property
-    def url(self):
+    def url(self) -> URIRef:
         return self._url()
 
     value = url