Coverage for src / bluetooth_sig / gatt / characteristics / imds_descriptor_value_changed.py: 100%
27 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"""IMDS Descriptor Value Changed characteristic (0x2C0D).
3Indicates changes to descriptors in the Industrial Monitoring Device Service.
5References:
6 Bluetooth SIG Industrial Monitoring Device Service
7"""
9from __future__ import annotations
11from enum import IntFlag
13import msgspec
15from ...types.gatt_enums import CharacteristicRole
16from ..context import CharacteristicContext
17from .base import BaseCharacteristic
18from .utils import DataParser
21class IMDSDescriptorChangeFlags(IntFlag):
22 """IMDS Descriptor Value Changed flags (uint16)."""
24 SOURCE_OF_CHANGE = 0x0001
25 CHARACTERISTIC_VALUE_CHANGED = 0x0002
26 DESCRIPTOR_VALUE_CHANGED = 0x0004
27 ADDITIONAL_DESCRIPTORS_CHANGED = 0x0008
30class IMDSDescriptorValueChangedData(msgspec.Struct, frozen=True, kw_only=True):
31 """Parsed data from IMDS Descriptor Value Changed characteristic.
33 Attributes:
34 flags: Change indication flags.
35 characteristic_uuid: UUID of the changed characteristic (uint16).
36 """
38 flags: IMDSDescriptorChangeFlags
39 characteristic_uuid: int
42class IMDSDescriptorValueChangedCharacteristic(BaseCharacteristic[IMDSDescriptorValueChangedData]):
43 """IMDS Descriptor Value Changed characteristic (0x2C0D).
45 org.bluetooth.characteristic.imds_descriptor_value_changed
47 Indicates which descriptors have changed and for which characteristic.
48 """
50 _manual_role = CharacteristicRole.STATUS
51 min_length = 4 # flags(2) + uuid(2)
53 def _decode_value(
54 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True
55 ) -> IMDSDescriptorValueChangedData:
56 """Parse IMDS Descriptor Value Changed data.
58 Format: Flags (uint16 LE) + Characteristic_UUID (uint16 LE).
59 """
60 flags = IMDSDescriptorChangeFlags(DataParser.parse_int16(data, 0, signed=False))
61 characteristic_uuid = DataParser.parse_int16(data, 2, signed=False)
63 return IMDSDescriptorValueChangedData(
64 flags=flags,
65 characteristic_uuid=characteristic_uuid,
66 )
68 def _encode_value(self, data: IMDSDescriptorValueChangedData) -> bytearray:
69 """Encode IMDS Descriptor Value Changed data."""
70 result = bytearray()
71 result.extend(DataParser.encode_int16(int(data.flags), signed=False))
72 result.extend(DataParser.encode_int16(data.characteristic_uuid, signed=False))
73 return result