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

13 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-11 20:14 +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 expected_type = bytes 

31 

32 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None) -> ReportData: 

33 """Parse report data. 

34 

35 Args: 

36 data: Raw bytearray from BLE characteristic. 

37 ctx: Optional context. 

38 

39 Returns: 

40 ReportData containing the report bytes. 

41 """ 

42 return ReportData(data=bytes(data)) 

43 

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

45 """Encode report data back to bytes. 

46 

47 Args: 

48 data: ReportData instance to encode 

49 

50 Returns: 

51 Encoded bytes 

52 """ 

53 return bytearray(data.data)