Coverage for src/bluetooth_sig/types/protocols.py: 100%
14 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 00:10 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 00:10 +0000
1"""Protocol definitions for Bluetooth SIG standards."""
3from __future__ import annotations
5from typing import Any, Protocol
7from .gatt_enums import GattProperty
10class CharacteristicDataProtocol(Protocol): # pylint: disable=too-few-public-methods
11 """Minimal protocol describing the attributes used by parsers.
13 This avoids importing the full `CharacteristicData` type here and
14 gives callers a useful static type for `other_characteristics`.
16 Now includes field-level error reporting and parse trace capabilities
17 for improved diagnostics.
18 """
20 value: Any
21 raw_data: bytes
22 parse_success: bool
23 properties: list[GattProperty]
24 name: str
25 field_errors: list[Any] # ParseFieldError, but avoid circular import
26 parse_trace: list[str]
29class CharacteristicProtocol(Protocol):
30 """Protocol for characteristic validation and round-trip testing.
32 Defines the minimal interface for characteristics that support
33 parse/encode operations without requiring full BaseCharacteristic import.
34 Used primarily by debug utilities.
35 """
37 def parse_value(self, data: bytearray) -> Any: # noqa: ANN401
38 """Parse raw data into characteristic value."""
39 ... # pylint: disable=unnecessary-ellipsis # Ellipsis is required for Protocol method stubs
41 def encode_value(self, value: Any) -> bytearray: # noqa: ANN401
42 """Encode characteristic value into raw data."""
43 ... # pylint: disable=unnecessary-ellipsis # Ellipsis is required for Protocol method stubs