src.bluetooth_sig.gatt.characteristics.role_classifier¶
Role classification for GATT characteristics.
Classifies a characteristic’s purpose (MEASUREMENT, FEATURE, CONTROL, etc.) from SIG spec metadata using a tiered heuristic based on GSS YAML signals, name conventions, and type inference.
Validated against a hand-verified ground truth map of all 294 registered
characteristics — see scripts/test_classifier.py. Characteristics
that cannot be classified from the available YAML metadata alone should
use _manual_role on their class.
Functions¶
Name | Description |
|---|---|
|
Classify a characteristic's purpose from SIG spec metadata. |
Module Contents¶
- src.bluetooth_sig.gatt.characteristics.role_classifier.classify_role(char_name: str, python_type: type | str | None, is_bitfield: bool, unit: str, spec: src.bluetooth_sig.types.registry.CharacteristicSpec | None) src.bluetooth_sig.types.gatt_enums.CharacteristicRole¶
Classify a characteristic’s purpose from SIG spec metadata.
Role definitions: -
MEASUREMENT: value represents something measured or observed fromthe device or environment (physical quantity, sampled reading, derived sensor metric).
STATUS: discrete operational/device state (mode, flag, trend,categorical state snapshot).
FEATURE: capability declaration (supported options/bitmasks), not alive measured value.
CONTROL: command/control endpoint (typically control point writes).INFO: contextual metadata, identifiers, or descriptive/static datathat does not represent a measurement.
Uses a tiered priority system — strongest YAML signals first, then name conventions, type inference, and struct name patterns.
- Tier 1 — YAML-data-driven (highest confidence):
Name contains Control Point → CONTROL
Physical (non-unitless)
unit_id→ MEASUREMENTField-level physical units in structure → MEASUREMENT
- Tier 2 — Name + type signals:
Name contains Status → STATUS
is_bitfieldis True → FEATUREpython_typeis IntFlag subclass → FEATURE
- Tier 3 — SIG naming conventions:
Name contains Measurement or ends with Data → MEASUREMENT
Name ends with Feature(s) → FEATURE
- Tier 4 — Type-driven inference:
Non-empty unit string → MEASUREMENT
python_type is str→ INFOpython_typeis a string subtype name → INFOpython_typeis an Enum subclass → STATUSUnitless
unit_id+ numeric type → MEASUREMENTpython_type is float→ MEASUREMENTpython_type is bool→ STATUS
- Tier 5 — Struct name patterns (for structs with no YAML signal):
Measurement struct keyword → MEASUREMENT
Status struct keyword → STATUS
- Tier 6 — Fallback:
Otherwise → UNKNOWN
- Parameters:
char_name – Display name of the characteristic.
python_type – Resolved Python type (int, float, str, etc.) or None.
is_bitfield – Whether the characteristic is a bitfield.
unit – Unit string (empty string if not applicable).
spec – Resolved YAML spec (may be None).
- Returns:
The classified
CharacteristicRole.