Example #1
0
    def __init__(self, uuid, handle, group_end_handle):
        if isinstance(uuid, UUID):
            self.uuid = uuid
        elif isinstance(uuid, string_types):
            self.uuid = string_to_uuid(uuid)
        elif isinstance(uuid, dict):
            self.uuid = string_to_uuid(uuid['uuid'],
                                       input_byteorder=uuid['byteorder'])
        else:
            raise ValueError(
                "UUID must be either a uuid.UUID object, a dict or a string")

        self.handle = handle
        self.group_end_handle = group_end_handle
Example #2
0
def test_string_to_uuid():
    """ Test to convert a string into a uuid. """
    # Test with 2-byte UUID (Big Endian)
    string = '1234'
    uuid = string_to_uuid(string)
    assert uuid == UUID('00001234-0000-1000-8000-00805f9b34fb')

    # Test with 2-byte UUID (Little Endian)
    string = '3412'
    uuid = string_to_uuid(string, input_byteorder='little')
    assert uuid == UUID('00001234-0000-1000-8000-00805f9b34fb')

    # Test with 16-byte UUID (Big Endian)
    string = '12345678-1234-1234-1234-123456789112'
    uuid = string_to_uuid(string)
    assert uuid == UUID('12345678-1234-1234-1234-123456789112')

    # Test with 16-byte UUID (Little Endian)
    string = '12917856-3412-3412-3412-341278563412'
    uuid = string_to_uuid(string, input_byteorder='little')
    assert uuid == UUID('12345678-1234-1234-1234-123456789112')
Example #3
0
    def on_device_found_event(packet):
        result = packet.get_dict([
            'controller_id', 'type', ('address', lambda value: value.decode()),
            ('address_type', lambda value: 'public'
             if value == 0 else 'random'), 'rssi',
            ('uuid',
             lambda value: string_to_uuid(value, input_byteorder='little')),
            'company_id', ('device_name', lambda value: value.decode()),
            ('manufacturer_data', bytes)
        ])

        on_device_found_cb(True, result, None, *on_device_found_params)
Example #4
0
    def __init__(self,
                 uuid,
                 handle,
                 value_handle,
                 config_handle=None,
                 indicate=False,
                 notify=False,
                 read=False,
                 write=False,
                 broadcast=False,
                 notification_enabled=False,
                 indication_enabled=False,
                 const_value=None):
        if isinstance(uuid, UUID):
            self.uuid = uuid
        elif isinstance(uuid, string_types):
            self.uuid = string_to_uuid(uuid)
        elif isinstance(uuid, dict):
            self.uuid = string_to_uuid(uuid['uuid'],
                                       input_byteorder=uuid['byteorder'])
        else:
            raise ValueError(
                "UUID must be either a uuid.UUID object, a dict or a string")

        self.handle = handle
        self.value_handle = value_handle
        self.config_handle = config_handle

        self.properties = {
            'indicate': indicate,
            'notify': notify,
            'read': read,
            'write': write,
            'broadcast': broadcast
        }

        self.notification_enabled = notification_enabled
        self.indication_enabled = indication_enabled

        self.const_value = const_value