Mercurial > code > home > repos > homeauto
changeset 1154:5da3a85b59e4
more robust about not accumulating old stmts
Ignore-this: ee8618c8341d028fd7bd3596cd16a43d
darcs-hash:447cf599c2a1633481bc68fc3bc2fa5b8352fbf5
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Mon, 16 Apr 2018 22:16:15 -0700 |
parents | e4f49cd9dda3 |
children | 3d478b05f9b1 |
files | service/piNode/piNode.py |
diffstat | 1 files changed, 16 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/service/piNode/piNode.py Sun Apr 15 04:41:00 2018 -0700 +++ b/service/piNode/piNode.py Mon Apr 16 22:16:15 2018 -0700 @@ -115,7 +115,7 @@ def __init__(self, graph, masterGraph, uri): self.graph, self.uri = graph, uri self.masterGraph = masterGraph - self.masterGraph.patch(Patch(addQuads=self.staticStmts())) + self.masterGraph.setToGraph(self.staticStmts()) self.pi = pigpio.pi() self._devs = devices.makeDevices(graph, self.uri, self.pi) log.debug('found %s devices', len(self._devs)) @@ -148,19 +148,8 @@ new = new['latest'] else: oneshot = None - prev = self._statementsFromInputs.get(i.uri, set()) - if new or prev: - self._statementsFromInputs[i.uri] = new - # it's important that quads from different devices - # don't clash, since that can lead to inconsistent - # patches (e.g. - # dev1 changes value from 1 to 2; - # dev2 changes value from 2 to 3; - # dev1 changes from 2 to 4 but this patch will - # fail since the '2' statement is gone) - self.masterGraph.patch(Patch.fromDiff(inContext(prev, i.uri), - inContext(new, i.uri))) + self._updateMasterWithNewPollStatements(i.uri, new) if oneshot: self._sendOneshot(oneshot) @@ -175,6 +164,20 @@ if pollResults: self._influx.exportToInflux(set.union(*pollResults)) + def _updateMasterWithNewPollStatements(self, dev, new): + prev = self._statementsFromInputs.get(dev, set()) + + # it's important that quads from different devices + # don't clash, since that can lead to inconsistent + # patches (e.g. + # dev1 changes value from 1 to 2; + # dev2 changes value from 2 to 3; + # dev1 changes from 2 to 4 but this patch will + # fail since the '2' statement is gone) + self.masterGraph.patch(Patch.fromDiff(inContext(prev, dev), + inContext(new, dev))) + self._statementsFromInputs[dev] = new + def _sendOneshot(self, oneshot): body = (' '.join('%s %s %s .' % (s.n3(), p.n3(), o.n3()) for s,p,o in oneshot)).encode('utf8')