Ejemplo n.º 1
0
    def EditSensor(self, name, description, device, args):
        """Edit an existing sensor/actuator
  
        Args:
            name: Name of sensor to edit
            description: New sensor description
            device: New sensor device class
            args: New sensor specific args

        Returns:
            True for success, False otherwise.
        """
        info('EditSensor: {}, {}, {}, {}'.format(name, description, device, args))
        bVal = False
        try:
            sensorEdit = {}
            name = name
            sensorEdit['name'] = name
            sensorEdit['device'] = device
            sensorEdit['description'] = description
            sensorEdit['args'] = args
            with self.sensorMutex:
                retValue = manager.updateDevice(name, sensorEdit)
                self.InitCallbacks()
            info('Edit device returned: {}'.format(retValue))
            if retValue[0] == 200:
                bVal = True
        except:
            exception("Edit sensor failed")
            bVal = False
        return bVal
Ejemplo n.º 2
0
 def EditSensor(self, name, description, device, args):
     info('EditSensor: {}, {}, {}, {}'.format(name, description, device,
                                              args))
     bVal = False
     try:
         sensorEdit = {}
         name = req.pathname2url(name)
         sensorEdit['name'] = name
         sensorEdit['device'] = device
         sensorEdit['description'] = description
         sensorEdit['args'] = args
         with self.sensorMutex:
             retValue = manager.updateDevice(name, sensorEdit)
         info('Edit device returned: {}'.format(retValue))
         try:
             hashKey = self.SHA_Calc_str(name + device)
             with self.sensorMutex:
                 if self.currentSensorsInfo:
                     currentSensorsDictionary = dict(
                         (i['sensor'], i) for i in self.currentSensorsInfo)
                     sensorData = currentSensorsDictionary[hashKey]
                     sensor = sensorData[hashKey]
                     raspberryValue = {}
                     sensor['args'] = args
                     sensor['description'] = description
                     raspberryValue['SensorsInfo'] = []
                     raspberryValue['SensorsInfo'].append(sensor)
                     if self.onDataChanged != None:
                         self.onDataChanged(raspberryValue)
         except:
             pass
         if retValue[0] == 200:
             bVal = True
             self.AddRefresh()
     except:
         exception("Edit sensor failed")
         bVal = False
     return bVal