예제 #1
0
    def scan(self, wait=None, sort=None, reverse=False, limit=None):
        """Scan for available devices and print a dictionary of information about them.

        If wait is specified as a floating point number in seconds, then the default wait times
        configured inside of the stream or device adapter used to find IOTile devices is overriden
        with the value specified.

        Args:
            wait (float): An optional override time to wait for results to accumulate before returning
        """

        devices = self.stream.scan(wait=wait)

        for device in devices:
            # Add a Device Slug for user convenience
            if 'uuid' in device:
                device['slug'] = uuid_to_slug(device['uuid'])

        if sort is not None:
            devices.sort(key=lambda x: x[sort], reverse=reverse)

        if limit is not None:
            devices = devices[:limit]

        # FIXME: Use dictionary format in bled112stream to document information returned about devices
        return devices
예제 #2
0
    def test_uuid_to_slug(self):
        """Test UUID to DeviceSlug."""

        with pytest.raises(ArgumentError):
            uuid_to_slug('a')

        with pytest.raises(ArgumentError):
            uuid_to_slug(-1)

        with pytest.raises(ArgumentError):
            uuid_to_slug(0xffffffff)

        assert uuid_to_slug(1) == 'd--0000-0000-0000-0001'
        assert uuid_to_slug(0x9c400) == 'd--0000-0000-0009-c400'
        assert uuid_to_slug(0x0fffffff) == 'd--0000-0000-0fff-ffff'