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

10 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-11 20:14 +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) -> str: 

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

22 

23 Args: 

24 data: Raw bytearray (6 bytes). 

25 ctx: Optional CharacteristicContext. 

26 

27 Returns: 

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

29 """ 

30 return bytes_to_mac_address(data) 

31 

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

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

34 

35 Args: 

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

37 

38 Returns: 

39 Encoded bytes (6 bytes validated by BaseCharacteristic) 

40 """ 

41 return bytearray(mac_address_to_bytes(data))