/
/
/
1"""
2Tests for the Hue Lights Sync settings readers.
3
4Brightness and latency both accept 0 as a valid value (the config entries
5declare ranges of 0-100 and 0-3000), so the readers must fall back to the
6default only when nothing is configured.
7"""
8
9from __future__ import annotations
10
11from collections.abc import Callable
12
13import pytest
14from music_assistant_models.config_entries import ConfigEntry, ConfigValueType, ProviderConfig
15from music_assistant_models.enums import ConfigEntryType, ProviderType
16
17from music_assistant.providers.hue_entertainment.constants import (
18 CONF_BRIGHTNESS,
19 CONF_COLOR_MODE,
20 CONF_HUE_LATENCY_MS,
21 DEFAULT_BRIGHTNESS,
22 DEFAULT_COLOR_MODE,
23 DEFAULT_HUE_LATENCY_MS,
24)
25from music_assistant.providers.hue_entertainment.settings import (
26 get_brightness,
27 get_color_mode,
28 get_hue_latency_ms,
29)
30
31
32def _config(**values: ConfigValueType) -> ProviderConfig:
33 """Build a ProviderConfig holding only the given settings."""
34 entries = {}
35 for key, value in values.items():
36 entry = ConfigEntry(key=key, type=ConfigEntryType.STRING)
37 entry.value = value
38 entries[key] = entry
39 return ProviderConfig(
40 type=ProviderType.PLUGIN,
41 domain="hue_entertainment",
42 instance_id="hue_entertainment--test",
43 values=entries,
44 )
45
46
47@pytest.mark.parametrize(
48 ("value", "expected"),
49 [(0, 0), (50, 50), (100, 100), ("75", 75), (62.5, 62)],
50 ids=["zero", "mid", "max", "string", "float"],
51)
52def test_get_brightness(value: ConfigValueType, expected: int) -> None:
53 """Brightness is read as-is, including 0."""
54 assert get_brightness(_config(**{CONF_BRIGHTNESS: value})) == expected
55
56
57@pytest.mark.parametrize(
58 ("value", "expected"),
59 [(0, 0), (120, 120), ("250", 250)],
60 ids=["zero", "mid", "string"],
61)
62def test_get_hue_latency_ms(value: ConfigValueType, expected: int) -> None:
63 """Latency is read as-is, including 0."""
64 assert get_hue_latency_ms(_config(**{CONF_HUE_LATENCY_MS: value})) == expected
65
66
67def test_get_color_mode() -> None:
68 """Colour mode is read as-is."""
69 assert get_color_mode(_config(**{CONF_COLOR_MODE: "ambient"})) == "ambient"
70
71
72@pytest.mark.parametrize(
73 ("reader", "default"),
74 [
75 (get_brightness, DEFAULT_BRIGHTNESS),
76 (get_hue_latency_ms, DEFAULT_HUE_LATENCY_MS),
77 (get_color_mode, DEFAULT_COLOR_MODE),
78 ],
79 ids=["brightness", "latency", "color_mode"],
80)
81def test_unset_setting_falls_back_to_default(
82 reader: Callable[[ProviderConfig], int | str], default: int | str
83) -> None:
84 """An unconfigured setting yields the default."""
85 assert reader(_config()) == default
86