Coverage for src / bluetooth_sig / types / registry / units.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"""Types for Bluetooth SIG units registry."""
3from __future__ import annotations
5from bluetooth_sig.types.registry.common import UuidIdInfo
8class UnitInfo(UuidIdInfo, frozen=True, kw_only=True):
9 """Unit information from Bluetooth SIG units registry.
11 Extends UuidIdInfo with a symbol field for the SI unit symbol.
13 Attributes:
14 uuid: Bluetooth UUID for this unit
15 name: Descriptive name (e.g., "thermodynamic temperature (degree celsius)")
16 id: Org.bluetooth identifier (e.g., "org.bluetooth.unit.thermodynamic_temperature.degree_celsius")
17 symbol: SI unit symbol (e.g., "°C"), derived from name during loading
18 """
20 symbol: str = ""
22 @property
23 def readable_name(self) -> str:
24 """Human-readable unit name extracted from the descriptive name.
26 Extracts the parenthetical content from YAML-style names:
27 - ``"thermodynamic temperature (degree celsius)"`` → ``"degree celsius"``
28 - ``"period (beats per minute)"`` → ``"beats per minute"``
29 - ``"percentage"`` → ``"percentage"`` (no parenthetical → returns full name)
30 """
31 if "(" in self.name and ")" in self.name:
32 start = self.name.find("(") + 1
33 end = self.name.find(")", start)
34 if 0 < start < end:
35 return self.name[start:end].strip()
36 return self.name