fix(config_flow): 🐛 stop options flow crashing with a 500 on default update interval#668
Merged
Merged
Conversation
…update interval - add DEFAULT_UPDATE_INTERVAL_OPTION, the UPDATE_INTERVAL_OPTIONS string key matching DEFAULT_UPDATE_INTERVAL, derived from the dict so the two can't drift apart - use it instead of DEFAULT_UPDATE_INTERVAL as the options flow's CONF_UPDATE_INTERVAL fallback in config_flow.py and schema_helper.py - DEFAULT_UPDATE_INTERVAL is a timedelta, correct for the coordinator's own polling fallback, but wrong for the options form: its SelectSelector default/suggested_value must be one of UPDATE_INTERVAL_OPTIONS' string keys. Any entry that had never saved options before (the common case) hit this fallback and got a timedelta in the schema, which the frontend can't serialize to JSON - exactly the 500 reported in #656, confirmed against a user's log: "Bad data found at $.data_schema[1].default=0:01:00(<class 'datetime.timedelta'>" - add regression tests: build_options_schema() with no stored interval now round-trips through voluptuous_serialize + json.dumps exactly as the frontend does, and a const-level test pins DEFAULT_UPDATE_INTERVAL_OPTION to a valid UPDATE_INTERVAL_OPTIONS key Resolves #656 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐞 Problem
Opening "Configure" (gear icon) on the integration entry gives a
500 Internal Server Error, reported across #656.🔍 Root cause
Confirmed against a user's
home-assistant.login #656:DEFAULT_UPDATE_INTERVAL(timedelta(seconds=60)) was reused as the fallback default for the options flow'sCONF_UPDATE_INTERVALfield. That field is aSelectSelectorwhose valid values are the string keys ofUPDATE_INTERVAL_OPTIONS("10 seconds","1 minute (default)", ...) — not the timedelta itself. Any config entry that had never explicitly saved options before (the common case: fresh installs, reconfigured entries, anyone who hasn't touched the update-interval dropdown) fell through to this fallback, putting a rawtimedeltainto the schema'sdefault/suggested_value. The frontend serializes the schema to JSON to render the form, andtimedeltaisn't JSON-serializable — hence the 500.This was introduced when the update-interval option was added (
66c9fbe, 2026-06-14) and is untouched by the earlier coordinator-refresh-ordering fixes in this issue, which is why those didn't resolve it.🔧 Fix
DEFAULT_UPDATE_INTERVAL_OPTIONtoconst.py: theUPDATE_INTERVAL_OPTIONSstring key matchingDEFAULT_UPDATE_INTERVAL, derived from the dict itself so the two can never drift apart.DEFAULT_UPDATE_INTERVALinconfig_flow.pyandschema_helper.pywherever the options-flow schema needs a default.DEFAULT_UPDATE_INTERVALitself is untouched and still correctly used as the coordinator's own polling-interval fallback.🧪 Testing
build_options_schema()with no stored interval is run throughvoluptuous_serialize.convert()+json.dumps()— the exact path Home Assistant's frontend uses — and must not raise. Verified this test fails with the exact reportedTypeError: Object of type timedelta is not JSON serializableagainst the old code.DEFAULT_UPDATE_INTERVAL_OPTIONto a validUPDATE_INTERVAL_OPTIONSkey.pytest -q— 746 passedruff check/ruff format --check— cleanbasedpyright— 0 errors✅ Test plan
Resolves #656
🤖 Generated with Claude Code