changeset 205:40000fafad94

piNode onboard temp Ignore-this: 2e603499925ff5a114273057a07fb36a
author drewp@bigasterisk.com
date Sat, 07 Nov 2015 09:50:00 -0800
parents 9a3b8f1aaf78
children aa98ff8b147c
files service/piNode/config.n3 service/piNode/devices.py
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/service/piNode/config.n3	Sun Oct 04 04:19:26 2015 -0700
+++ b/service/piNode/config.n3	Sat Nov 07 09:50:00 2015 -0800
@@ -9,6 +9,7 @@
 
 ha:node2 a :PiBoard;
   :hostname "sticker";
+  :onboardDevice ha:bedroomPiTemp .
   :hasPin
     board2pin:GPIO2,
     board2pin:GPIO3,
@@ -17,6 +18,8 @@
     board2pin:GPIO27
     .
 
+ha:bedroomPiTemp a :OnboardTemperature .
+
 board2pin:GPIO2 :gpioNumber 2 .
 board2pin:GPIO3 :gpioNumber 3 .
 board2pin:GPIO4 :gpioNumber 4 .
--- a/service/piNode/devices.py	Sun Oct 04 04:19:26 2015 -0700
+++ b/service/piNode/devices.py	Sat Nov 07 09:50:00 2015 -0800
@@ -176,6 +176,31 @@
             'pred': ROOM['color'],
         }]
 
+@register
+class OnboardTemperature(DeviceType):
+    deviceType = ROOM['OnboardTemperature']
+    @classmethod
+    def findInstances(cls, graph, board, pi):
+        for row in graph.query('''SELECT DISTINCT ?dev WHERE {
+          ?board :onboardDevice ?uri . 
+          ?uri a :OnboardTemperature .
+        }'''):
+            yield cls(graph, row.uri, pi, pinNumber=None)
+    
+    def readFromPoll(self):
+        milliC = open('/sys/class/thermal/thermal_zone0/temp').read().strip()
+        c = float(milliC) / 1000.
+        f = c * 1.8 + 32
+        return [
+            (self.uri, ROOM['temperatureF'], Literal(f, datatype=XSD['decimal'])),
+            ]
+
+    def watchPrefixes(self):
+        # these uris will become dynamic! see note on watchPrefixes
+        # about eliminating it.
+        return [(self.uri, ROOM['temperatureF']),
+                ]
+        
 def makeDevices(graph, board, pi):
     out = []
     for dt in sorted(_knownTypes, key=lambda cls: cls.__name__):