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

23 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-11 20:14 +0000

1"""PLX Features characteristic implementation.""" 

2 

3from __future__ import annotations 

4 

5from enum import IntFlag 

6 

7from bluetooth_sig.gatt.context import CharacteristicContext 

8 

9from .base import BaseCharacteristic 

10from .utils import DataParser 

11 

12 

13class PLXFeatureFlags(IntFlag): 

14 """PLX Features flags per Bluetooth SIG specification. 

15 

16 Spec: Bluetooth SIG Assigned Numbers, PLX Features characteristic 

17 """ 

18 

19 MEASUREMENT_STATUS_SUPPORT = 0x0001 

20 DEVICE_AND_SENSOR_STATUS_SUPPORT = 0x0002 

21 MEASUREMENT_STORAGE_SUPPORT = 0x0004 

22 TIMESTAMP_SUPPORT = 0x0008 

23 SPO2PR_FAST_SUPPORT = 0x0010 

24 SPO2PR_SLOW_SUPPORT = 0x0020 

25 PULSE_AMPLITUDE_INDEX_SUPPORT = 0x0040 

26 MULTIPLE_BONDS_SUPPORT = 0x0080 

27 # Bits 8-15 are reserved for future use 

28 

29 

30class PLXFeaturesCharacteristic(BaseCharacteristic[PLXFeatureFlags]): 

31 """PLX Features characteristic (0x2A60). 

32 

33 Describes the supported features of a pulse oximeter device. 

34 Returns a 16-bit feature flags value. 

35 

36 Spec: Bluetooth SIG Assigned Numbers, PLX Features characteristic 

37 """ 

38 

39 expected_length: int | None = 2 

40 

41 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None) -> PLXFeatureFlags: 

42 """Decode PLX features from raw bytes. 

43 

44 Args: 

45 data: Raw bytes from BLE characteristic (2 bytes) 

46 ctx: Unused, for signature compatibility 

47 

48 Returns: 

49 PLXFeatureFlags enum with supported features 

50 

51 """ 

52 del ctx # Unused parameter 

53 

54 raw_value = DataParser.parse_int16(data, 0, signed=False) 

55 return PLXFeatureFlags(raw_value) 

56 

57 def _encode_value(self, data: PLXFeatureFlags | int) -> bytearray: 

58 """Encode PLX features to bytes. 

59 

60 Args: 

61 data: PLXFeatureFlags enum or 16-bit feature flags as integer 

62 

63 Returns: 

64 Encoded bytes (2 bytes, little-endian) 

65 

66 """ 

67 value = data.value if isinstance(data, PLXFeatureFlags) else data 

68 return DataParser.encode_int16(value, signed=False)