Coverage for src / bluetooth_sig / gatt / characteristics / boot_keyboard_output_report.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
1"""Boot Keyboard Output Report characteristic implementation."""
3from __future__ import annotations
5from enum import IntFlag
7from ..context import CharacteristicContext
8from .base import BaseCharacteristic
11class KeyboardLEDs(IntFlag):
12 """Keyboard LED states bitmap."""
14 NUM_LOCK = 0x01
15 CAPS_LOCK = 0x02
16 SCROLL_LOCK = 0x04
17 COMPOSE = 0x08
18 KANA = 0x10
21class BootKeyboardOutputReportCharacteristic(BaseCharacteristic[KeyboardLEDs]):
22 """Boot Keyboard Output Report characteristic (0x2A32).
24 org.bluetooth.characteristic.boot_keyboard_output_report
26 Contains keyboard LED states from host to keyboard following USB HID boot protocol.
27 Format: 1 byte - LED states bitmap.
29 Spec Reference:
30 USB HID Specification v1.11, Appendix B - Boot Interface Descriptors
31 """
33 min_length = 1
34 max_length = 1
35 allow_variable_length = False
37 def _decode_value(
38 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True
39 ) -> KeyboardLEDs:
40 """Parse keyboard LED states.
42 Args:
43 data: Raw bytearray from BLE characteristic (1 byte).
44 ctx: Optional CharacteristicContext.
45 validate: Whether to validate ranges (default True)
47 Returns:
48 KeyboardLEDs with parsed LED states.
49 """
50 return KeyboardLEDs(data[0])
52 def _encode_value(self, data: KeyboardLEDs) -> bytearray:
53 """Encode LED states to bytes.
55 Args:
56 data: KeyboardLEDs to encode
58 validate: Whether to validate ranges (default True)
60 Returns:
61 Encoded bytes (1 byte)
62 """
63 return bytearray([int(data)])