Coverage for src / bluetooth_sig / gatt / characteristics / boot_keyboard_output_report.py: 100%
19 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"""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 _manual_value_type = "KeyboardLEDs"
35 min_length = 1
36 max_length = 1
37 allow_variable_length = False
39 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None) -> KeyboardLEDs:
40 """Parse keyboard LED states.
42 Args:
43 data: Raw bytearray from BLE characteristic (1 byte).
44 ctx: Optional CharacteristicContext.
46 Returns:
47 KeyboardLEDs with parsed LED states.
48 """
49 return KeyboardLEDs(data[0])
51 def _encode_value(self, data: KeyboardLEDs) -> bytearray:
52 """Encode LED states to bytes.
54 Args:
55 data: KeyboardLEDs to encode
57 Returns:
58 Encoded bytes (1 byte)
59 """
60 return bytearray([int(data)])