adaptive-lighting/custom_components/adaptive_lighting/config_flow.py

530 lines
18 KiB
Python
Raw Normal View History

Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
"""Config flow for Adaptive Lighting (CDiT fork).
Replaces upstream's flat 40-field options dialog with a six-section
layout (Targets / Daytime curve / Sun schedule / Light control / Advanced /
Diagnostics) using HA's `section()` helper and native selectors throughout.
See design.md decisions 1, 5, 6, 9, 14 and specs/options-flow/spec.md R1-R7.
"""
import contextlib
2020-09-12 23:25:36 +02:00
import logging
2025-11-27 07:35:09 -10:00
from typing import Any
import voluptuous as vol
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
from homeassistant.config_entries import (
SOURCE_IMPORT,
ConfigEntry,
)
from homeassistant.config_entries import ConfigFlow as HAConfigFlow
try:
from homeassistant.config_entries import OptionsFlowWithReload
except ImportError: # pragma: no cover — HA < 2025.1 fallback for dev env
from homeassistant.config_entries import OptionsFlow as OptionsFlowWithReload
2025-12-12 22:37:42 +01:00
from homeassistant.const import CONF_NAME
2020-09-12 23:25:36 +02:00
from homeassistant.core import callback
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
from homeassistant.data_entry_flow import section
from homeassistant.helpers import entity_registry as er
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
from homeassistant.helpers.selector import (
BooleanSelector,
EntitySelector,
EntitySelectorConfig,
NumberSelector,
NumberSelectorConfig,
NumberSelectorMode,
)
2020-09-12 23:25:36 +02:00
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
from .const import (
CONF_ADAPT_DELAY,
CONF_INCLUDE_CONFIG_IN_ATTRIBUTES,
CONF_INITIAL_TRANSITION,
CONF_INTERCEPT,
CONF_INTERVAL,
CONF_LIGHTS,
CONF_LUX_SENSOR,
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
CONF_MAX_BRIGHTNESS,
CONF_MAX_COLOR_TEMP,
CONF_MIN_BRIGHTNESS,
CONF_MIN_COLOR_TEMP,
CONF_MULTI_LIGHT_INTERCEPT,
CONF_PREFER_RGB_COLOR,
CONF_SEND_SPLIT_DELAY,
CONF_SEPARATE_TURN_ON_COMMANDS,
CONF_SKIP_REDUNDANT_COMMANDS,
CONF_SUNRISE_ENTITY,
CONF_SUNSET_ENTITY,
CONF_TARGET_LUX,
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
CONF_TRANSITION,
CONFIG_ENTRY_VERSION,
DEFAULT_INITIAL_TRANSITION,
DEFAULT_INTERCEPT,
DEFAULT_INTERVAL,
DEFAULT_LUX_SENSOR,
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
DEFAULT_MAX_BRIGHTNESS,
DEFAULT_MAX_COLOR_TEMP,
DEFAULT_MIN_BRIGHTNESS,
DEFAULT_MIN_COLOR_TEMP,
DEFAULT_MULTI_LIGHT_INTERCEPT,
DEFAULT_PREFER_RGB_COLOR,
DEFAULT_SEND_SPLIT_DELAY,
DEFAULT_SEPARATE_TURN_ON_COMMANDS,
DEFAULT_SKIP_REDUNDANT_COMMANDS,
DEFAULT_SUNRISE_ENTITY,
DEFAULT_SUNSET_ENTITY,
DEFAULT_TARGET_LUX,
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
DEFAULT_TRANSITION,
DOMAIN,
RANGE_ENTITIES,
)
2020-09-12 23:25:36 +02:00
_LOGGER = logging.getLogger(__name__)
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
# --- Section identifiers (also the translation-key roots in strings.json) ---
SECTION_TARGETS = "targets"
SECTION_DAYTIME = "daytime_curve"
SECTION_SUN = "sun_schedule"
SECTION_AMBIENT_LUX = "ambient_lux"
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
SECTION_LIGHT_CONTROL = "light_control"
SECTION_ADVANCED = "advanced"
SECTION_DIAGNOSTICS = "diagnostics"
2020-09-12 23:25:36 +02:00
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
# --- Selector factories (consistent units, ranges, units of measurement) ---
2020-09-12 23:25:36 +02:00
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
def _brightness_selector() -> NumberSelector:
return NumberSelector(
NumberSelectorConfig(
min=1,
max=100,
step=1,
unit_of_measurement="%",
mode=NumberSelectorMode.SLIDER,
),
)
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
def _color_temp_selector() -> NumberSelector:
return NumberSelector(
NumberSelectorConfig(
min=1000,
max=10000,
step=100,
unit_of_measurement="K",
mode=NumberSelectorMode.BOX,
),
)
def _duration_seconds_selector(max_value: int = 3600) -> NumberSelector:
return NumberSelector(
NumberSelectorConfig(
min=0,
max=max_value,
step=1,
unit_of_measurement="s",
mode=NumberSelectorMode.BOX,
),
)
def _duration_milliseconds_selector() -> NumberSelector:
return NumberSelector(
NumberSelectorConfig(
min=0,
max=10000,
step=10,
unit_of_measurement="ms",
mode=NumberSelectorMode.BOX,
),
)
def _lights_selector() -> EntitySelector:
return EntitySelector(EntitySelectorConfig(domain="light", multiple=True))
def _sun_event_selector() -> EntitySelector:
return EntitySelector(
EntitySelectorConfig(domain="sensor", device_class="timestamp"),
)
def _lux_sensor_selector() -> EntitySelector:
return EntitySelector(
EntitySelectorConfig(domain="sensor", device_class="illuminance"),
)
def _target_lux_selector() -> NumberSelector:
return NumberSelector(
NumberSelectorConfig(
min=1,
max=10000,
step=10,
unit_of_measurement="lx",
mode=NumberSelectorMode.BOX,
),
)
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
# --- Schema builder ---
def _build_options_schema(
current: dict[str, Any],
*,
show_send_split_delay: bool,
show_target_lux: bool,
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
) -> vol.Schema:
"""Build the sectioned options schema from the entry's current values."""
targets_section = section(
vol.Schema(
{
vol.Required(
CONF_LIGHTS,
default=current.get(CONF_LIGHTS, []),
): _lights_selector(),
},
),
{"collapsed": False},
)
daytime_section = section(
vol.Schema(
{
vol.Required(
CONF_MIN_BRIGHTNESS,
default=current.get(CONF_MIN_BRIGHTNESS, DEFAULT_MIN_BRIGHTNESS),
): _brightness_selector(),
vol.Required(
CONF_MAX_BRIGHTNESS,
default=current.get(CONF_MAX_BRIGHTNESS, DEFAULT_MAX_BRIGHTNESS),
): _brightness_selector(),
vol.Required(
CONF_MIN_COLOR_TEMP,
default=current.get(CONF_MIN_COLOR_TEMP, DEFAULT_MIN_COLOR_TEMP),
): _color_temp_selector(),
vol.Required(
CONF_MAX_COLOR_TEMP,
default=current.get(CONF_MAX_COLOR_TEMP, DEFAULT_MAX_COLOR_TEMP),
): _color_temp_selector(),
vol.Required(
CONF_PREFER_RGB_COLOR,
default=current.get(
CONF_PREFER_RGB_COLOR,
DEFAULT_PREFER_RGB_COLOR,
),
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
): BooleanSelector(),
},
),
{"collapsed": False},
)
sun_section = section(
vol.Schema(
{
vol.Required(
CONF_SUNRISE_ENTITY,
default=current.get(CONF_SUNRISE_ENTITY, DEFAULT_SUNRISE_ENTITY),
): _sun_event_selector(),
vol.Required(
CONF_SUNSET_ENTITY,
default=current.get(CONF_SUNSET_ENTITY, DEFAULT_SUNSET_ENTITY),
): _sun_event_selector(),
},
),
{"collapsed": True},
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
)
# An illuminance EntitySelector rejects an empty string, so we must NOT
# hand it `default=""`. When no sensor is configured, omit the default
# entirely (vol.UNDEFINED) so the field is simply absent on submit and
# treated as "unconfigured" — otherwise the form cannot be saved without
# selecting a lux sensor.
lux_default = current.get(CONF_LUX_SENSOR) or vol.UNDEFINED
ambient_lux_schema: dict[Any, Any] = {
vol.Optional(
CONF_LUX_SENSOR,
default=lux_default,
): _lux_sensor_selector(),
}
if show_target_lux:
ambient_lux_schema[
vol.Optional(
CONF_TARGET_LUX,
default=current.get(CONF_TARGET_LUX, DEFAULT_TARGET_LUX),
)
] = _target_lux_selector()
ambient_lux_section = section(
vol.Schema(ambient_lux_schema),
{"collapsed": True},
)
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
light_control_section = section(
vol.Schema(
{
vol.Required(
CONF_INTERCEPT,
default=current.get(CONF_INTERCEPT, DEFAULT_INTERCEPT),
): BooleanSelector(),
vol.Required(
CONF_MULTI_LIGHT_INTERCEPT,
default=current.get(
CONF_MULTI_LIGHT_INTERCEPT,
DEFAULT_MULTI_LIGHT_INTERCEPT,
),
): BooleanSelector(),
},
),
{"collapsed": True},
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
)
advanced_schema: dict[Any, Any] = {
vol.Required(
CONF_INTERVAL,
default=current.get(CONF_INTERVAL, DEFAULT_INTERVAL),
): _duration_seconds_selector(),
vol.Required(
CONF_TRANSITION,
default=current.get(CONF_TRANSITION, DEFAULT_TRANSITION),
): _duration_seconds_selector(max_value=300),
vol.Required(
CONF_INITIAL_TRANSITION,
default=current.get(CONF_INITIAL_TRANSITION, DEFAULT_INITIAL_TRANSITION),
): _duration_seconds_selector(max_value=300),
vol.Required(
CONF_ADAPT_DELAY,
default=current.get(CONF_ADAPT_DELAY, 0),
): _duration_seconds_selector(max_value=300),
vol.Required(
CONF_SEPARATE_TURN_ON_COMMANDS,
default=current.get(
CONF_SEPARATE_TURN_ON_COMMANDS,
DEFAULT_SEPARATE_TURN_ON_COMMANDS,
),
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
): BooleanSelector(),
vol.Required(
CONF_SKIP_REDUNDANT_COMMANDS,
default=current.get(
CONF_SKIP_REDUNDANT_COMMANDS,
DEFAULT_SKIP_REDUNDANT_COMMANDS,
),
): BooleanSelector(),
}
# Conditional visibility for send_split_delay: only when its driver
# (separate_turn_on_commands) is true. Spec R2.
if show_send_split_delay:
advanced_schema[
vol.Required(
CONF_SEND_SPLIT_DELAY,
default=current.get(CONF_SEND_SPLIT_DELAY, DEFAULT_SEND_SPLIT_DELAY),
)
] = _duration_milliseconds_selector()
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
advanced_section = section(
vol.Schema(advanced_schema),
{"collapsed": True},
)
diagnostics_section = section(
vol.Schema(
{
vol.Required(
CONF_INCLUDE_CONFIG_IN_ATTRIBUTES,
default=current.get(CONF_INCLUDE_CONFIG_IN_ATTRIBUTES, False),
): BooleanSelector(),
},
),
{"collapsed": True},
)
return vol.Schema(
{
vol.Required(SECTION_TARGETS): targets_section,
vol.Required(SECTION_DAYTIME): daytime_section,
vol.Required(SECTION_SUN): sun_section,
vol.Required(SECTION_AMBIENT_LUX): ambient_lux_section,
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
vol.Required(SECTION_LIGHT_CONTROL): light_control_section,
vol.Required(SECTION_ADVANCED): advanced_section,
vol.Required(SECTION_DIAGNOSTICS): diagnostics_section,
},
)
def _flatten_sections(sectioned: dict[str, Any]) -> dict[str, Any]:
"""Flatten a sectioned form result back into a flat options dict.
HA's section() wraps each section's values in a nested dict; we store
options flat (matching VALIDATION_TUPLES), so unwrap here.
"""
flat: dict[str, Any] = {}
for value in sectioned.values():
if isinstance(value, dict):
flat.update(value)
else:
flat[CONF_NAME] = value # unlikely fallback
return flat
2020-09-12 23:25:36 +02:00
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
def _has_pending_reveal(flat: dict[str, Any]) -> bool:
"""Return True when a just-toggled driver hides a dependent field.
HA's section() forms are not reactive, so when a user enables a driver
in this submission its dependent field was absent from the rendered
schema (and therefore from ``flat``). The caller re-shows the rebuilt
form so the dependent field appears in the same session, per the
options-flow conditional-visibility spec.
"""
return (bool(flat.get(CONF_LUX_SENSOR)) and CONF_TARGET_LUX not in flat) or (
bool(flat.get(CONF_SEPARATE_TURN_ON_COMMANDS))
and CONF_SEND_SPLIT_DELAY not in flat
)
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
class AdaptiveLightingConfigFlow(HAConfigFlow, domain=DOMAIN):
"""Handle a config flow for the CDiT Adaptive Lighting fork."""
VERSION = CONFIG_ENTRY_VERSION
async def async_step_user(self, user_input: dict[str, Any] | None = None):
"""Initial step: ask for a profile name."""
errors: dict[str, str] = {}
2020-09-12 23:25:36 +02:00
if user_input is not None:
2020-10-05 23:41:57 +02:00
await self.async_set_unique_id(user_input[CONF_NAME])
2020-09-12 23:25:36 +02:00
self._abort_if_unique_id_configured()
return self.async_create_entry(
title=user_input[CONF_NAME],
data=user_input,
)
return self.async_show_form(
step_id="user",
2020-10-05 23:41:57 +02:00
data_schema=vol.Schema({vol.Required(CONF_NAME): str}),
errors=errors,
)
2020-09-12 23:25:36 +02:00
2025-11-27 21:01:05 +01:00
async def async_step_import(self, user_input: dict[str, Any] | None = None):
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
"""Handle a YAML import.
YAML-configured entries can be loaded into HA but cannot be edited
via the options flow — see `OptionsFlowHandler.async_step_init`.
"""
2025-11-27 21:01:05 +01:00
if user_input is None:
return self.async_abort(reason="no_data")
2020-10-05 23:41:57 +02:00
await self.async_set_unique_id(user_input[CONF_NAME])
data = self.hass.data.setdefault(DOMAIN, {})
data.setdefault("__yaml__", set()).add(self.unique_id)
2020-09-28 16:10:05 +02:00
for entry in self._async_current_entries():
if entry.unique_id == self.unique_id:
2020-09-29 13:13:08 +02:00
self.hass.config_entries.async_update_entry(entry, data=user_input)
self._abort_if_unique_id_configured()
2020-10-05 23:41:57 +02:00
return self.async_create_entry(title=user_input[CONF_NAME], data=user_input)
2020-09-23 18:20:25 +02:00
2020-09-12 23:25:36 +02:00
@staticmethod
@callback
2025-11-27 21:01:05 +01:00
def async_get_options_flow(
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
config_entry: ConfigEntry, # noqa: ARG004
2025-11-27 21:01:05 +01:00
) -> "OptionsFlowHandler":
2020-09-12 23:25:36 +02:00
"""Get the options flow for this handler."""
2025-12-12 22:37:42 +01:00
return OptionsFlowHandler()
2020-09-12 23:25:36 +02:00
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
# Legacy alias so external code that does `from .config_flow import ConfigFlow`
# (such as upstream's docs/tests harness) still resolves.
ConfigFlow = AdaptiveLightingConfigFlow
2020-09-23 18:20:25 +02:00
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
class OptionsFlowHandler(OptionsFlowWithReload):
"""Sectioned options flow with reload-on-save.
2020-09-23 18:20:25 +02:00
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
Spec R6: extends OptionsFlowWithReload so saving triggers a clean
reload of the entry. Spec R7: YAML-managed entries abort with a
translation-keyed message instead of presenting an editable form.
"""
2020-09-12 23:25:36 +02:00
def _overlay_range_values(self, current: dict[str, Any]) -> None:
"""Overlay live runtime-range number entity values onto ``current``.
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
Keeps the dialog's brightness/color-temp defaults in sync with what
the four ``number`` entities are actually running (spec R6, D4).
"""
registry = er.async_get(self.hass)
for row in RANGE_ENTITIES:
unique_id = f"{self.config_entry.entry_id}_{row['field_key']}"
entity_id = registry.async_get_entity_id("number", DOMAIN, unique_id)
if entity_id is None:
continue
state = self.hass.states.get(entity_id)
if state is None or state.state in (None, "unavailable", "unknown"):
continue
try:
current[row["conf_key"]] = int(float(state.state))
except (TypeError, ValueError):
continue
async def async_step_init(self, user_input: dict[str, Any] | None = None):
"""Render the single-page options form and handle its submission."""
conf = self.config_entry
if conf.source == SOURCE_IMPORT:
return self.async_abort(reason="yaml_managed")
# Merge data and options to compute the effective "current" view.
current = dict(conf.data)
current.update(conf.options)
# Overlay live values from the four runtime range number entities
# so the dialog matches what the user's lights are actually running
# (spec R6, design D4). Other ~14 fields keep their `entry.options`
# values from above.
self._overlay_range_values(current)
2025-12-12 22:37:42 +01:00
errors: dict[str, str] = {}
2020-09-12 23:25:36 +02:00
if user_input is not None:
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
flat = _flatten_sections(user_input)
# Validate at least one light still exists.
all_lights = set(self.hass.states.async_entity_ids("light"))
for configured_light in flat.get(CONF_LIGHTS, []):
if configured_light not in all_lights:
errors[CONF_LIGHTS] = "entity_missing"
_LOGGER.error(
"Adaptive Lighting: light entity %s is configured but not "
"currently registered. Aborting save.",
configured_light,
)
break
2020-09-23 12:17:51 +02:00
if not errors:
if _has_pending_reveal(flat):
# Overlay the just-submitted values so the re-rendered
# form keeps the user's edits and recomputes conditional
# visibility from the new driver values below, instead of
# saving — the dependent field then appears in the same
# session (no save-and-reopen round-trip).
current.update(flat)
else:
return self.async_create_entry(title="", data=flat)
2020-09-19 11:10:54 +02:00
lux_sensor_id = current.get(CONF_LUX_SENSOR, DEFAULT_LUX_SENSOR)
lux_reading = "—"
if lux_sensor_id:
lux_state = self.hass.states.get(lux_sensor_id)
if lux_state and lux_state.state not in ("unavailable", "unknown"):
with contextlib.suppress(TypeError, ValueError):
lux_reading = f"{float(lux_state.state):.0f} lx"
2020-09-23 12:17:51 +02:00
return self.async_show_form(
step_id="init",
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
data_schema=_build_options_schema(
current,
show_send_split_delay=bool(
current.get(
CONF_SEPARATE_TURN_ON_COMMANDS,
DEFAULT_SEPARATE_TURN_ON_COMMANDS,
),
),
show_target_lux=bool(lux_sensor_id),
Implement cdit-config-redesign groups 1-6 (30/53 tasks) const.py: - Drop 21 retired CONF_*/DEFAULT_* (sleep cluster, manual sun timing, brightness curve variants, take-over-control cluster). - Add CONF_SUNRISE_ENTITY / CONF_SUNSET_ENTITY (default sensor.sun_next_rising / _setting). - Add RAMP_HALF_WIDTH_SECONDS = 1800. - Add CONFIG_ENTRY_VERSION = 2 (gate for strict version-break). - Re-default DEFAULT_MIN_BRIGHTNESS 1→5, DEFAULT_MIN_COLOR_TEMP 2000→2200. - Update ICON_MAIN / _BRIGHTNESS / _COLOR_TEMP to the CDiT picks. manifest.json: bump to 2.0.0-cdit.1, pin homeassistant: 2025.1.0, re-point codeowners/documentation/issue_tracker to the CaseyRo fork. switch.py: - Drop sleep_mode_switch creation in async_setup_entry; integration now creates 3 switches per profile (master, adapt_color, adapt_brightness). - Strip sleep-mode state machine from AdaptiveSwitch (sleep_mode_switch attribute, sleep_transition, adapt_until_sleep, the state-change listener, the _sleep_mode_switch_state_event_action method). - Bridge-stub _take_over_control / _detect_non_ha_changes / _adapt_only_on_bare_turn_on / _only_once / _auto_reset_manual_control_time as class-level False/0 so Manager-side branches become dead code without needing a full rewrite of AdaptiveLightingManager. - Remove handle_set_manual_control service + its registration. - Replace astral-driven curve init with the new SunLightSettings call shape; add AdaptiveSwitch._today_sun_events() helper that reads the configured sunrise/sunset entities. - Set _attr_icon on AdaptiveSwitch. color_and_brightness.py: - Rewrite SunLightSettings as a pure curve-math wrapper (5 fields: name + bounds + ramp half-width); methods take t_sunrise/t_sunset as args, never reads HA state. - Implement piecewise tanh ramp curve per spec R4 / design D11 in _tanh_day_curve(). Both brightness and color-temp use the same shape. - Drop SunEvents, sleep-mode branches, brightness_mode-switch, astral dependency, force_rgb_color, lerp_color_hsv sleep-tinted color blending. config_flow.py: - Rewrite as sectioned schema (Targets / Daytime curve / Sun schedule / Light control / Advanced / Diagnostics) via HA's section() helper. - Native HA selectors throughout (NumberSelector, EntitySelector, BooleanSelector). Strict typing on sun-event entity pickers. - Conditional visibility for send_split_delay (driver: separate_turn_on_commands). - Extend OptionsFlowWithReload (with ImportError fallback for HA < 2025.1 dev environment); async_abort(reason="yaml_managed") for SOURCE_IMPORT. - VERSION = CONFIG_ENTRY_VERSION. __init__.py: - Reject older config entries with ConfigEntryError ("recreate the entry") per spec R8 / design D4. - Add _remove_orphan_sleep_entities tombstone helper that scans the entity registry for sleep-mode entities owned by this entry and removes them on first setup. Idempotent and config_entry-scoped. _docs_helpers.py: stub the removed DOCS_MANUAL_CONTROL / SET_MANUAL_CONTROL_SCHEMA so the docs-generator script keeps importing. Validation: - ALL modules import cleanly under HA 2024.12.5 (dev env). - openspec validate cdit-config-redesign --strict: green. - ruff check --select=F: clean. Remaining: groups 7 (16 tests), 8 (strings + plain-language pass), 9 (docs).
2026-05-16 14:27:39 +02:00
),
description_placeholders={"current_lux": lux_reading},
errors=errors,
2020-09-23 12:17:51 +02:00
)