Fix new-group defaults + tidy section collapse defaults

Thread 2 (bug): runtime range number entities seeded from native_min on a
fresh profile (only a name stored at setup), so new groups ran at
max_brightness=1% and a 1000-1000K color-temp range until the options
dialog was saved once. Each RANGE_ENTITIES row now carries a sensible
DEFAULT_* and _options_value() falls back to it. Adds a regression test.

Thread 3: collapse 'Sun schedule' and 'Light control' by default
(now 2 open / 5 closed): Targets + Daytime curve expanded, the rest
collapsed.

Existing profiles unaffected (their options are already saved); only
newly-created groups get the corrected seed. Bump 2.3.0 -> 2.3.1-cdit.1.
This commit is contained in:
Casey 2026-05-31 21:41:57 +02:00
commit 61be07c179
5 changed files with 55 additions and 5 deletions

View file

@ -25,6 +25,10 @@ from custom_components.adaptive_lighting.const import (
CONF_MIN_BRIGHTNESS,
CONF_MIN_COLOR_TEMP,
CONFIG_ENTRY_VERSION,
DEFAULT_MAX_BRIGHTNESS,
DEFAULT_MAX_COLOR_TEMP,
DEFAULT_MIN_BRIGHTNESS,
DEFAULT_MIN_COLOR_TEMP,
DOMAIN,
)
@ -126,6 +130,38 @@ async def test_number_entity_attributes(hass, field_key, expected) -> None:
assert attrs["mode"] == NumberMode.SLIDER
# ---------------------------------------------------------------------------
# 7.4b — Fresh profile (only a name) seeds sensible DEFAULT_*, not native_min
# ---------------------------------------------------------------------------
@pytest.mark.parametrize(
("field_key", "expected_default"),
[
("min_brightness", DEFAULT_MIN_BRIGHTNESS),
("max_brightness", DEFAULT_MAX_BRIGHTNESS),
("min_color_temp", DEFAULT_MIN_COLOR_TEMP),
("max_color_temp", DEFAULT_MAX_COLOR_TEMP),
],
)
async def test_new_profile_seeds_sensible_defaults(
hass,
field_key,
expected_default,
) -> None:
"""A profile created with only a name must come up at DEFAULT_*.
Regression: the seed previously fell back to the slider's native_min,
so a brand-new group ran at max_brightness=1% and a collapsed
1000-1000K color-temp range until the options dialog was saved once.
"""
entry = await _setup_entry(hass) # data={name}, options={}
eid = _resolve_entity_id(hass, entry, field_key)
state = hass.states.get(eid)
assert state is not None
assert float(state.state) == float(expected_default)
# ---------------------------------------------------------------------------
# 7.5 — async_set_native_value does NOT write to entry.options
# ---------------------------------------------------------------------------