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

10 statements  

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

1"""Peripheral Privacy Flag characteristic implementation.""" 

2 

3from __future__ import annotations 

4 

5from ..context import CharacteristicContext 

6from .base import BaseCharacteristic 

7from .utils.data_parser import DataParser 

8 

9 

10class PeripheralPrivacyFlagCharacteristic(BaseCharacteristic[bool]): 

11 """Peripheral Privacy Flag characteristic (0x2A02). 

12 

13 org.bluetooth.characteristic.gap.peripheral_privacy_flag 

14 

15 Indicates whether privacy is enabled (True) or disabled (False). 

16 """ 

17 

18 def _decode_value( 

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

20 ) -> bool: 

21 """Decode the privacy flag value.""" 

22 value = DataParser.parse_int8(data, 0, signed=False) 

23 return bool(value) 

24 

25 def _encode_value(self, data: bool) -> bytearray: 

26 """Encode the privacy flag value.""" 

27 return DataParser.encode_int8(1 if data else 0, signed=False)