Coverage for src / bluetooth_sig / gatt / characteristics / esl_sensor_information.py: 100%
21 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 Sensor Information characteristic implementation."""
3from __future__ import annotations
5import msgspec
7from ...types.gatt_enums import CharacteristicRole
8from ..context import CharacteristicContext
9from .base import BaseCharacteristic
10from .utils import DataParser
13class ESLSensorInformationData(msgspec.Struct, frozen=True, kw_only=True):
14 """Parsed data from ESL Sensor Information characteristic.
16 Attributes:
17 property_id: Mesh Device Property ID (uint16).
18 raw_data: Remaining raw mesh device property bytes.
20 """
22 property_id: int
23 raw_data: bytes = b""
26class ESLSensorInformationCharacteristic(BaseCharacteristic[ESLSensorInformationData]):
27 """ESL Sensor Information characteristic (0x2BFC).
29 org.bluetooth.characteristic.esl_sensor_information
31 Variable-length characteristic containing a Mesh Device Property ID
32 (uint16) followed by the associated property value bytes.
33 """
35 _manual_role = CharacteristicRole.INFO
36 min_length: int = 2 # property_id (uint16)
37 allow_variable_length: bool = True
39 def _decode_value(
40 self,
41 data: bytearray,
42 ctx: CharacteristicContext | None = None,
43 *,
44 validate: bool = True,
45 ) -> ESLSensorInformationData:
46 """Parse ESL sensor information.
48 Args:
49 data: Raw bytes (2+ bytes).
50 ctx: Optional CharacteristicContext.
51 validate: Whether to validate ranges (default True).
53 Returns:
54 ESLSensorInformationData with property_id and raw_data.
56 """
57 property_id = DataParser.parse_int16(data, 0, signed=False)
58 raw_data = bytes(data[2:])
59 return ESLSensorInformationData(property_id=property_id, raw_data=raw_data)
61 def _encode_value(self, data: ESLSensorInformationData) -> bytearray:
62 """Encode ESL sensor information to bytes.
64 Args:
65 data: ESLSensorInformationData to encode.
67 Returns:
68 Encoded bytes.
70 """
71 result = DataParser.encode_int16(data.property_id, signed=False)
72 result.extend(data.raw_data)
73 return result