src.bluetooth_sig.gatt.characteristics.templates.epoch_date¶
Epoch-date template returning datetime.date for BLE date characteristics.
Wraps a 24-bit unsigned integer (days since 1970-01-01) and converts to/from
datetime.date so callers receive a proper Python date type.
Classes¶
Name | Description |
|---|---|
Template for epoch-day date characteristics that return |
Module Contents¶
- class src.bluetooth_sig.gatt.characteristics.templates.epoch_date.EpochDateTemplate¶
Bases:
src.bluetooth_sig.gatt.characteristics.templates.base.CodingTemplate[datetime.date]Template for epoch-day date characteristics that return
datetime.date.The raw wire value is a 24-bit unsigned integer counting the number of days elapsed since 1970-01-01 (the Unix epoch).
- Pipeline Integration:
bytes → [UINT24 extractor] → day_count → date(1970,1,1) + timedelta(days=…)
Examples
>>> template = EpochDateTemplate() >>> template.decode_value(bytearray([0x61, 0x4D, 0x00])) datetime.date(2024, 2, 19)
- decode_value(data: bytearray, offset: int = 0, ctx: src.bluetooth_sig.gatt.context.CharacteristicContext | None = None, *, validate: bool = True) datetime.date¶
Decode 24-bit day count to
datetime.date.- Parameters:
data – Raw bytes from BLE characteristic.
offset – Starting offset in data buffer.
ctx – Optional context for parsing.
validate – Whether to validate data length (default True).
- Returns:
datetime.daterepresenting the decoded date.- Raises:
InsufficientDataError – If data too short.
- encode_value(value: datetime.date | int, *, validate: bool = True) bytearray¶
Encode
datetime.date(or raw day count) to 3 bytes.- Parameters:
value –
datetime.dateor integer day count since epoch.validate – Whether to validate (default True).
- Returns:
Encoded bytes (3 bytes, little-endian).
- property extractor: src.bluetooth_sig.gatt.characteristics.utils.extractors.RawExtractor¶
Return uint24 extractor for pipeline access.