comparison service/arduinoNode/devices.py @ 268:6103688dce6d

'seesRecently30' in arduinoNode Ignore-this: f89899de0374c9f2b2606d331213465
author drewp@bigasterisk.com
date Thu, 14 Apr 2016 00:14:55 -0700
parents b97495befcab
children 6614416dd2c3
comparison
equal deleted inserted replaced
267:4685fbd208d1 268:6103688dce6d
203 self.lastRead = motion 203 self.lastRead = motion
204 204
205 return {'latest': [ 205 return {'latest': [
206 (self.uri, ROOM['sees'], 206 (self.uri, ROOM['sees'],
207 ROOM['motion'] if motion else ROOM['noMotion']), 207 ROOM['motion'] if motion else ROOM['noMotion']),
208 self.recentMotionStatement(motion), 208 ] + self.recentMotionStatements(motion),
209 ], 'oneshot': oneshot} 209 'oneshot': oneshot}
210 210
211 def recentMotionStatement(self, motion): 211 def recentMotionStatements(self, motion):
212 if not hasattr(self, 'lastMotionTime'): 212 if not hasattr(self, 'lastMotionTime'):
213 self.lastMotionTime = 0 213 self.lastMotionTime = 0
214 now = time.time() 214 now = time.time()
215 if motion: 215 if motion:
216 self.lastMotionTime = now 216 self.lastMotionTime = now
217 recentMotion = now - self.lastMotionTime < 60 * 10 217 dt = now - self.lastMotionTime
218 return (self.uri, ROOM['seesRecently'], 218 return [(self.uri, ROOM['seesRecently'],
219 ROOM['motion'] if recentMotion else ROOM['noMotion']) 219 ROOM['motion'] if (dt < 60 * 10) else ROOM['noMotion']),
220 (self.uri, ROOM['seesRecently30'],
221 ROOM['motion'] if (dt < 30) else ROOM['noMotion'])]
220 222
221 def watchPrefixes(self): 223 def watchPrefixes(self):
222 return [ 224 return [
223 (self.uri, ROOM['sees']), 225 (self.uri, ROOM['sees']),
224 (self.uri, ROOM['seesRecently']), 226 (self.uri, ROOM['seesRecently']),
227 (self.uri, ROOM['seesRecently30']),
225 ] 228 ]
226 229
227 @register 230 @register
228 class PushbuttonInput(DeviceType): 231 class PushbuttonInput(DeviceType):
229 """add a switch to ground; we'll turn on pullup""" 232 """add a switch to ground; we'll turn on pullup"""