Skip to content

fix(config_flow): 🐛 stop options flow crashing with a 500 on default update interval#668

Merged
rhammen merged 1 commit into
mainfrom
fix/options-flow-update-interval-serialization
Jul 4, 2026
Merged

fix(config_flow): 🐛 stop options flow crashing with a 500 on default update interval#668
rhammen merged 1 commit into
mainfrom
fix/options-flow-update-interval-serialization

Conversation

@rhammen

@rhammen rhammen commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

🐞 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.log in #656:

ERROR (MainThread) [homeassistant.helpers.http] Unable to serialize to JSON. Bad data found at
$.data_schema[1].default=0:01:00(<class 'datetime.timedelta'>, $.data_schema[1].description.suggested_value=0:01:00(<class 'datetime.timedelta'>

DEFAULT_UPDATE_INTERVAL (timedelta(seconds=60)) was reused as the fallback default for the options flow's CONF_UPDATE_INTERVAL field. That field is a SelectSelector whose valid values are the string keys of UPDATE_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 raw timedelta into the schema's default/suggested_value. The frontend serializes the schema to JSON to render the form, and timedelta isn'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

  • Add DEFAULT_UPDATE_INTERVAL_OPTION to const.py: the UPDATE_INTERVAL_OPTIONS string key matching DEFAULT_UPDATE_INTERVAL, derived from the dict itself so the two can never drift apart.
  • Use it instead of DEFAULT_UPDATE_INTERVAL in config_flow.py and schema_helper.py wherever the options-flow schema needs a default. DEFAULT_UPDATE_INTERVAL itself is untouched and still correctly used as the coordinator's own polling-interval fallback.

🧪 Testing

  • New regression test: build_options_schema() with no stored interval is run through voluptuous_serialize.convert() + json.dumps() — the exact path Home Assistant's frontend uses — and must not raise. Verified this test fails with the exact reported TypeError: Object of type timedelta is not JSON serializable against the old code.
  • New const-level test pinning DEFAULT_UPDATE_INTERVAL_OPTION to a valid UPDATE_INTERVAL_OPTIONS key.
  • pytest -q — 746 passed
  • ruff check / ruff format --check — clean
  • basedpyright — 0 errors

✅ Test plan

  • Confirm "Configure" (gear icon) opens without error on an entry that has never saved options before
  • Confirm the update-interval dropdown still shows/saves correctly

Resolves #656

🤖 Generated with Claude Code

…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>
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
custom_components.luxtronik2 100%
Summary 100% (2881 / 2881)

@rhammen rhammen merged commit 27ae54b into main Jul 4, 2026
9 checks passed
@rhammen rhammen deleted the fix/options-flow-update-interval-serialization branch July 4, 2026 11:44
@blue-bean blue-bean mentioned this pull request Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integration issues

1 participant