예제 #1
0
    def test_sensors(self):
        self.sensor_index = 0
        def tdSensor(protocol, p_len, model, m_len, id, datatypes):
            sensors = [{'protocol': b"proto_1", 'model': b"model_1", 'id': 1,
                        'datatypes': TELLSTICK_TEMPERATURE},
                       {'protocol': b"proto_2", 'model': b"model_2", 'id': 2,
                        'datatypes': TELLSTICK_TEMPERATURE},
                       {'protocol': b"proto_3", 'model': b"model_3", 'id': 3,
                        'datatypes': TELLSTICK_HUMIDITY}]
            if self.sensor_index < len(sensors):
                sensor = sensors[self.sensor_index]
                self.sensor_index += 1

                protocol.value = sensor['protocol']
                model.value = sensor['model']
                id._obj.value = sensor['id']
                datatypes._obj.value = sensor['datatypes']
                return TELLSTICK_SUCCESS
            else:
                self.sensor_index = 0
                return TELLSTICK_ERROR_DEVICE_NOT_FOUND
        self.mocklib.tdSensor = tdSensor
        
        core = TelldusCore()
        sensors = core.sensors()

        self.assertEqual(3, len(sensors))
        self.assertEqual(["proto_1", "proto_2", "proto_3"],
                         [s.protocol for s in sensors])
        self.assertEqual(["model_1", "model_2", "model_3"],
                         [s.model for s in sensors])
        self.assertEqual([1, 2, 3], [s.id for s in sensors])
        self.assertEqual([TELLSTICK_TEMPERATURE, TELLSTICK_TEMPERATURE,
                          TELLSTICK_HUMIDITY],
                         [s.datatypes for s in sensors])
예제 #2
0
    def test_devices(self):
        devs = {0: {'protocol': b"proto_1", 'model': b"model_1"},
                3: {'protocol': b"proto_2", 'model': b"model_2"},
                6: {'protocol': b"proto_3", 'model': b"model_3"}}

        self.mocklib.tdGetNumberOfDevices = lambda: len(devs)
        self.mocklib.tdGetDeviceId = lambda index: index * 3
        self.mocklib.tdGetProtocol = lambda id: \
            c_char_p(devs[id]['protocol'])
        self.mocklib.tdGetModel = lambda id: \
            c_char_p(devs[id]['model'])

        core = TelldusCore()
        devices = core.devices()

        self.assertEqual(3, len(devices))
        self.assertEqual(['proto_1', 'proto_2', 'proto_3'],
                         [d.protocol for d in devices])
        self.assertEqual(['model_1', 'model_2', 'model_3'],
                         [d.model for d in devices])