Coverage for src/bluetooth_sig/gatt/descriptors/measurement_description.py: 89%
19 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 00:10 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-30 00:10 +0000
1"""Measurement Description Descriptor implementation."""
3from __future__ import annotations
5import msgspec
7from .base import BaseDescriptor
10class MeasurementDescriptionData(msgspec.Struct, frozen=True, kw_only=True):
11 """Measurement Description descriptor data."""
13 description: str
16class MeasurementDescriptionDescriptor(BaseDescriptor):
17 """Measurement Description Descriptor (0x2912).
19 Contains a human-readable description of the measurement.
20 UTF-8 encoded string describing what the measurement represents.
21 """
23 def _has_structured_data(self) -> bool:
24 return True
26 def _get_data_format(self) -> str:
27 return "utf8"
29 def _parse_descriptor_value(self, data: bytes) -> MeasurementDescriptionData:
30 """Parse Measurement Description value.
32 Args:
33 data: Raw UTF-8 bytes
35 Returns:
36 MeasurementDescriptionData with the description string
37 """
38 try:
39 description = data.decode("utf-8")
40 return MeasurementDescriptionData(description=description)
41 except UnicodeDecodeError as e:
42 raise ValueError(f"Invalid UTF-8 data in Measurement Description: {e}") from e
44 def get_description(self, data: bytes) -> str:
45 """Get the measurement description string."""
46 parsed = self._parse_descriptor_value(data)
47 return parsed.description