Commits

Anonymous committed 8f5ddc1

added name attribute to gadgets

Comments (0)

Files changed (12)

gadgets/__init__.py

-
 import time
+import platform
 
 from gadgets.gadget import Gadget
 from gadgets.sockets import Sockets, Addresses, Broker
     
     """
 
-    def __init__(self, gadgets, addresses=None, ensure_off=False):
+    def __init__(self, gadgets, addresses=None, ensure_off=False, name=None):
+        if name is None:
+            name = platform.node()
+        self._name = name
         self._gadgets = gadgets
         self._ensure_off = ensure_off
         if addresses is not None:
             broker = Broker(self._addresses)
             broker.start()
             time.sleep(0.2)
-            self.coordinator = Coordinator(self._addresses)
+            self.coordinator = Coordinator(self._addresses, self._name)
             self.coordinator.start()
         for gadget in self._gadgets:
             gadget.start()

gadgets/coordinator.py

             })
     """
 
-    def __init__(self, addresses):
+    def __init__(self, addresses, name):
         self._addresses = addresses
+        self._name = name
         self._ids = []
 
         self._sockets = None
             }
         
         self._state = {
+            'name': self._name,
             'locations': defaultdict(dict),
             'method': {},
             'errors': []

gadgets/devices/input/adc.py

     def events(self):
         return []
 
+    @property
+    def value(self):
+        return False
+
     def event_received(self, event, message):
         pass 
 

gadgets/tests/test_coordinator.py

     def setup(self):
         port = random.randint(5000, 50000)
         self.addresses = Addresses(in_port=port, out_port=port + 1)
-        self.coordinator = Coordinator(self.addresses)
+        self.coordinator = Coordinator(self.addresses, 'testsys')
 
     def test_create(self):
         pass

gadgets/tests/test_float_trigger.py

 
     def __init__(self, *args, **kw):
         pass
+    
+    @property
+    def value(self):
+        return False
 
     def wait(self):
         time.sleep(0.4)
     def close(self):
         pass
 
+    
+
 class TestFloatTrigger(object):
 
     def setup(self):

gadgets/tests/test_gadgets.py

         event, message = sockets.recv()
         sockets.send('shutdown')
         eq_(event, uid + ' status')
-        eq_(message, {u'errors': [], u'locations': {u'back yard': {u'sprinklers': {u'value': True}}}, u'method': {}})
+        eq_(message, {u'name': u'pjoe', u'errors': [], u'locations': {u'back yard': {u'sprinklers': {u'value': True}}}, u'method': {}})
 

gadgets/tests/test_input.py

     def close(self):
         pass
 
+    @property
+    def value(self):
+        return False
+
 class TestInput(object):
 
     def setup(self):
         time.sleep(1)
         event, message = self.sockets.recv()
         eq_(event, 'update')
-        expected = {u'left': {u'input': {u'input': {u'value': u'open', u'units': u'boolean'}}}}
+        expected = {u'left': {u'input': {u'input': {u'value': False, u'units': u'boolean'}}}}
         eq_(message, expected)
         self.sockets.send('shutdown')

gadgets/tests/test_input_adc.py

         self._target = target
         super(FakeADC, self).__init__()
 
+    @property
+    def value(self):
+        return False
+
     def run(self):
         time.sleep(2)
         self._target(2046)

gadgets/tests/test_thermometer.py

         eq_(event, 'test thermometer status')
         expected = {
             u'errors': [],
+            u'name': u'pjoe',
             u'sender': 'living room temperature',
             u'locations': {
                 u'living room': {

gadgets/ui/data_getter.py

         self._target = target
         self._sockets = None
         self.locations = None
+        self.name = None
 
     def do_shutdown(self):
         self._stop_event.set()
         self.sockets.send('status', {'id': self.uid})
         event, status = self.sockets.recv()
         self.locations = status['locations'].keys()
+        self.name = status['name']
         self.sockets.send('events', {'id': self.uid})
         _id, self.commands = self.sockets.recv()
         self._target(status)

gadgets/ui/dialogs/notes.py

     """take some notes"""
 
     _table = '''CREATE TABLE if not exists notes
-             (method_id integer, timestamp integer, notes text)'''
+             (host text, method_id integer, timestamp integer, notes text)'''
 
-    _insert = '''INSERT INTO notes VALUES(?, ?, ?)'''
+    _insert = '''INSERT INTO notes VALUES(?, ?, ?, ?)'''
 
     def __init__(self, socket, lock, db):
+        self.name = None
         self._socket = socket
         self._lock = lock
         db.ensure_table(self._table)
 
     def _save(self, notes, method_id):
         timestamp=datetime.datetime.now()
-        self._db.save(self._insert, (method_id, int(timestamp.strftime('%s')), notes))
+        self._db.save(self._insert, (self._name, method_id, int(timestamp.strftime('%s')), notes))
 
     def __call__(self, screen, data, method_id=None):
         self._lock.acquire()
         )
         self.sockets = Sockets(addresses)
         self._lock = threading.RLock()
+        self._name = name
         self._title_bar_string = 'help: h  quit: q'
         self._location_names = locations
         self._stop = False
             time.sleep(0.1)
         if self._location_names == []:
             self._location_names = self._getter.locations
+        self._name = self._getter.name
+        notes = self._dialogs['n']
+        notes.name = self._name
         self._row, self._col = self._get_center(screen)
         self._lock.release()
         self._draw()
         x = 'go'
-        
         while x != ord('q'):
             x = self._screen.getch()
             if self._command_mode.is_active: