Coverage for src / bluetooth_sig / gatt / characteristics / report.py: 85%
13 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
1"""Report characteristic implementation."""
3from __future__ import annotations
5import msgspec
7from ..context import CharacteristicContext
8from .base import BaseCharacteristic
11class ReportData(msgspec.Struct, frozen=True):
12 """Parsed data from Report characteristic.
14 Attributes:
15 data: Report data bytes (variable length)
16 """
18 data: bytes
21class ReportCharacteristic(BaseCharacteristic[ReportData]):
22 """Report characteristic (0x2A4D).
24 org.bluetooth.characteristic.report
26 Report characteristic.
27 """
29 min_length = 1
30 expected_type = bytes
32 def _decode_value(
33 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True
34 ) -> ReportData:
35 """Parse report data.
37 Args:
38 data: Raw bytearray from BLE characteristic.
39 ctx: Optional context.
40 validate: Whether to validate ranges (default True)
42 Returns:
43 ReportData containing the report bytes.
44 """
45 return ReportData(data=bytes(data))
47 def _encode_value(self, data: ReportData) -> bytearray:
48 """Encode report data back to bytes.
50 Args:
51 data: ReportData instance to encode
53 Returns:
54 Encoded bytes
55 """
56 return bytearray(data.data)