Mercurial > code > home > repos > homeauto
diff 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 |
line wrap: on
line diff
--- a/service/arduinoNode/devices.py Sun May 03 17:21:20 2015 -0700 +++ b/service/arduinoNode/devices.py Thu May 14 01:26:12 2015 -0700 @@ -1,6 +1,7 @@ from __future__ import division import itertools from rdflib import Namespace, RDF, URIRef, Literal +import time ROOM = Namespace('http://projects.bigasterisk.com/room/') XSD = Namespace('http://www.w3.org/2001/XMLSchema#') @@ -164,11 +165,28 @@ if b not in 'yn': raise ValueError('unexpected response %r' % b) motion = b == 'y' - return [(self.uri, ROOM['sees'], - ROOM['motion'] if motion else ROOM['noMotion'])] + + return [ + (self.uri, ROOM['sees'], + ROOM['motion'] if motion else ROOM['noMotion']), + self.recentMotionStatement(motion), + ] + def recentMotionStatement(self, motion): + if not hasattr(self, 'lastMotionTime'): + self.lastMotionTime = 0 + now = time.time() + if motion: + self.lastMotionTime = now + recentMotion = now - self.lastMotionTime < 60 * 10 + return (self.uri, ROOM['seesRecently'], + ROOM['motion'] if recentMotion else ROOM['noMotion']) + def watchPrefixes(self): - return [(self.uri, ROOM['sees'])] + return [ + (self.uri, ROOM['sees']), + (self.uri, ROOM['seesRecently']), + ] @register class OneWire(DeviceType):