Commits

Anonymous committed b03b16a

added a test

Comments (0)

Files changed (1)

examples/greenhouse.py

 
 class Siphons(Gadget):
     """
-    I use this Siphons Gadget to control the pumps in
+    I use this Siphons Gadget to control the pump and valves in
     my aquaponics greenhouse.
     """
 
         }
 
     def event_received(self, event, message):
-        sender = message['sender']
+        sender = message.get('sender')
         if sender in self._siphons:
             location = sender.replace(' siphon', '')
             self.sockets.send('turn off {0} valve'.format(location))
         """
         >>> addresses = Addresses()
         >>> siphons = Siphons('na', 'siphons monitor', addresses)
-        
+        >>> msg = {
+        ...    'locations': {
+        ...        'bed one': {
+        ...            'output': {
+        ...                'valve': {
+        ...                    'value': True
+        ...                    }
+        ...                }
+        ...            },
+        ...        'bed two': {
+        ...            'output': {
+        ...                'valve': {
+        ...                    'value': False
+        ...                    }
+        ...                }
+        ...            },
+        ...        'bed three': {
+        ...            'output': {
+        ...                'valve': {
+        ...                    'value': True
+        ...                    }
+        ...                }
+        ...            }
+        ...        }
+        ...    }
+        >>> siphons._all_valves_closed(msg)
+        False
+        >>> msg = {
+        ...    'locations': {
+        ...        'bed one': {
+        ...            'output': {
+        ...                'valve': {
+        ...                    'value': False
+        ...                    }
+        ...                }
+        ...            },
+        ...        'bed two': {
+        ...            'output': {
+        ...                'valve': {
+        ...                    'value': False
+        ...                    }
+        ...                }
+        ...            },
+        ...        'bed three': {
+        ...            'output': {
+        ...                'valve': {
+        ...                    'value': True
+        ...                    }
+        ...                }
+        ...            }
+        ...        }
+        ...    }
+        >>> siphons._all_valves_closed(msg)
+        False
+        >>> msg = {
+        ...    'locations': {
+        ...        'bed one': {
+        ...            'output': {
+        ...                'valve': {
+        ...                    'value': False
+        ...                    }
+        ...                }
+        ...            },
+        ...        'bed two': {
+        ...            'output': {
+        ...                'valve': {
+        ...                    'value': False
+        ...                    }
+        ...                }
+        ...            },
+        ...        'bed three': {
+        ...            'output': {
+        ...                'valve': {
+        ...                    'value': False
+        ...                    }
+        ...                }
+        ...            }
+        ...        }
+        ...    }
+        >>> siphons._all_valves_closed(msg)
+        True
         """
         for siphon in self._siphons:
             location = siphon.replace(' siphon', '')