Mercurial > code > home > repos > homeauto
comparison service/reasoning/actions.py @ 1560:c3d699b5759c
more py3 fixes
Ignore-this: f212b4a5edf8e599e9efd70bc65e7651
darcs-hash:d944ca9d7d7b36c2c02529dcf9225a99c0aa1831
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Fri, 14 Feb 2020 00:33:31 -0800 |
parents | d36d3b9ae516 |
children | c8562ace4917 |
comparison
equal
deleted
inserted
replaced
1559:6047a660ef76 | 1560:c3d699b5759c |
---|---|
70 log.debug('putDevices: stmt %s leads to putting at %s', | 70 log.debug('putDevices: stmt %s leads to putting at %s', |
71 ntStatement(stmt), putUrl.n3()) | 71 ntStatement(stmt), putUrl.n3()) |
72 self._put(putUrl + '?' + urllib.parse.urlencode([ | 72 self._put(putUrl + '?' + urllib.parse.urlencode([ |
73 ('s', str(stmt[0])), | 73 ('s', str(stmt[0])), |
74 ('p', str(putPred))]), | 74 ('p', str(putPred))]), |
75 str(stmt[2].toPython()), | 75 payload=str(stmt[2].toPython()), |
76 agent=agentFor.get(stmt[0], None), | 76 agent=agentFor.get(stmt[0], None), |
77 refreshSecs=self._getRefreshSecs(stmt[0])) | 77 refreshSecs=self._getRefreshSecs(stmt[0])) |
78 activated.add((stmt[0], | 78 activated.add((stmt[0], |
79 # didn't test that this should be | 79 # didn't test that this should be |
80 # stmt[1] and not putPred | 80 # stmt[1] and not putPred |
144 # should be able to map(secsFromLiteral) in here somehow and | 144 # should be able to map(secsFromLiteral) in here somehow and |
145 # remove the workaround in httpputoutputs.currentRefreshSecs | 145 # remove the workaround in httpputoutputs.currentRefreshSecs |
146 return self.inputGraph.rxValue(target, ROOM['refreshPutValue'], | 146 return self.inputGraph.rxValue(target, ROOM['refreshPutValue'], |
147 default=Literal('30s'))#.map(secsFromLiteral) | 147 default=Literal('30s'))#.map(secsFromLiteral) |
148 | 148 |
149 def _put(self, url, payload, refreshSecs, agent=None): | 149 def _put(self, url, payload: str, refreshSecs, agent=None): |
150 if isinstance(payload, str): | |
151 payload = payload.encode('utf8') | |
152 assert isinstance(payload, bytes) | |
153 self.putOutputs.put(url, payload, agent, refreshSecs) | 150 self.putOutputs.put(url, payload, agent, refreshSecs) |
154 | 151 |
155 import cyclone.sse | 152 import cyclone.sse |
156 | 153 |
157 class PutOutputsTable(cyclone.sse.SSEHandler): | 154 class PutOutputsTable(cyclone.sse.SSEHandler): |
167 self.bound = False | 164 self.bound = False |
168 | 165 |
169 def loop(self): | 166 def loop(self): |
170 if not self.bound: | 167 if not self.bound: |
171 return | 168 return |
172 | 169 puts = { |
173 self.sendEvent(message=json.dumps({ | |
174 'puts': [row.report() for _, row in | 170 'puts': [row.report() for _, row in |
175 sorted(self.actions.putOutputs.state.items())], | 171 sorted(self.actions.putOutputs.state.items())], |
176 }), event='update') | 172 } |
173 self.sendEvent(message=json.dumps(puts).encode('utf8'), event=b'update') | |
177 reactor.callLater(1, self.loop) | 174 reactor.callLater(1, self.loop) |