Coverage for src / bluetooth_sig / gatt / characteristics / object_id.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-18 11:17 +0000
1"""Object ID characteristic implementation."""
3from __future__ import annotations
5from ...types.gatt_enums import CharacteristicRole
6from ..constants import UINT48_MAX
7from ..context import CharacteristicContext
8from .base import BaseCharacteristic
9from .utils import DataParser
12class ObjectIdCharacteristic(BaseCharacteristic[int]):
13 """Object ID characteristic (0x2AC3).
15 org.bluetooth.characteristic.object_id
17 A 48-bit locally unique object identifier used by the Object
18 Transfer Service (OTS).
19 """
21 _manual_role = CharacteristicRole.INFO
22 expected_length: int = 6 # uint48
23 min_length: int = 6
24 min_value = 0
25 max_value = UINT48_MAX
27 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True) -> int:
28 """Parse object ID (uint48).
30 Args:
31 data: Raw bytes (6 bytes).
32 ctx: Optional CharacteristicContext.
33 validate: Whether to validate ranges (default True).
35 Returns:
36 Object ID as integer.
38 """
39 return DataParser.parse_int48(data, 0, signed=False)
41 def _encode_value(self, data: int) -> bytearray:
42 """Encode object ID to bytes.
44 Args:
45 data: Object ID as integer (0 to 2^48-1).
47 Returns:
48 Encoded bytes (6 bytes).
50 """
51 return DataParser.encode_int48(data, signed=False)