src.bluetooth_sig.gatt.services.registry

Bluetooth SIG GATT service registry.

This module contains the service registry implementation, including the ServiceName enum, service class mappings, and the GattServiceRegistry class. This was moved from __init__.py to follow Python best practices of keeping __init__.py files lightweight.

Classes

Name

Description

GattServiceRegistry

Registry for all supported GATT services.

Functions

Name

Description

get_service_class_map(...)

Get the current service class map.

Module Contents

class src.bluetooth_sig.gatt.services.registry.GattServiceRegistry

Bases: src.bluetooth_sig.registry.base.BaseUUIDClassRegistry[src.bluetooth_sig.types.gatt_enums.ServiceName, src.bluetooth_sig.gatt.services.base.BaseGattService]

Registry for all supported GATT services.

classmethod clear_custom_registrations() None

Clear all custom service registrations (for testing).

classmethod create_service(uuid: str | src.bluetooth_sig.types.uuid.BluetoothUUID | int, characteristics: src.bluetooth_sig.types.gatt_services.ServiceDiscoveryData) src.bluetooth_sig.gatt.services.base.BaseGattService | None

Create a service instance for the given UUID and characteristics.

Parameters:
  • uuid – Service UUID

  • characteristics – Dict mapping characteristic UUIDs to CharacteristicInfo

Returns:

Service instance if found, None otherwise

Raises:

ValueError – If uuid format is invalid

classmethod get_all_services() list[type[src.bluetooth_sig.gatt.services.base.BaseGattService]]

Get all registered service classes.

Returns:

List of all registered service classes

classmethod get_service_class(uuid: str | src.bluetooth_sig.types.uuid.BluetoothUUID | int) type[src.bluetooth_sig.gatt.services.base.BaseGattService] | None

Get the service class for a given UUID.

Parameters:

uuid – The service UUID

Returns:

Service class if found, None otherwise

Raises:

ValueError – If uuid format is invalid

classmethod get_service_class_by_name(name: str | src.bluetooth_sig.types.gatt_enums.ServiceName) type[src.bluetooth_sig.gatt.services.base.BaseGattService] | None

Get the service class for a given name or enum.

classmethod get_service_class_by_uuid(uuid: str | src.bluetooth_sig.types.uuid.BluetoothUUID | int) type[src.bluetooth_sig.gatt.services.base.BaseGattService] | None

Get the service class for a given UUID (alias for get_service_class).

classmethod register_service_class(uuid: str | src.bluetooth_sig.types.uuid.BluetoothUUID | int, service_cls: type[src.bluetooth_sig.gatt.services.base.BaseGattService], override: bool = False) None

Register a custom service class at runtime.

Parameters:
  • uuid – The service UUID

  • service_cls – The service class to register

  • override – Whether to override existing registrations

Raises:
  • TypeError – If service_cls does not inherit from BaseGattService

  • ValueError – If UUID conflicts with existing registration and override=False

classmethod supported_service_names() list[str]

Get a list of supported service names.

classmethod supported_services() list[str]

Get a list of supported service UUIDs.

classmethod unregister_service_class(uuid: str | src.bluetooth_sig.types.uuid.BluetoothUUID | int) None

Unregister a custom service class.

Parameters:

uuid – The service UUID to unregister

src.bluetooth_sig.gatt.services.registry.get_service_class_map() dict[src.bluetooth_sig.types.gatt_enums.ServiceName, type[src.bluetooth_sig.gatt.services.base.BaseGattService]]

Get the current service class map.

Returns:

Dictionary mapping ServiceName enum to service classes