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

1"""IMDS Descriptor Value Changed characteristic (0x2C0D). 

2 

3Indicates changes to descriptors in the Industrial Monitoring Device Service. 

4 

5References: 

6 Bluetooth SIG Industrial Monitoring Device Service 

7""" 

8 

9from __future__ import annotations 

10 

11from enum import IntFlag 

12 

13import msgspec 

14 

15from ...types.gatt_enums import CharacteristicRole 

16from ..context import CharacteristicContext 

17from .base import BaseCharacteristic 

18from .utils import DataParser 

19 

20 

21class IMDSDescriptorChangeFlags(IntFlag): 

22 """IMDS Descriptor Value Changed flags (uint16).""" 

23 

24 SOURCE_OF_CHANGE = 0x0001 

25 CHARACTERISTIC_VALUE_CHANGED = 0x0002 

26 DESCRIPTOR_VALUE_CHANGED = 0x0004 

27 ADDITIONAL_DESCRIPTORS_CHANGED = 0x0008 

28 

29 

30class IMDSDescriptorValueChangedData(msgspec.Struct, frozen=True, kw_only=True): 

31 """Parsed data from IMDS Descriptor Value Changed characteristic. 

32 

33 Attributes: 

34 flags: Change indication flags. 

35 characteristic_uuid: UUID of the changed characteristic (uint16). 

36 """ 

37 

38 flags: IMDSDescriptorChangeFlags 

39 characteristic_uuid: int 

40 

41 

42class IMDSDescriptorValueChangedCharacteristic(BaseCharacteristic[IMDSDescriptorValueChangedData]): 

43 """IMDS Descriptor Value Changed characteristic (0x2C0D). 

44 

45 org.bluetooth.characteristic.imds_descriptor_value_changed 

46 

47 Indicates which descriptors have changed and for which characteristic. 

48 """ 

49 

50 _manual_role = CharacteristicRole.STATUS 

51 min_length = 4 # flags(2) + uuid(2) 

52 

53 def _decode_value( 

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

55 ) -> IMDSDescriptorValueChangedData: 

56 """Parse IMDS Descriptor Value Changed data. 

57 

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) 

62 

63 return IMDSDescriptorValueChangedData( 

64 flags=flags, 

65 characteristic_uuid=characteristic_uuid, 

66 ) 

67 

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