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

23 statements  

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

1"""Client Supported Features characteristic (0x2B29).""" 

2 

3from __future__ import annotations 

4 

5from enum import IntFlag 

6 

7from ..context import CharacteristicContext 

8from .base import BaseCharacteristic 

9 

10 

11class ClientFeatures(IntFlag): 

12 """GATT client supported feature flags.""" 

13 

14 ROBUST_CACHING = 0x01 

15 EATT = 0x02 

16 MULTIPLE_HANDLE_VALUE_NOTIFICATIONS = 0x04 

17 

18 

19class ClientSupportedFeaturesCharacteristic(BaseCharacteristic[ClientFeatures]): 

20 """Client Supported Features characteristic (0x2B29). 

21 

22 org.bluetooth.characteristic.client_supported_features 

23 

24 Variable-length bitfield indicating GATT features supported by the client. 

25 """ 

26 

27 allow_variable_length: bool = True 

28 min_length: int = 1 

29 

30 def _decode_value( 

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

32 ) -> ClientFeatures: 

33 result = 0 

34 for i, byte in enumerate(data): 

35 result |= byte << (8 * i) 

36 return ClientFeatures(result) 

37 

38 def _encode_value(self, data: ClientFeatures) -> bytearray: 

39 result = bytearray() 

40 val = int(data) 

41 while val > 0: 

42 result.append(val & 0xFF) 

43 val >>= 8 

44 return result or bytearray([0])