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

32 statements  

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

1"""Hearing Aid Preset Control Point characteristic (0x2BDB). 

2 

3Control point for Hearing Aid presets. 

4 

5References: 

6 Bluetooth SIG Hearing Access Service specification 

7""" 

8 

9from __future__ import annotations 

10 

11from enum import IntEnum 

12 

13import msgspec 

14 

15from ..context import CharacteristicContext 

16from .base import BaseCharacteristic 

17from .utils import DataParser 

18 

19 

20class HearingAidPresetControlPointOpCode(IntEnum): 

21 """Hearing Aid Preset Control Point Op Codes.""" 

22 

23 READ_PRESETS_REQUEST = 0x01 

24 READ_PRESET_RESPONSE = 0x02 

25 PRESET_CHANGED = 0x03 

26 WRITE_PRESET_NAME = 0x04 

27 SET_ACTIVE_PRESET = 0x05 

28 SET_NEXT_PRESET = 0x06 

29 SET_PREVIOUS_PRESET = 0x07 

30 SET_ACTIVE_PRESET_SYNCED_LOCALLY = 0x08 

31 SET_NEXT_PRESET_SYNCED_LOCALLY = 0x09 

32 SET_PREVIOUS_PRESET_SYNCED_LOCALLY = 0x0A 

33 

34 

35class HearingAidPresetControlPointData(msgspec.Struct, frozen=True, kw_only=True): 

36 """Parsed data from Hearing Aid Preset Control Point. 

37 

38 Attributes: 

39 opcode: The operation code. 

40 parameter: Raw parameter bytes (variable per opcode). Empty if none. 

41 

42 """ 

43 

44 opcode: HearingAidPresetControlPointOpCode 

45 parameter: bytes = b"" 

46 

47 

48class HearingAidPresetControlPointCharacteristic( 

49 BaseCharacteristic[HearingAidPresetControlPointData], 

50): 

51 """Hearing Aid Preset Control Point characteristic (0x2BDB). 

52 

53 org.bluetooth.characteristic.hearing_aid_preset_control_point 

54 

55 Control point for managing presets in the Hearing Access Service. 

56 """ 

57 

58 min_length = 1 

59 allow_variable_length = True 

60 

61 def _decode_value( 

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

63 ) -> HearingAidPresetControlPointData: 

64 """Parse Hearing Aid Preset Control Point data. 

65 

66 Format: OpCode (uint8) + Parameter (variable). 

67 """ 

68 opcode = HearingAidPresetControlPointOpCode(DataParser.parse_int8(data, 0, signed=False)) 

69 parameter = bytes(data[1:]) 

70 

71 return HearingAidPresetControlPointData( 

72 opcode=opcode, 

73 parameter=parameter, 

74 ) 

75 

76 def _encode_value(self, data: HearingAidPresetControlPointData) -> bytearray: 

77 """Encode Hearing Aid Preset Control Point data.""" 

78 result = bytearray() 

79 result.extend(DataParser.encode_int8(int(data.opcode), signed=False)) 

80 result.extend(data.parameter) 

81 return result