Skip to content

v1.4.0: Prevent HTTP 500 errors and refactor to HA integration best practices#29

Merged
Geek-MD merged 7 commits intomainfrom
copilot/fix-config-flow-error-500
Feb 17, 2026
Merged

v1.4.0: Prevent HTTP 500 errors and refactor to HA integration best practices#29
Geek-MD merged 7 commits intomainfrom
copilot/fix-config-flow-error-500

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 17, 2026

Config flow crashes with HTTP 500 when encountering empty entity lists, invalid domains, or schema construction failures during configuration. Additionally, code structure did not follow Home Assistant integration conventions used by professional integrations like Battery Devices Monitor.

Error Handling

Wrapped all flow steps in defensive error boundaries:

  • Try-except blocks around user input processing and schema construction
  • Fallback schemas when primary construction fails
  • Early return on empty entity lists instead of invalid dropdown construction
  • Structured logging throughout flow lifecycle

Example:

# Before: crashes on empty available_entities
select_options = [SelectOptionDict(value=e, label=e) for e in available_entities]

# After: safe fallback
try:
    if not available_entities:
        return await self.async_step_finish()
    select_options = [SelectOptionDict(value=e, label=e) for e in available_entities]
    data_schema = vol.Schema({...})
except Exception as err:
    _LOGGER.error("Error building schema: %s", err, exc_info=True)
    data_schema = vol.Schema({
        vol.Required(ATTR_TRIGGER_ENTITY): EntitySelector(EntitySelectorConfig())
    })

Structure Refactoring

Aligned with HA best practices:

  • Renamed HADailyCounterConfigFlowFlowHandler
  • Renamed HADailyCounterOptionsFlowOptionsFlowHandler
  • Consolidated both classes into config_flow.py (removed separate options_flow.py)
  • Updated type hints to modern Python syntax (dict[str, Any] vs Dict[str, Any])

Files changed:

  • config_flow.py: +402/-116 lines (now 540 lines, contains both flow handlers)
  • options_flow.py: deleted (217 lines)
  • manifest.json: version → 1.4.0
  • CHANGELOG.md: release notes

Structure now matches Battery Devices Monitor and other professional HA integrations where both flow handlers reside in single file.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 17, 2026 06:02
…Devices Monitor pattern

Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com>
Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com>
…es and None domain

Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error 500 in config_flow.py for integration reconfiguration Fix HTTP 500 errors in config flow with defensive error handling Feb 17, 2026
Copilot AI requested a review from Geek-MD February 17, 2026 06:06
Copilot AI changed the title Fix HTTP 500 errors in config flow with defensive error handling v1.4.0: Prevent HTTP 500 errors in config flow with defensive error handling Feb 17, 2026
Copilot AI and others added 3 commits February 17, 2026 06:15
… practices

Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com>
…ctices

Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com>
Co-authored-by: Geek-MD <25725990+Geek-MD@users.noreply.github.com>
Copilot AI changed the title v1.4.0: Prevent HTTP 500 errors in config flow with defensive error handling v1.4.0: Prevent HTTP 500 errors and refactor to HA integration best practices Feb 17, 2026
@Geek-MD Geek-MD marked this pull request as ready for review February 17, 2026 06:21
@Geek-MD Geek-MD merged commit f9ce753 into main Feb 17, 2026
3 checks passed
@Geek-MD Geek-MD deleted the copilot/fix-config-flow-error-500 branch February 17, 2026 06:21
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.

2 participants