Coverage for src / bluetooth_sig / gatt / characteristics / scan_interval_window.py: 100%
20 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 20:14 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 20:14 +0000
1"""Scan Interval Window characteristic implementation."""
3from __future__ import annotations
5from ...types.scan_interval_window import ScanIntervalWindowData
6from ..context import CharacteristicContext
7from .base import BaseCharacteristic
8from .utils import DataParser
11class ScanIntervalWindowCharacteristic(BaseCharacteristic[ScanIntervalWindowData]):
12 """Scan Interval Window characteristic (0x2A4F).
14 org.bluetooth.characteristic.scan_interval_window
16 The Scan Interval Window characteristic is used to set the scan interval
17 and scan window parameters for BLE scanning.
19 This is a write-only characteristic containing:
20 - Scan Interval: uint16 (2 bytes, little-endian, units of 0.625ms, range 0x0004-0x4000)
21 - Scan Window: uint16 (2 bytes, little-endian, units of 0.625ms, range 0x0004-0x4000)
23 The scan window must be less than or equal to the scan interval.
24 """
26 _characteristic_name = "Scan Interval Window"
27 _manual_value_type = "ScanIntervalWindowData" # Override since decode_value returns structured data
29 min_length = 4 # Scan Interval(2) + Scan Window(2)
30 max_length = 4 # Fixed length
31 allow_variable_length: bool = False # Fixed length
33 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None) -> ScanIntervalWindowData:
34 """Parse scan interval window data.
36 Args:
37 data: Raw bytearray from BLE characteristic (4 bytes).
38 ctx: Optional CharacteristicContext providing surrounding context (may be None).
40 Returns:
41 ScanIntervalWindowData with parsed scan parameters.
43 """
44 scan_interval = DataParser.parse_int16(data, 0, signed=False)
45 scan_window = DataParser.parse_int16(data, 2, signed=False)
47 return ScanIntervalWindowData(scan_interval=scan_interval, scan_window=scan_window)
49 def _encode_value(self, data: ScanIntervalWindowData) -> bytearray:
50 """Encode scan interval window value back to bytes.
52 Args:
53 data: ScanIntervalWindowData instance
55 Returns:
56 Encoded bytes representing the scan parameters (4 bytes)
58 """
59 result = bytearray()
60 result.extend(DataParser.encode_int16(data.scan_interval, signed=False))
61 result.extend(DataParser.encode_int16(data.scan_window, signed=False))
62 return result