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

10 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-18 11:17 +0000

1"""Reconnection Address characteristic implementation.""" 

2 

3from __future__ import annotations 

4 

5from ...types.address import bytes_to_mac_address, mac_address_to_bytes 

6from ..context import CharacteristicContext 

7from .base import BaseCharacteristic 

8 

9 

10class ReconnectionAddressCharacteristic(BaseCharacteristic[str]): 

11 """Reconnection Address characteristic (0x2A03). 

12 

13 org.bluetooth.characteristic.gap.reconnection_address 

14 

15 Contains a 48-bit Bluetooth device address for reconnection. 

16 """ 

17 

18 expected_length = 6 

19 

20 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True) -> str: 

21 """Parse BD_ADDR to colon-separated hex string. 

22 

23 Args: 

24 data: Raw bytearray (6 bytes). 

25 ctx: Optional CharacteristicContext. 

26 validate: Whether to validate ranges (default True) 

27 

28 Returns: 

29 BD_ADDR as string (e.g., "AA:BB:CC:DD:EE:FF"). 

30 """ 

31 return bytes_to_mac_address(data) 

32 

33 def _encode_value(self, data: str) -> bytearray: 

34 """Encode BD_ADDR from colon-separated hex string. 

35 

36 Args: 

37 data: BD_ADDR string (e.g., "AA:BB:CC:DD:EE:FF") 

38 

39 Returns: 

40 Encoded bytes (6 bytes validated by BaseCharacteristic) 

41 """ 

42 return bytearray(mac_address_to_bytes(data))