Ga naar inhoud

generic_access

GenericAccessService #

Deze klasse bevat de functies om de informatie aangeboden door de bluetooth generic access service uit te lezen

Source code in src/kaspersmicrobit/services/generic_access.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class GenericAccessService:
    """
    This class contains the functions to access the information provided by the Bluetooth generic access service
    to read out
    """

    def __init__(self, device: BluetoothDevice):
        self._device = device

    def is_available(self) -> bool:
        """
        Checks whether the generic access Bluetooth service is found on the connected micro:bit.

        Returns:
            true if the generic access service was found, false if not.
        """
        return self._device.is_service_available(Service.GENERIC_ACCESS)

    def read_device_name(self) -> str:
        """
        Reads the name of the micro:bit.

        Returns:
            the name of the micro:bit

        Raises:
            errors.BluetoothServiceNotFound: When the generic access service is not active on the micro:bit
            errors.BluetoothCharacteristicNotFound: When the generic access service is running but there was no way
                to read the device name (normally not present)
        """
        return str(self._device.read(Service.GENERIC_ACCESS, Characteristic.DEVICE_NAME), "utf-8")

is_available #

is_available() -> bool

Kijkt na of de generic access bluetooth service gevonden wordt op de geconnecteerde micro:bit.

Returns:

  • bool

    true als de generic access service gevonden werd, false indien niet.

Source code in src/kaspersmicrobit/services/generic_access.py
19
20
21
22
23
24
25
26
def is_available(self) -> bool:
    """
    Checks whether the generic access Bluetooth service is found on the connected micro:bit.

    Returns:
        true if the generic access service was found, false if not.
    """
    return self._device.is_service_available(Service.GENERIC_ACCESS)

read_device_name #

read_device_name() -> str

Leest de naam van de micro:bit.

Returns:

  • str

    de naam van de micro:bit

Raises:

Source code in src/kaspersmicrobit/services/generic_access.py
28
29
30
31
32
33
34
35
36
37
38
39
40
def read_device_name(self) -> str:
    """
    Reads the name of the micro:bit.

    Returns:
        the name of the micro:bit

    Raises:
        errors.BluetoothServiceNotFound: When the generic access service is not active on the micro:bit
        errors.BluetoothCharacteristicNotFound: When the generic access service is running but there was no way
            to read the device name (normally not present)
    """
    return str(self._device.read(Service.GENERIC_ACCESS, Characteristic.DEVICE_NAME), "utf-8")