Commits

Craig Swank committed d5ba6e2 Merge

Merge branch 'master' of bitbucket.org:cswank/gadgets

  • Participants
  • Parent commits 401a790, 0e85953

Comments (0)

Files changed (1)

File examples/greenhouse.py

 
     def event_received(self, event, message):
         sender = message.get('sender')
-        if sender in self._float_switches and self._float_switch_is_open(sender, message):
+        
+        if sender in self._float_switches and self._float_switch_is_open(sender, message) and not self._too_cold:
             location = sender.replace(' float_switch', '')
             self.sockets.send('turn off {0} pump'.format(location))
             self._start_timer(location)
+        elif sender == 'greenhouse temperature':
+            self._check_temperature(message):
+
+    def _check_temperature(self, message):
+        t = self._get_greenhouse_temperature(message)
+        print 'is too cold?', t
+        if t < 15:
+            self._too_cold = True
+            self.sockets.send('turn on bed one pump')
+            self.sockets.send('turn off bed two pump')
+            self.sockets.send('turn off bed three pump')
+        else:
+            self._too_cold = False
+                        
+
+    def _greenhouse_temperature(self, message):
+        """
+        
+        """
+        return message.get('locations', {}).get('greenhouse', {}).get('temperature', {}).get('value')
 
     def _float_switch_is_open(self, sender, message):
         location = sender.replace(' float_switch', '')
         return ['UPDATE']
 
     def on_start(self):
+        self._too_cold = False
         self.sockets.send('turn on bed one pump')
         self.sockets.send('turn on bed two pump')
         self.sockets.send('turn on bed three pump')