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

45 statements  

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

1"""IDD Status Reader Control Point characteristic (0x2B24). 

2 

3Control point for reading various IDD status fields. 

4 

5References: 

6 Bluetooth SIG Insulin Delivery Service 1.0 

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 IDDStatusReaderOpCode(IntEnum): 

21 """IDD Status Reader Control Point Op Codes.""" 

22 

23 RESPONSE_CODE = 0x0303 

24 RESET_STATUS = 0x030C 

25 GET_ACTIVE_BOLUS_IDS = 0x0330 

26 GET_ACTIVE_BOLUS_IDS_RESPONSE = 0x033F 

27 GET_ACTIVE_BOLUS_DELIVERY = 0x0356 

28 GET_ACTIVE_BOLUS_DELIVERY_RESPONSE = 0x0359 

29 GET_ACTIVE_BASAL_RATE_DELIVERY = 0x0365 

30 GET_ACTIVE_BASAL_RATE_DELIVERY_RESPONSE = 0x036A 

31 GET_TOTAL_DAILY_INSULIN_STATUS = 0x0395 

32 GET_TOTAL_DAILY_INSULIN_STATUS_RESPONSE = 0x039A 

33 GET_COUNTER = 0x03A6 

34 GET_COUNTER_RESPONSE = 0x03A9 

35 GET_DELIVERED_INSULIN = 0x03C0 

36 GET_DELIVERED_INSULIN_RESPONSE = 0x03CF 

37 GET_INSULIN_ON_BOARD = 0x03F3 

38 GET_INSULIN_ON_BOARD_RESPONSE = 0x03FC 

39 

40 

41class IDDStatusReaderResponseCode(IntEnum): 

42 """IDD Status Reader response codes.""" 

43 

44 SUCCESS = 0x0F 

45 OP_CODE_NOT_SUPPORTED = 0x70 

46 INVALID_OPERAND = 0x71 

47 PROCEDURE_NOT_COMPLETED = 0x72 

48 PARAMETER_OUT_OF_RANGE = 0x73 

49 PROCEDURE_NOT_APPLICABLE = 0x74 

50 

51 

52class IDDStatusReaderControlPointData(msgspec.Struct, frozen=True, kw_only=True): 

53 """Parsed data from IDD Status Reader Control Point. 

54 

55 Attributes: 

56 opcode: The operation code. 

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

58 

59 """ 

60 

61 opcode: IDDStatusReaderOpCode 

62 parameter: bytes = b"" 

63 

64 

65class IDDStatusReaderControlPointCharacteristic(BaseCharacteristic[IDDStatusReaderControlPointData]): 

66 """IDD Status Reader Control Point characteristic (0x2B24). 

67 

68 org.bluetooth.characteristic.idd_status_reader_control_point 

69 

70 Control point for reading IDD status information. 

71 ROLE: CONTROL 

72 """ 

73 

74 min_length = 2 

75 allow_variable_length = True 

76 

77 def _decode_value( 

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

79 ) -> IDDStatusReaderControlPointData: 

80 """Parse IDD Status Reader Control Point data. 

81 

82 Format: OpCode (uint16) + Parameter (variable). 

83 """ 

84 opcode = IDDStatusReaderOpCode(DataParser.parse_int16(data, 0, signed=False)) 

85 parameter = bytes(data[2:]) 

86 

87 return IDDStatusReaderControlPointData( 

88 opcode=opcode, 

89 parameter=parameter, 

90 ) 

91 

92 def _encode_value(self, data: IDDStatusReaderControlPointData) -> bytearray: 

93 """Encode IDD Status Reader Control Point data.""" 

94 result = bytearray() 

95 result.extend(DataParser.encode_int16(int(data.opcode), signed=False)) 

96 result.extend(data.parameter) 

97 return result