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

16 statements  

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

1"""ESL Current Absolute Time characteristic implementation.""" 

2 

3from __future__ import annotations 

4 

5from ...types.gatt_enums import CharacteristicRole 

6from ..constants import UINT32_MAX 

7from ..context import CharacteristicContext 

8from .base import BaseCharacteristic 

9from .utils import DataParser 

10 

11 

12class ESLCurrentAbsoluteTimeCharacteristic(BaseCharacteristic[int]): 

13 """ESL Current Absolute Time characteristic (0x2BF9). 

14 

15 org.bluetooth.characteristic.esl_current_absolute_time 

16 

17 A uint32 representing milliseconds since the ESL epoch. 

18 """ 

19 

20 _manual_role = CharacteristicRole.STATUS 

21 expected_length: int = 4 # uint32 

22 min_length: int = 4 

23 min_value = 0 

24 max_value = UINT32_MAX 

25 

26 def _decode_value( 

27 self, 

28 data: bytearray, 

29 ctx: CharacteristicContext | None = None, 

30 *, 

31 validate: bool = True, 

32 ) -> int: 

33 """Parse ESL absolute time (uint32 milliseconds). 

34 

35 Args: 

36 data: Raw bytes (4 bytes). 

37 ctx: Optional CharacteristicContext. 

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

39 

40 Returns: 

41 Milliseconds since ESL epoch as integer. 

42 

43 """ 

44 return DataParser.parse_int32(data, 0, signed=False) 

45 

46 def _encode_value(self, data: int) -> bytearray: 

47 """Encode ESL absolute time to bytes. 

48 

49 Args: 

50 data: Milliseconds since ESL epoch as integer. 

51 

52 Returns: 

53 Encoded bytes (4 bytes). 

54 

55 """ 

56 return DataParser.encode_int32(data, signed=False)