src.bluetooth_sig.utils.values¶
Value utilities for consumers of parsed Bluetooth SIG data.
Provides helpers that avoid leaking implementation details (msgspec, enum ordering) into every consumer codebase.
Functions¶
Name | Description |
|---|---|
|
Check whether obj is a parsed struct produced by the library. |
|
Coerce a parsed characteristic value to a plain Python primitive. |
Module Contents¶
- src.bluetooth_sig.utils.values.is_struct_value(obj: object) bool¶
Check whether obj is a parsed struct produced by the library.
Use this instead of
hasattr(obj, '__struct_fields__')so consumer code does not depend on the msgspec implementation detail.- Parameters:
obj – Any parsed characteristic value.
- Returns:
Trueif obj is amsgspec.Structinstance.
- src.bluetooth_sig.utils.values.to_primitive(value: Any) int | float | str | bool¶
Coerce a parsed characteristic value to a plain Python primitive.
Handles the full range of types the library may return (
bool,IntFlag,IntEnum,Enum,int,float,str,datetime,timedelta, msgspec Structs, …).Order matters:
boolbeforeint—boolis a subclass ofint.IntFlagbefore the.namebranch — bit-field values expose a.nameattribute but should be stored as a plainint.IntEnum/Enum→.namestring.
- Parameters:
value – Any value returned by
BaseCharacteristic.parse_value()or extracted from a struct field.- Returns:
A plain
int,float,str, orbool.