def test_timestamp(): """Test readings with a timestamp.""" time = datetime.utcnow() reading = IOTileReading(0, 1, 2, reading_id=5, reading_time=time) assert reading.reading_time == time reading2 = IOTileReading.FromDict(reading.asdict()) assert reading2 == reading
def make_sequential(iotile_id, stream, num_readings, give_ids=False): readings = [] for i in range(0, num_readings): if give_ids: reading = IOTileReading(i, stream, i, reading_id=i+1) else: reading = IOTileReading(i, stream, i) readings.append(reading) report = SignedListReport.FromReadings(iotile_id, readings) return report.encode()
def test_no_id(): """Test readings with no reading_id.""" reading = IOTileReading(0, 1, 2) assert reading.raw_time == 0 assert reading.stream == 1 assert reading.value == 2 assert reading.reading_id == reading.InvalidReadingID
def test_with_id(): """Test readings with a reading_id.""" reading = IOTileReading(0, 1, 2, reading_id=5) assert reading.raw_time == 0 assert reading.stream == 1 assert reading.value == 2 assert reading.reading_id == 5
def _initialize(self): self.dev = MockIOTileDevice(1, 'TestCN') self.dev.reports = [IndividualReadingReport.FromReadings(100, [IOTileReading(0, 1, 2)])] self.adapter = MockDeviceAdapter() self.adapter.add_device('test', self.dev) self.manager = DeviceManager(self.io_loop) self.manager.add_adapter(self.adapter) self.hw = None
def make_sequential(iotile_id, stream, num_readings, give_ids=False, root_key=AuthProvider.NoKey, signer=None): """Create sequaltial report from reading Args: iotile_id (int): The uuid of the device that this report came from stream (int): The stream that these readings are part of num_readings(int): amount of readings give_ids(bool): whether to set sequantial id for every reading root_key(int): type of root key to sign the report signer (AuthProvider): An optional preconfigured AuthProvider that should be used to sign this report. If no AuthProvider is provided, the default ChainedAuthProvider is used. """ readings = [] for i in range(0, num_readings): if give_ids: reading = IOTileReading(i, stream, i, reading_id=i+1) else: reading = IOTileReading(i, stream, i) readings.append(reading) report = SignedListReport.FromReadings(iotile_id, readings, root_key=root_key, signer=signer) return report
def setUp(self): super(TestDeviceManager, self).setUp() self.dev = MockIOTileDevice(1, 'TestCN') self.dev.reports = [ IndividualReadingReport.FromReadings(100, [IOTileReading(0, 1, 2)]) ] self.adapter = MockDeviceAdapter() self.adapter.add_device('test', self.dev) self.manager = DeviceManager(self.io_loop) self.manager.add_adapter(self.adapter) self.manager.register_monitor(1, ['report'], self.on_report) self.reports = [] self.reports_received = threading.Event()
def test_fromreadings(): """Make sure we can create this report dynamically from a list of readings """ report = IndividualReadingReport.FromReadings(10, [IOTileReading(3, 1, 2)]) assert len(report.visible_readings) == 1 assert report.signed is False assert report.encrypted is False assert report.origin == 10 reading = report.visible_readings[0] assert reading.stream == 1 assert reading.value == 2 assert reading.raw_time == 3 assert reading.reading_time is not None
def setUp(self): self.old_serial = serial.Serial serial.Serial = util.dummy_serial.Serial self.adapter = MockBLED112(3) self.dev1 = MockIOTileDevice(100, 'TestCN') self.dev1_ble = MockBLEDevice("00:11:22:33:44:55", self.dev1) self.adapter.add_device(self.dev1_ble) util.dummy_serial.RESPONSE_GENERATOR = self.adapter.generate_response self.dev1.reports = [ IndividualReadingReport.FromReadings(100, [IOTileReading(0, 1, 2)]) ] self._reports_received = threading.Event() logging.basicConfig(level=logging.INFO, stream=sys.stdout) self.scanned_devices = [] self.hw = HardwareManager(port='bled112:test')
def stream_realtime(self, stream, value): """Stream a realtime value as an IndividualReadingReport. If the streaming interface of the VirtualInterface this VirtualDevice is attached to is not opened, the realtime reading may be dropped. Args: stream (int): The stream id to send value (int): The stream value to send """ if not self.stream_iface_open: return reading = IOTileReading(0, stream, value) report = IndividualReadingReport.FromReadings(self.iotile_id, [reading]) self.stream(report)