Allow saving the empty default notify target

An empty target means notifications are not configured yet and is the
shipped default; only malformed strings (padded or whitespace-only)
reject.
This commit is contained in:
2026-09-19 14:20:13 -04:00
parent 3c832c1cee
commit fbde3eeaa1
2 changed files with 23 additions and 6 deletions
+8 -4
View File
@@ -98,11 +98,15 @@ def _async_validate(user_input: dict[str, Any]) -> dict[str, str]:
):
errors[time_key] = "invalid_time"
notify_target = user_input.get(CONF_NOTIFY_TARGET)
if notify_target is not None and (
not isinstance(notify_target, str)
or not notify_target.strip()
or notify_target != notify_target.strip()
if notify_target is not None and not isinstance(notify_target, str):
errors[CONF_NOTIFY_TARGET] = "invalid"
elif isinstance(notify_target, str) and notify_target != (
notify_target.strip()
):
# An EMPTY target is valid — it means "no notifications
# configured yet" and is the shipped default; a value that
# differs from its own trim (padded or whitespace-only) is
# malformed and rejected.
errors[CONF_NOTIFY_TARGET] = "invalid"
for toggle_key in (
CONF_MORNING_SUMMARY_ENABLED,
+15 -2
View File
@@ -712,9 +712,22 @@ def test_options_flow_notification_times_must_be_strict_hh_mm() -> None:
assert result["errors"] == {CONF_MORNING_SUMMARY_TIME: "invalid_time"}
def test_options_flow_notify_target_must_be_clean_nonempty_string() -> None:
def test_options_flow_notify_target_validation() -> None:
"""The empty target is VALID (it is the shipped default and must be
savable); only malformed non-empty values reject."""
flow = _make_flow(_make_entry())
for bad_target in ("", " notify.x ", 42):
# The empty default saves cleanly.
result = _run(
flow.async_step_init(
{**VALID_INPUT, CONF_NOTIFY_TARGET: ""}
)
)
assert result["type"] == "create_entry"
assert result["data"][CONF_NOTIFY_TARGET] == ""
# Malformed non-empty values reject.
for bad_target in (" notify.x ", " ", 42):
flow = _make_flow(_make_entry())
result = _run(
flow.async_step_init(
{