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

1"""Boot Keyboard Output Report characteristic implementation.""" 

2 

3from __future__ import annotations 

4 

5from enum import IntFlag 

6 

7from ..context import CharacteristicContext 

8from .base import BaseCharacteristic 

9 

10 

11class KeyboardLEDs(IntFlag): 

12 """Keyboard LED states bitmap.""" 

13 

14 NUM_LOCK = 0x01 

15 CAPS_LOCK = 0x02 

16 SCROLL_LOCK = 0x04 

17 COMPOSE = 0x08 

18 KANA = 0x10 

19 

20 

21class BootKeyboardOutputReportCharacteristic(BaseCharacteristic[KeyboardLEDs]): 

22 """Boot Keyboard Output Report characteristic (0x2A32). 

23 

24 org.bluetooth.characteristic.boot_keyboard_output_report 

25 

26 Contains keyboard LED states from host to keyboard following USB HID boot protocol. 

27 Format: 1 byte - LED states bitmap. 

28 

29 Spec Reference: 

30 USB HID Specification v1.11, Appendix B - Boot Interface Descriptors 

31 """ 

32 

33 _manual_value_type = "KeyboardLEDs" 

34 

35 min_length = 1 

36 max_length = 1 

37 allow_variable_length = False 

38 

39 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None) -> KeyboardLEDs: 

40 """Parse keyboard LED states. 

41 

42 Args: 

43 data: Raw bytearray from BLE characteristic (1 byte). 

44 ctx: Optional CharacteristicContext. 

45 

46 Returns: 

47 KeyboardLEDs with parsed LED states. 

48 """ 

49 return KeyboardLEDs(data[0]) 

50 

51 def _encode_value(self, data: KeyboardLEDs) -> bytearray: 

52 """Encode LED states to bytes. 

53 

54 Args: 

55 data: KeyboardLEDs to encode 

56 

57 Returns: 

58 Encoded bytes (1 byte) 

59 """ 

60 return bytearray([int(data)])