Ga naar inhoud

errors

KaspersMicrobitNotFound #

Bases: Exception

Wordt gegooid wanneer geen micro:bit gevonden werd, terwijl dit wel verwacht werd.

Attributes:

  • name (str) –

    De naam van de micro:bit waar naar gezocht werd

  • devices (List[BLEDevice]) –

    De lijst van toestellen die wel gevonden werden

Source code in src/kaspersmicrobit/errors.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class KaspersMicrobitNotFound(Exception):
    """
    Raised when no micro:bit was found, even though this was expected.

    Attributes:
        name (str):
            The name of the micro:bit being searched for
        devices (List[BLEDevice]):
            The list of devices that were found
    """

    def __init__(self, name: str, devices: List[BLEDevice]):
        found_devices = '\n'.join([f'  - {device.address} {device.name}' for device in devices])
        super().__init__(
            f'Could not find the micro:bit with name "{name}"\n'
            f'The following devices were detected:\n'
            f'{ found_devices }\n\n'
            f'Is the micro:bit loaded with the correct ".hex" file and powered on?'
        )
        self.name = name
        self.devices = devices

BluetoothCharacteristicNotFound #

Bases: Exception

Wordt gegooid wanneer een Bluetooth GATT characteristic niet gevonden werd, terwijl dit wel verwacht werd.

Attributes:

  • service (Service) –

    De micro:bit bluetooth service waarin de characteristic gezocht werd

  • characteristic (Characteristic) –

    De characteristic die niet gevonden werd

Source code in src/kaspersmicrobit/errors.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class BluetoothCharacteristicNotFound(Exception):
    """
    Raised when a Bluetooth GATT characteristic was not found, even though it was expected.

    Attributes:
        service (Service):
            The micro:bit Bluetooth service in which the characteristic was sought
        characteristic (Characteristic):
            The characteristic that was not found
    """
    def __init__(self, client: BleakClient, service: Service, characteristic: Characteristic):
        available_characteristics = '\n'.join(
            [
                f'  - {gatt_characteristic.description:35}'
                f' ({str(Characteristic.lookup(gatt_characteristic.uuid)):40} uuid={gatt_characteristic.uuid})'
                for gatt_characteristic in client.services.get_service(service.value).characteristics
            ]
        )
        super().__init__(
            f'Could not find the characteristic {characteristic.name} (uuid={characteristic.value})\n'
            f'The available characteristics of the service {service} on this micro:bit are:\n'
            f'{available_characteristics}')
        self.service = service
        self.characteristic = characteristic

BluetoothServiceNotFound #

Bases: Exception

Wordt gegooid wanneer een Bluetooth service niet gevonden werd, terwijl dit wel verwacht werd.

Attributes:

  • service (Service) –

    De micro:bit bluetooth service die niet gevonden werd

Source code in src/kaspersmicrobit/errors.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class BluetoothServiceNotFound(Exception):
    """
    Raised when a Bluetooth service was not found even though it was expected to be.

    Attributes:
        service (Service):
            The micro:bit bluetooth service that was not found
    """
    def __init__(self, client: BleakClient, service: Service):
        available_services = '\n'.join(
            [
                f'  - {gatt_service.description:30}'
                f' ({str(Service.lookup(gatt_service.uuid)):27} uuid={gatt_service.uuid})'
                for gatt_service in client.services
            ]
        )
        super().__init__(
            f'Could not find the service {service} (uuid={service.value})\n'
            f'The available services on this micro:bit are:\n'
            f'{ available_services }\n\n'
            f'Is this micro:bit loaded with the correct ".hex" file?'
        )
        self.service = service