Coverage for src / bluetooth_sig / gatt / characteristics / object_name.py: 100%
12 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 Name characteristic implementation."""
3from __future__ import annotations
5from ..context import CharacteristicContext
6from .base import BaseCharacteristic
7from .utils import DataParser
9_MAX_NAME_LENGTH = 120 # Maximum UTF-8 string length per OTS spec
12class ObjectNameCharacteristic(BaseCharacteristic[str]):
13 """Object Name characteristic (0x2ABE).
15 org.bluetooth.characteristic.object_name
17 A UTF-8 string (0-120 bytes) representing the name of an object
18 in the Object Transfer Service (OTS).
19 """
21 min_length: int = 0
22 max_length: int = _MAX_NAME_LENGTH
24 def _decode_value(self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True) -> str:
25 """Parse object name (UTF-8 string).
27 Args:
28 data: Raw bytes (0-120 bytes).
29 ctx: Optional CharacteristicContext.
30 validate: Whether to validate ranges (default True).
32 Returns:
33 Object name as string.
35 """
36 return DataParser.parse_utf8_string(data)
38 def _encode_value(self, data: str) -> bytearray:
39 """Encode object name to bytes.
41 Args:
42 data: Object name as string (0-120 bytes when encoded).
44 Returns:
45 Encoded bytes.
47 """
48 return bytearray(data.encode("utf-8"))