Coverage for src / bluetooth_sig / gatt / characteristics / imd_control.py: 100%
30 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 16:41 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 16:41 +0000
1"""IMD Control characteristic (0x2C12).
3Control point for Industrial Monitoring Device operations.
5References:
6 Bluetooth SIG Industrial Monitoring Device Service
7"""
9from __future__ import annotations
11from enum import IntEnum
13import msgspec
15from ...types.gatt_enums import CharacteristicRole
16from ..context import CharacteristicContext
17from .base import BaseCharacteristic
18from .utils import DataParser
21class IMDControlOpCode(IntEnum):
22 """IMD Control operation codes."""
24 RESET_DEVICE = 0x01
25 START_MEASUREMENT = 0x02
26 STOP_MEASUREMENT = 0x03
27 CLEAR_STATUS = 0x04
28 SET_CONFIGURATION = 0x05
29 RESPONSE = 0xFF
32class IMDControlData(msgspec.Struct, frozen=True, kw_only=True):
33 """Parsed data from IMD Control characteristic.
35 Attributes:
36 opcode: IMD Control operation code.
37 parameters: Raw parameter bytes.
38 """
40 opcode: IMDControlOpCode
41 parameters: bytes = b""
44class IMDControlCharacteristic(BaseCharacteristic[IMDControlData]):
45 """IMD Control characteristic (0x2C12).
47 org.bluetooth.characteristic.imd_control
49 Control point for Industrial Monitoring Device operations.
50 """
52 _manual_role = CharacteristicRole.CONTROL
53 min_length = 1
54 allow_variable_length = True
56 def _decode_value(
57 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True
58 ) -> IMDControlData:
59 """Parse IMD Control data.
61 Format: OpCode (uint8) + Parameters (variable).
62 """
63 opcode = IMDControlOpCode(DataParser.parse_int8(data, 0, signed=False))
64 parameters = bytes(data[1:])
66 return IMDControlData(
67 opcode=opcode,
68 parameters=parameters,
69 )
71 def _encode_value(self, data: IMDControlData) -> bytearray:
72 """Encode IMD Control data."""
73 result = bytearray()
74 result.extend(DataParser.encode_int8(int(data.opcode), signed=False))
75 result.extend(data.parameters)
76 return result