Skip to content

Fix: Config flow options ignored and Options flow 500 error#448

Open
maileys wants to merge 3 commits intosockless-coding:masterfrom
maileys:fix/energy-sensor-config-and-500-error
Open

Fix: Config flow options ignored and Options flow 500 error#448
maileys wants to merge 3 commits intosockless-coding:masterfrom
maileys:fix/energy-sensor-config-and-500-error

Conversation

@maileys
Copy link
Copy Markdown

@maileys maileys commented May 5, 2026

Fixes #403
Fixes #420

Three related bugs preventing user-selected config options (energy sensors, nanoe, preset names, fetch intervals) from being applied.
Bug 1: User input discarded in config flow (config_flow.py)
async_step_user() collects the full user_input dict (including energy sensor, nanoe, preset names, fetch intervals), but passes only username and password to _create_device() → _create_entry(), which hardcodes all other values to their defaults. The user's selections from the setup form are never saved.
Fix: Pass the full user_input dict through _create_device() → _create_entry() so all user-selected values are persisted to entry.data.
Bug 2: entry.data not migrated to entry.options (init.py)
The integration's consumers (switch.py, climate.py, coordinator.py, init.py) read settings from entry.options, but the initial config flow saves values to entry.data. entry.options is only populated after the Options flow is used. On a fresh install entry.options is empty, so all settings fall back to defaults.
Fix: Added a migration block in async_setup_entry() that populates entry.options from entry.data when entry.options is empty. This runs once on first startup after install, ensuring all consumers read the correct values without needing changes to each individual consumer.
Bug 3: Options flow crashes with 500 error (config_flow.py)
PanasonicOptionsFlowHandler.init() sets self.config_entry = config_entry, but newer Home Assistant versions made config_entry a read-only property on OptionsFlow. This raises AttributeError: property 'config_entry' of 'PanasonicOptionsFlowHandler' object has no setter, causing a 500 Internal Server Error when clicking Configure.
Fix: Removed the init method from PanasonicOptionsFlowHandler and removed the config_entry argument from the constructor call in async_get_options_flow(). The base OptionsFlow class already provides self.config_entry automatically.
Testing

Fresh install with energy sensor checkbox ticked → energy sensors created ✓
Fresh install with energy sensor checkbox unticked → no energy sensors ✓
Configure button (Options flow) no longer throws 500 error ✓
Options values correctly migrated from entry.data to entry.options on startup ✓
Existing installs with options already configured → behaviour unchanged ✓

Files changed

custom_components/panasonic_cc/init.py
custom_components/panasonic_cc/config_flow.py

maileys added 3 commits May 6, 2026 01:28
Migrate initial setup options from entry.data to entry.options for consistent access.

Fixes current issues with energy entities not being created on initial setup
thi should resolve the 500 error when accessing the configuration button in hass
Copilot AI review requested due to automatic review settings May 5, 2026 17:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to ensure user-selected configuration/options (energy sensors, nanoe, preset naming, fetch intervals) are persisted correctly and applied consistently by the integration, and to fix a crash when opening the Options flow.

Changes:

  • Pass full user_input through the config flow device creation path so selected options are saved into the config entry data.
  • Add a one-time migration in async_setup_entry() to populate entry.options from entry.data when entry.options is empty.
  • Adjust the Options flow handler initialization to avoid setting a now-read-only config_entry property.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
custom_components/panasonic_cc/config_flow.py Updates config flow to persist full user selections and modifies how the options flow handler is instantiated.
custom_components/panasonic_cc/init.py Adds migration logic from entry.dataentry.options during setup to align with consumers reading entry.options.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread custom_components/panasonic_cc/config_flow.py
Comment thread custom_components/panasonic_cc/config_flow.py
Comment thread custom_components/panasonic_cc/__init__.py
@maileys
Copy link
Copy Markdown
Author

maileys commented May 5, 2026

Test evidence:
Energy sensors created successfully after fresh install with checkbox ticked:
image

Options flow working — no longer throws 500 error:
image

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.

Setup Energy entities gone

2 participants