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

13 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-18 11:17 +0000

1"""Report Map characteristic implementation.""" 

2 

3from __future__ import annotations 

4 

5import msgspec 

6 

7from ..context import CharacteristicContext 

8from .base import BaseCharacteristic 

9 

10 

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

12 """Parsed data from Report Map characteristic. 

13 

14 Attributes: 

15 data: Report map data bytes (up to 512 octets) 

16 """ 

17 

18 data: bytes 

19 

20 

21class ReportMapCharacteristic(BaseCharacteristic[ReportMapData]): 

22 """Report Map characteristic (0x2A4B). 

23 

24 org.bluetooth.characteristic.report_map 

25 

26 Report Map characteristic. 

27 """ 

28 

29 min_length = 1 

30 expected_type = bytes 

31 

32 def _decode_value( 

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

34 ) -> ReportMapData: 

35 """Parse report map data. 

36 

37 Args: 

38 data: Raw bytearray from BLE characteristic. 

39 ctx: Optional context. 

40 validate: Whether to validate ranges (default True) 

41 

42 Returns: 

43 ReportMapData containing the report map bytes. 

44 """ 

45 return ReportMapData(data=bytes(data)) 

46 

47 def _encode_value(self, data: ReportMapData) -> bytearray: 

48 """Encode report map back to bytes. 

49 

50 Args: 

51 data: ReportMapData instance to encode 

52 

53 Returns: 

54 Encoded bytes 

55 """ 

56 return bytearray(data.data)