Coverage for src / bluetooth_sig / gatt / characteristics / time_update_state.py: 100%
30 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"""Time Update State characteristic (0x2A17) implementation."""
3from __future__ import annotations
5from enum import IntEnum
7import msgspec
9from bluetooth_sig.types.context import CharacteristicContext
11from .base import BaseCharacteristic
14class TimeUpdateState(msgspec.Struct, kw_only=True):
15 """Time Update State data structure."""
17 current_state: TimeUpdateCurrentState
18 result: TimeUpdateResult
21class TimeUpdateCurrentState(IntEnum):
22 """Time Update Current State values."""
24 IDLE = 0x00
25 PENDING = 0x01
26 UPDATING = 0x02
29class TimeUpdateResult(IntEnum):
30 """Time Update Result values."""
32 SUCCESSFUL = 0x00
33 CANCELED = 0x01
34 NO_CONNECTION_TO_REFERENCE = 0x02
35 REFERENCE_RESPONDED_WITH_ERROR = 0x03
36 TIMEOUT = 0x04
37 UPDATE_NOT_ATTEMPTED_AFTER_RESET = 0x05
40class TimeUpdateStateCharacteristic(BaseCharacteristic[TimeUpdateState]):
41 """Time Update State characteristic.
43 Indicates the current state of time update operations.
45 Value: 2 bytes
46 - Current State: uint8 (0=Idle, 1=Pending, 2=Updating)
47 - Result: uint8 (0=Successful, 1=Canceled, etc.)
48 """
50 min_length: int = 2
51 max_length: int = 2
53 def __init__(self) -> None:
54 """Initialize the Time Update State characteristic."""
55 super().__init__()
57 def _decode_value(
58 self, data: bytearray, ctx: CharacteristicContext | None = None, *, validate: bool = True
59 ) -> TimeUpdateState:
60 """Decode the raw data to TimeUpdateState."""
61 current_state = TimeUpdateCurrentState(data[0])
62 result = TimeUpdateResult(data[1])
64 return TimeUpdateState(current_state=current_state, result=result)
66 def _encode_value(self, data: TimeUpdateState) -> bytearray:
67 """Encode TimeUpdateState to bytes."""
68 return bytearray([int(data.current_state), int(data.result)])