# HG changeset patch # User drewp # Date 1463028335 25200 # Node ID 870d1bbae402445906ef9d648b1f319be7a4f566 # Parent 90bf3f11fc2b36fccd223d5fe39120c33310098c more motion sensor statements Ignore-this: 7019e6042e602812057bbffd9dab89b1 darcs-hash:4bc357effae2f3fc976d854be836022f4ad5ff47 diff -r 90bf3f11fc2b -r 870d1bbae402 service/piNode/devices.py --- a/service/piNode/devices.py Wed May 11 21:45:11 2016 -0700 +++ b/service/piNode/devices.py Wed May 11 21:45:35 2016 -0700 @@ -125,7 +125,18 @@ @register class MotionSensorInput(DeviceType): - # compare motion sensor lib at http://pythonhosted.org/gpiozero/inputs/ + """ + 0 30s 60s 90s 10min + | | | | ... | + Sensor input ******** ** ******* **** + :sees output ........ .. ....... .... + :seesRecently ............................................................. + :seesRecently30 .................................... + :motionStart x x x x + :motionStart30 x x + """ + # compare motion sensor lib at + # https://gpiozero.readthedocs.org/en/v1.2.0/api_input.html#motion-sensor-d-sun-pir # which is a bit fancier deviceType = ROOM['MotionSensor'] @@ -135,25 +146,31 @@ def hostStateInit(self): self.lastRead = None + self.lastMotionStart30 = 0 + self.lastMotionStart90 = 0 def poll(self): motion = self.pi.read(17) + now = time.time() oneshot = [] if self.lastRead is not None and motion != self.lastRead: oneshot = [(self.uri, ROOM['sees'], ROOM['motionStart'])] + for v, t in [('lastMotionStart30', 30), ('lastMotionStart90', 90)]: + if now - getattr(self, v) > t: + oneshot.append((self.uri, ROOM['sees'], ROOM['motionStart%s' % t])) + setattr(self, v, now) self.lastRead = motion return {'latest': [ (self.uri, ROOM['sees'], ROOM['motion'] if motion else ROOM['noMotion']), - ] + self.recentMotionStatements(motion), + ] + self.recentMotionStatements(now, motion), 'oneshot': oneshot} - def recentMotionStatements(self, motion): + def recentMotionStatements(self, now, motion): if not hasattr(self, 'lastMotionTime'): self.lastMotionTime = 0 - now = time.time() if motion: self.lastMotionTime = now dt = now - self.lastMotionTime