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

24 statements  

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

1"""Object Properties characteristic implementation.""" 

2 

3from __future__ import annotations 

4 

5from enum import IntFlag 

6 

7from ...types.gatt_enums import CharacteristicRole 

8from ..context import CharacteristicContext 

9from .base import BaseCharacteristic 

10from .utils import DataParser 

11 

12 

13class ObjectProperties(IntFlag): 

14 """Object property flags as per OTS specification.""" 

15 

16 DELETE = 0x00000001 

17 EXECUTE = 0x00000002 

18 READ = 0x00000004 

19 WRITE = 0x00000008 

20 APPEND = 0x00000010 

21 TRUNCATE = 0x00000020 

22 PATCH = 0x00000040 

23 MARK = 0x00000080 

24 

25 

26class ObjectPropertiesCharacteristic(BaseCharacteristic[ObjectProperties]): 

27 """Object Properties characteristic (0x2AC4). 

28 

29 org.bluetooth.characteristic.object_properties 

30 

31 A 32-bit flags bitfield describing the properties of an object 

32 in the Object Transfer Service (OTS). 

33 """ 

34 

35 _manual_role = CharacteristicRole.INFO 

36 expected_length: int = 4 # uint32 

37 min_length: int = 4 

38 

39 def _decode_value( 

40 self, 

41 data: bytearray, 

42 ctx: CharacteristicContext | None = None, 

43 *, 

44 validate: bool = True, 

45 ) -> ObjectProperties: 

46 """Parse object properties (uint32 flags). 

47 

48 Args: 

49 data: Raw bytes (4 bytes). 

50 ctx: Optional CharacteristicContext. 

51 validate: Whether to validate ranges (default True). 

52 

53 Returns: 

54 ObjectProperties flags. 

55 

56 """ 

57 raw = DataParser.parse_int32(data, 0, signed=False) 

58 return ObjectProperties(raw) 

59 

60 def _encode_value(self, data: ObjectProperties) -> bytearray: 

61 """Encode object properties to bytes. 

62 

63 Args: 

64 data: ObjectProperties flags. 

65 

66 Returns: 

67 Encoded bytes (4 bytes). 

68 

69 """ 

70 return DataParser.encode_int32(int(data), signed=False)