33 lines
986 B
Python
33 lines
986 B
Python
"""Tests for the PlaybackIntent dataclass (optimistic state tracking)."""
|
|
|
|
from ha_adb_common.intent import PlaybackIntent
|
|
|
|
|
|
def test_create_captures_fields():
|
|
intent = PlaybackIntent.create(
|
|
target_state="paused", command="media_pause", prior_state="playing"
|
|
)
|
|
assert intent.target_state == "paused"
|
|
assert intent.command == "media_pause"
|
|
assert intent.prior_state == "playing"
|
|
assert intent.retry_count == 0
|
|
assert intent.created_at > 0
|
|
|
|
|
|
def test_debug_dict_shape():
|
|
intent = PlaybackIntent.create(target_state="playing", command="media_play")
|
|
debug = intent.to_debug_dict()
|
|
assert debug["target"] == "playing"
|
|
assert debug["command"] == "media_play"
|
|
assert debug["retries"] == 0
|
|
assert "age_s" in debug
|
|
|
|
|
|
def test_age_increases():
|
|
import time
|
|
|
|
intent = PlaybackIntent.create(target_state="playing", command="media_play")
|
|
before = intent.age_seconds
|
|
time.sleep(0.01)
|
|
assert intent.age_seconds >= before
|