Coverage for src / bluetooth_sig / gatt / characteristics / esl_led_information.py: 100%
27 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 16:41 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 16:41 +0000
1"""ESL LED Information characteristic implementation."""
3from __future__ import annotations
5from enum import IntFlag
7import msgspec
9from ...types.gatt_enums import CharacteristicRole
10from ..context import CharacteristicContext
11from .base import BaseCharacteristic
12from .utils import DataParser
15class ESLColorGamut(IntFlag):
16 """ESL LED colour gamut flags per ESL specification."""
18 RED = 0x01
19 GREEN = 0x02
20 BLUE = 0x04
23class ESLLEDInformationData(msgspec.Struct, frozen=True, kw_only=True):
24 """Parsed data from ESL LED Information characteristic.
26 Attributes:
27 led_index: Index of the LED (0-based).
28 color_gamut: Colour gamut bitfield indicating supported colours.
30 """
32 led_index: int
33 color_gamut: ESLColorGamut
36class ESLLEDInformationCharacteristic(BaseCharacteristic[ESLLEDInformationData]):
37 """ESL LED Information characteristic (0x2BFD).
39 org.bluetooth.characteristic.esl_led_information
41 Describes an ESL LED: index and colour gamut bitfield (Red, Green, Blue).
42 """
44 _characteristic_name = "ESL LED Information"
45 _manual_role = CharacteristicRole.INFO
46 expected_length: int = 2 # led_index(1) + color_gamut(1)
47 min_length: int = 2
49 def _decode_value(
50 self,
51 data: bytearray,
52 ctx: CharacteristicContext | None = None,
53 *,
54 validate: bool = True,
55 ) -> ESLLEDInformationData:
56 """Parse ESL LED information.
58 Args:
59 data: Raw bytes (2 bytes).
60 ctx: Optional CharacteristicContext.
61 validate: Whether to validate ranges (default True).
63 Returns:
64 ESLLEDInformationData with LED details.
66 """
67 led_index = DataParser.parse_int8(data, 0, signed=False)
68 color_gamut = ESLColorGamut(DataParser.parse_int8(data, 1, signed=False))
69 return ESLLEDInformationData(led_index=led_index, color_gamut=color_gamut)
71 def _encode_value(self, data: ESLLEDInformationData) -> bytearray:
72 """Encode ESL LED information to bytes.
74 Args:
75 data: ESLLEDInformationData to encode.
77 Returns:
78 Encoded bytes (2 bytes).
80 """
81 result = DataParser.encode_int8(data.led_index, signed=False)
82 result.extend(DataParser.encode_int8(int(data.color_gamut), signed=False))
83 return result