示例#1
0
 def testSensorInfo(self):
     sensors = {
         'actuator': {
             'description': 'Digital Output',
             'device': 'DigitalActuator',
             'args': {
                 'gpio': 'GPIO',
                 'invert': False,
                 'channel': 16
             },
             'name': 'test_actuator'
         },
         'light_switch': {
             'description': 'Light Switch',
             'device': 'LightSwitch',
             'args': {
                 'gpio': 'GPIO',
                 'invert': True,
                 'channel': 15
             },
             'name': 'test_light_switch'
         },
         'MCP3004': {
             'description': 'MCP3004',
             'device': 'MCP3004',
             'args': {
                 'chip': '0'
             },
             'name': 'test_MCP3004'
         },
         'distance': {
             'description': 'Analog Distance Sensor',
             'device': 'DistanceSensor',
             'args': {
                 'adc': 'test_MCP3004',
                 'channel': 0
             },
             'name': 'test_distance'
         }
     }
     for sensor in sensors.values():
         SensorsClientTest.client.AddSensor(sensor['name'],
                                            sensor['description'],
                                            sensor['device'],
                                            sensor['args'])
     SensorsClientTest.client.SensorsInfo()
     #Test setting sensor values
     self.setSensorValue(sensors['actuator'], 1)
     self.setSensorValue(sensors['actuator'], 0)
     self.setSensorValue(sensors['light_switch'], 1)
     self.setSensorValue(sensors['light_switch'], 0)
     #Test getting analog value
     retrievedSensorInfo = next(
         obj for obj in SensorsClientTest.client.SensorsInfo()
         if obj['name'] == sensors['distance']['name'])
     self.assertEqual(retrievedSensorInfo['float'], 0.0)
     for sensor in sensors.values():
         self.assertTrue(
             SensorsClientTest.client.DeleteSensor(sensor['name']))
示例#2
0
 def testSensorCallback(self):
     debug('testSensorCallback')
     self.previousSystemData = None
     self.currentSystemData = None
     self.done = False
     SensorsClientTest.client.SetDataChanged(self.OnDataChanged)
     actuator_channel = GPIO().pins[10]
     sensor_channel = GPIO().pins[11]
     sensors = {
         'actuator': {
             'description': 'Digital Output',
             'device': 'DigitalActuator',
             'args': {
                 'gpio': 'GPIO',
                 'invert': False,
                 'channel': actuator_channel
             },
             'name': 'test_actuator'
         },
         'sensor': {
             'description': 'Digital Input',
             'device': 'DigitalSensor',
             'args': {
                 'gpio': 'GPIO',
                 'invert': False,
                 'channel': sensor_channel
             },
             'name': 'testdevice'
         }
     }
     for sensor in sensors.values():
         SensorsClientTest.client.AddSensor(sensor['name'],
                                            sensor['description'],
                                            sensor['device'],
                                            sensor['args'])
     for i in range(35):
         sleep(1)
         if self.done:
             break
     info('Changed items: {}'.format([
         x for x in self.currentSystemData
         if x not in self.previousSystemData
     ]))
     self.assertNotEqual(self.previousSystemData, self.currentSystemData)
     for sensor in sensors.values():
         self.assertTrue(
             SensorsClientTest.client.RemoveSensor(sensor['name']))
示例#3
0
 def testSensorInfo(self):
     actuator_channel = GPIO().pins[9]
     light_switch_channel = GPIO().pins[9]
     sensors = {
         'actuator': {
             'description': 'Digital Output',
             'device': 'DigitalActuator',
             'args': {
                 'gpio': 'GPIO',
                 'invert': False,
                 'channel': actuator_channel
             },
             'name': 'test_actuator'
         },
         'light_switch': {
             'description': 'Light Switch',
             'device': 'LightSwitch',
             'args': {
                 'gpio': 'GPIO',
                 'invert': True,
                 'channel': light_switch_channel
             },
             'name': 'test_light_switch'
         },
         'MCP3004': {
             'description': 'MCP3004',
             'device': 'MCP3004',
             'args': {
                 'chip': '0'
             },
             'name': 'test_MCP3004'
         },
         'distance': {
             'description': 'Analog Distance Sensor',
             'device': 'DistanceSensor',
             'args': {
                 'adc': 'test_MCP3004',
                 'channel': 0
             },
             'name': 'test_distance'
         }
     }
     for sensor in sensors.values():
         SensorsClientTest.client.AddSensor(sensor['name'],
                                            sensor['description'],
                                            sensor['device'],
                                            sensor['args'])
     SensorsClientTest.client.SensorsInfo()
     #Test setting sensor values
     self.setSensorValue(sensors['actuator'], 1)
     self.setSensorValue(sensors['actuator'], 0)
     self.setSensorValue(sensors['light_switch'], 1)
     self.setSensorValue(sensors['light_switch'], 0)
     #Test getting analog value
     channel = 'dev:{}'.format(sensors['distance']['name'])
     retrievedSensorInfo = next(
         obj for obj in SensorsClientTest.client.SensorsInfo()
         if obj['channel'] == channel)
     self.assertGreaterEqual(retrievedSensorInfo['value'], 0.0)
     self.assertLessEqual(retrievedSensorInfo['value'], 1.0)
     for sensor in sensors.values():
         self.assertTrue(
             SensorsClientTest.client.RemoveSensor(sensor['name']))
示例#4
0
    def testSensorInfo(self):
        debug('testSensorInfo')

        self.config = Config(APP_SETTINGS)
        self.location = self.config.get('Agent', 'Location', "house0_room0_")

        actuator_channel = GPIO().pins[10]
        light_switch_channel = GPIO().pins[11]

        adcSensors = {}

        for sensor in adcSensors.values():
            info('--------{} {} {}'.format(sensor['name'],
                                           sensor['description'],
                                           sensor['device']))
            SensorsClientTest.client.AddSensor(sensor['name'],
                                               sensor['description'],
                                               sensor['device'],
                                               sensor['args'])

        sensors = {
            'PCF8591': {
                'description': 'PCF8591',
                'index': 0,
                'device': 'PCF8591',
                'args': {},
                'name': 'adc'
            },
            'distance': {
                'description': 'distance',
                'index': 1,
                'device': 'VL6180X',
                'args': {},
                'name': self.location + 'distance'
            },
            'object_temperature': {
                'description': 'ir_body_temperature',
                'index': 2,
                'device': 'MLX90614',
                'args': {
                    'obj_temp': True
                },
                'name': self.location + 'ir_body'
            },
            'amb_temperature': {
                'description': 'ir_climate_temperature',
                'index': 3,
                'device': 'MLX90614',
                'args': {
                    'obj_temp': False
                },
                'name': self.location + 'ir_climate'
            },
            'luminosity': {
                'description': 'luminosity',
                'index': 4,
                'device': 'GY30',
                'args': {},
                'name': self.location + 'luminosity'
            },
            'co2': {
                'description': 'co2',
                'index': 5,
                'device': 'CO2Sensor',
                'args': {
                    'adc': 'adc',
                    'channel': 3
                },
                'name': self.location + 'gas'
            },
            'h2s': {
                'description': 'h2s',
                'index': 6,
                'device': 'MQSensor',
                'args': {
                    'adc': 'adc',
                    'channel': 2
                },
                'name': self.location + 'gas'
            },
            'nh3': {
                'description': 'nh3',
                'index': 6,
                'device': 'MQSensor',
                'args': {
                    'adc': 'adc',
                    'channel': 4
                },
                'name': self.location + 'gas'
            },
            'climate': {
                'description': 'climate',
                'index': 7,
                'device': 'BME280',
                'args': {
                    'temperature': True,
                    'pressure': True,
                    'humidity': True
                },
                'name': self.location + 'climate'
            },
        }
        for sensor in sensors.values():
            # info("sensors:{}".format(sensor))
            SensorsClientTest.client.RemoveSensor(sensor['name'])

        for sensor in sensors.values():
            info('--------{} {} {}'.format(sensor['name'],
                                           sensor['description'],
                                           sensor['device']))
            SensorsClientTest.client.AddSensor(sensor['name'],
                                               sensor['description'],
                                               sensor['device'],
                                               sensor['args'])
        # SensorsClientTest.client.SensorsInfo()
        #Test setting sensor values
        # self.setSensorValue(sensors['actuator'], 1)
        # self.setSensorValue(sensors['actuator'], 0)
        # self.setSensorValue(sensors['light_switch'], 1)
        # self.setSensorValue(sensors['light_switch'], 0)
        #Test getting analog value
        # channel = 'dev:{}'.format(sensors['MQ']['name'])
        # info(" channel -----> {} ".format(channel))
        count = 0
        while count < 1:
            info("new loop for SensorsInfo")
            sleep(5)
            for obj in SensorsClientTest.client.SensorsInfo():
                info(obj)
            count = count + 1