Mercurial > code > home > repos > homeauto
changeset 1439:233a07f068a8
piNode to py3
Ignore-this: c04a6b87bb776997781404c7e76898d4
darcs-hash:5b1439a8dcebf562fb65368c8db74d194e05301a
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Mon, 12 Aug 2019 10:07:49 -0700 |
parents | 07b5df124209 |
children | 2e9361f233f2 |
files | service/piNode/Dockerfile service/piNode/Dockerfile.check service/piNode/devices.py service/piNode/piNode.py |
diffstat | 4 files changed, 39 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/service/piNode/Dockerfile Mon Aug 12 02:23:15 2019 -0700 +++ b/service/piNode/Dockerfile Mon Aug 12 10:07:49 2019 -0700 @@ -7,15 +7,17 @@ COPY requirements.txt ./ -RUN pip install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt +RUN pip3 install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt +## not sure why this doesn't work from inside requirements.txt +RUN pip3 install -U 'https://github.com/drewp/cyclone/archive/python3.zip?v3' -# when we go to py3: -## not sure why this doesn't work from inside requirements.txt -#RUN pip3 install -U 'https://github.com/drewp/cyclone/archive/python3.zip?v3' +# fold these into requirements.txt +RUN pip3 install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple "devices_shared==0.4.0" +RUN apt install -y vim COPY *.py ./ COPY config/ ./config/ EXPOSE 9059 -CMD [ "python", "./piNode.py" ] +CMD [ "python3", "./piNode.py" ]
--- a/service/piNode/Dockerfile.check Mon Aug 12 02:23:15 2019 -0700 +++ b/service/piNode/Dockerfile.check Mon Aug 12 10:07:49 2019 -0700 @@ -1,15 +1,21 @@ FROM bang6:5000/base_x86 -RUN pip install grpcio==1.22.0 +RUN pip3 install grpcio==1.22.0 WORKDIR /opt COPY requirements.txt ./ RUN egrep -v ws281 requirements.txt > requirements_x86_ok.txt -RUN pip install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements_x86_ok.txt +RUN pip3 install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements_x86_ok.txt +RUN pip3 install -U 'https://github.com/drewp/cyclone/archive/python3.zip?v3' + -RUN pip install pytype +RUN pip3 install pytype +RUN pip3 install mypy + COPY *.py ./ COPY config/ ./config/ + +# mypy piNode.py
--- a/service/piNode/devices.py Mon Aug 12 02:23:15 2019 -0700 +++ b/service/piNode/devices.py Mon Aug 12 10:07:49 2019 -0700 @@ -1,8 +1,6 @@ """ https://github.com/juniorug/libsensorPy is a similar project """ -from __future__ import division - import time, logging, os from rdflib import Namespace, URIRef, Literal from twisted.internet import reactor, threads @@ -263,10 +261,11 @@ def sendOutput(self, statements): assert len(statements) == 1 - assert statements[0][:2] == (self.uri, ROOM['color']) + stmt = list(statements)[0] + assert stmt[:2] == (self.uri, ROOM['color']) - rgb = self._rgbFromHex(statements[0][2]) - self.value = statements[0][2] + rgb = self._rgbFromHex(stmt[2]) + self.value = stmt[2] for (i, v) in zip(self.rgb, rgb): self.pi.set_PWM_dutycycle(i, v) @@ -485,8 +484,9 @@ def sendOutput(self, statements): assert len(statements) == 1 - assert statements[0][:2] == (self.uri, ROOM['brightness']) - self.value = float(statements[0][2]) + stmt = list(statements)[0] + assert stmt[:2] == (self.uri, ROOM['brightness']) + self.value = float(stmt[2]) self.fv.set(self.value) def _setPwm(self, x): @@ -571,7 +571,7 @@ for idx, (r, g, b) in colors: if idx < 4: log.debug('out color %s (%s,%s,%s)', idx, r, g, b) - self.neo.setPixelColorRGB(idx, r, g, b) + self.neo.setPixelColorRGB(idx, int(r), int(g), int(b)) self.neo.show() @pixelStats.poll.time() @@ -697,10 +697,11 @@ def sendOutput(self, statements): assert len(statements) == 1 - assert statements[0][1] == ROOM['brightness']; - chan = self.outs[statements[0][0]] - value = float(statements[0][2]) - self.values[statements[0][0]] = value + stmt = list(statements)[0] + assert stmt[1] == ROOM['brightness']; + chan = self.outs[stmt[0]] + value = float(stmt[2]) + self.values[stmt[0]] = value self.pwm.set_duty_cycle(chan, value * 100) def outputWidgets(self):
--- a/service/piNode/piNode.py Mon Aug 12 02:23:15 2019 -0700 +++ b/service/piNode/piNode.py Mon Aug 12 10:07:49 2019 -0700 @@ -1,19 +1,17 @@ -from __future__ import division -import sys, logging, socket, json, time, pkg_resources +import logging, socket, json, time, pkg_resources import cyclone.web from cyclone.httpclient import fetch from rdflib import Namespace, URIRef, Literal, Graph, RDF, ConjunctiveGraph from rdflib.parser import StringInputSource -from twisted.internet import reactor, task -from twisted.internet.defer import inlineCallbacks, maybeDeferred, gatherResults, returnValue +from twisted.internet import reactor +from twisted.internet.defer import inlineCallbacks, maybeDeferred, returnValue from twisted.internet.threads import deferToThread from docopt import docopt -from typing import Any -import etcd3 # type: Any +import etcd3 from greplin import scales from greplin.scales.cyclonehandler import StatsHandler - -logging.basicConfig(level=logging.DEBUG) +import pigpio +import treq from patchablegraph import PatchableGraph, CycloneGraphHandler, CycloneGraphEventsHandler from cycloneerr import PrettyErrorHandler @@ -151,6 +149,7 @@ self.graph, self.uri = graph, uri self.hubHost = hubHost self.masterGraph = masterGraph + self.masterGraph.setToGraph(self.staticStmts()) self.pi = pigpio.pi() self._devs = [DeviceRunner(d) for d in devices.makeDevices(graph, self.uri, self.pi)] @@ -296,10 +295,10 @@ else: g = rdfGraphBody(self.request.body, self.request.headers) assert len(g) == 1, len(g) - stmt = g.triples((None, None, None)).next() + stmt = next(g.triples((None, None, None))) for b in self.settings.config.boards: - b.outputStatements([stmt]) + b.outputStatements({stmt}) class Boards(PrettyErrorHandler, cyclone.web.RequestHandler): def get(self): @@ -327,7 +326,7 @@ if arg['--ow']: log.setLevel(logging.INFO) for stmt in devices.OneWire().poll(): - print stmt + print(stmt) return masterGraph = PatchableGraph()