Coverage for src / bluetooth_sig / gatt / characteristics / report.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-03 16:41 +0000

1"""Report characteristic implementation.""" 

2 

3from __future__ import annotations 

4 

5import msgspec 

6 

7from ..context import CharacteristicContext 

8from .base import BaseCharacteristic 

9 

10 

11class ReportData(msgspec.Struct, frozen=True): 

12 """Parsed data from Report characteristic. 

13 

14 Attributes: 

15 data: Report data bytes (variable length) 

16 """ 

17 

18 data: bytes 

19 

20 

21class ReportCharacteristic(BaseCharacteristic[ReportData]): 

22 """Report characteristic (0x2A4D). 

23 

24 org.bluetooth.characteristic.report 

25 

26 Report characteristic. 

27 """ 

28 

29 min_length = 1 

30 

31 def _decode_value( 

32 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True 

33 ) -> ReportData: 

34 """Parse report data. 

35 

36 Args: 

37 data: Raw bytearray from BLE characteristic. 

38 ctx: Optional context. 

39 validate: Whether to validate ranges (default True) 

40 

41 Returns: 

42 ReportData containing the report bytes. 

43 """ 

44 return ReportData(data=bytes(data)) 

45 

46 def _encode_value(self, data: ReportData) -> bytearray: 

47 """Encode report data back to bytes. 

48 

49 Args: 

50 data: ReportData instance to encode 

51 

52 Returns: 

53 Encoded bytes 

54 """ 

55 return bytearray(data.data)