Esempio n. 1
0
    def EnableSensor(self, sensor, enable):
        """Enable a sensor/actuator

        Args:
            sensor: Hash composed from name and device class/type
            enable: 1 to enable, 0 to disable

        Returns:
            True for success, False otherwise.
        """
        info('Enable sensor: ' + str(sensor) + ' ' + str(enable))
        try:
            if sensor is None:
                return False
            if enable is None:
                return False
            with self.sensorMutex:
                if enable == 0:
                    #add item to the list
                    if sensor not in self.disabledSensors:
                        DbManager.Insert(self.disabledSensorTable, sensor)
                        self.disabledSensors[sensor] = 1
                else:
                    #remove item from the list
                    if sensor in self.disabledSensors:
                        DbManager.Delete(self.disabledSensorTable, sensor)
                        del self.disabledSensors[sensor]
                    #save list
        except Exception as ex:
            error('EnableSensor Failed with exception: '  + str(ex))
            return False
        return True
Esempio n. 2
0
 def EnableSensor(self, sensor, enable):
     #sensor is the hash composed from name and device class/type
     info('Enable sensor: ' + str(sensor) + ' ' + str(enable))
     try:
         if sensor is None:
             return False
         if enable is None:
             return False
         with self.sensorMutex:
             if enable == 0:
                 #add item to the list
                 if sensor not in self.disabledSensors:
                     rowId = DbManager.Insert(self.disabledSensorTable,
                                              sensor)
                     self.disabledSensors[sensor] = 1
             else:
                 #remove item from the list
                 if sensor in self.disabledSensors:
                     DbManager.Delete(self.disabledSensorTable, sensor)
                     del self.disabledSensors[sensor]
                 #save list
     except Exception as ex:
         error('EnableSensor Failed with exception: ' + str(ex))
         return False
     self.AddRefresh()
     return True
Esempio n. 3
0
 def RemoveDbItem(self, id):
     bVal = True
     try:
         with self.mutex:
             DbManager.Delete(self.tablename, id)
     except:
         bVal = False
     return bVal