Coverage for src/bluetooth_sig/gatt/descriptors/number_of_digitals.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"""Number of Digitals Descriptor implementation."""
3from __future__ import annotations
5import msgspec
7from ..characteristics.utils import DataParser
8from .base import BaseDescriptor
11class NumberOfDigitalsData(msgspec.Struct, frozen=True, kw_only=True):
12 """Number of Digitals descriptor data."""
14 number_of_digitals: int
17class NumberOfDigitalsDescriptor(BaseDescriptor):
18 """Number of Digitals Descriptor (0x2909).
20 Specifies the number of digital states supported by a characteristic.
21 Used in sensor applications.
22 """
24 def _has_structured_data(self) -> bool:
25 return True
27 def _get_data_format(self) -> str:
28 return "uint8"
30 def _parse_descriptor_value(self, data: bytes) -> NumberOfDigitalsData:
31 """Parse Number of Digitals value.
33 Args:
34 data: Raw bytes (should be 1 byte for uint8)
36 Returns:
37 NumberOfDigitalsData with number of digitals
39 Raises:
40 ValueError: If data is not exactly 1 byte
41 """
42 if len(data) != 1:
43 raise ValueError(f"Number of Digitals data must be exactly 1 byte, got {len(data)}")
45 number_of_digitals = DataParser.parse_int8(data)
47 return NumberOfDigitalsData(number_of_digitals=number_of_digitals)
49 def get_number_of_digitals(self, data: bytes) -> int:
50 """Get the number of digitals."""
51 parsed = self._parse_descriptor_value(data)
52 return parsed.number_of_digitals