Mercurial > code > home > repos > homeauto
comparison service/arduinoNode/devices.py @ 981:d9bbbd8d86f6
arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body
Ignore-this: 744c3c7d95655430b8ec547e56f6b4bc
darcs-hash:20150514082612-312f9-f77a103ef67321aa5a0ffd7991b92befd5dac37f
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Thu, 14 May 2015 01:26:12 -0700 |
parents | 03cfee8f9154 |
children | 2161c71c7b02 |
comparison
equal
deleted
inserted
replaced
980:2f1cb8b5950a | 981:d9bbbd8d86f6 |
---|---|
1 from __future__ import division | 1 from __future__ import division |
2 import itertools | 2 import itertools |
3 from rdflib import Namespace, RDF, URIRef, Literal | 3 from rdflib import Namespace, RDF, URIRef, Literal |
4 import time | |
4 | 5 |
5 ROOM = Namespace('http://projects.bigasterisk.com/room/') | 6 ROOM = Namespace('http://projects.bigasterisk.com/room/') |
6 XSD = Namespace('http://www.w3.org/2001/XMLSchema#') | 7 XSD = Namespace('http://www.w3.org/2001/XMLSchema#') |
7 | 8 |
8 def readLine(read): | 9 def readLine(read): |
162 def readFromPoll(self, read): | 163 def readFromPoll(self, read): |
163 b = read(1) | 164 b = read(1) |
164 if b not in 'yn': | 165 if b not in 'yn': |
165 raise ValueError('unexpected response %r' % b) | 166 raise ValueError('unexpected response %r' % b) |
166 motion = b == 'y' | 167 motion = b == 'y' |
167 return [(self.uri, ROOM['sees'], | 168 |
168 ROOM['motion'] if motion else ROOM['noMotion'])] | 169 return [ |
169 | 170 (self.uri, ROOM['sees'], |
171 ROOM['motion'] if motion else ROOM['noMotion']), | |
172 self.recentMotionStatement(motion), | |
173 ] | |
174 | |
175 def recentMotionStatement(self, motion): | |
176 if not hasattr(self, 'lastMotionTime'): | |
177 self.lastMotionTime = 0 | |
178 now = time.time() | |
179 if motion: | |
180 self.lastMotionTime = now | |
181 recentMotion = now - self.lastMotionTime < 60 * 10 | |
182 return (self.uri, ROOM['seesRecently'], | |
183 ROOM['motion'] if recentMotion else ROOM['noMotion']) | |
184 | |
170 def watchPrefixes(self): | 185 def watchPrefixes(self): |
171 return [(self.uri, ROOM['sees'])] | 186 return [ |
187 (self.uri, ROOM['sees']), | |
188 (self.uri, ROOM['seesRecently']), | |
189 ] | |
172 | 190 |
173 @register | 191 @register |
174 class OneWire(DeviceType): | 192 class OneWire(DeviceType): |
175 """ | 193 """ |
176 A OW bus with temperature sensors (and maybe other devices, which | 194 A OW bus with temperature sensors (and maybe other devices, which |