Skip to content

Fix OptionsFlow config_entry setter error in Home Assistant 2024.x+#165

Merged
fvanroie merged 1 commit intoHASwitchPlate:mainfrom
wjnelson78:fix/options-flow-config-entry-setter
Dec 17, 2025
Merged

Fix OptionsFlow config_entry setter error in Home Assistant 2024.x+#165
fvanroie merged 1 commit intoHASwitchPlate:mainfrom
wjnelson78:fix/options-flow-config-entry-setter

Conversation

@wjnelson78
Copy link
Contributor

Summary

This PR fixes a critical bug that causes a 500 Internal Server Error when clicking the gear (⚙️) icon to configure any openHASP plate in Home Assistant 2024.x+ versions.

Problem

When attempting to access the options flow for any openHASP plate device in Home Assistant, users receive:

500 Internal Server Error

The underlying error in the logs:

AttributeError: property 'config_entry' of 'OpenHASPOptionsFlowHandler' object has no setter
  File "custom_components/openhasp/config_flow.py", line 231, in __init__
    self.config_entry = config_entry

Root Cause

Starting with Home Assistant 2024.x, the config_entries.OptionsFlow base class changed config_entry from a regular attribute to a read-only property. The base class now automatically provides self.config_entry to subclasses.

The current code in OpenHASPOptionsFlowHandler tries to set self.config_entry = config_entry in its __init__ method, which fails because you cannot assign to a read-only property.

Solution

Remove the custom __init__ method from OpenHASPOptionsFlowHandler and rely on the base class to provide self.config_entry automatically. The async_get_options_flow method no longer needs to pass config_entry to the constructor.

Changes Made

Before:

@staticmethod
@callback
def async_get_options_flow(config_entry):
    return OpenHASPOptionsFlowHandler(config_entry)

class OpenHASPOptionsFlowHandler(config_entries.OptionsFlow):
    \"\"\"ConfigOptions flow for openHASP.\"\"\"

    def __init__(self, config_entry):
        \"\"\"Initialize openHASP options flow.\"\"\"
        self.config_entry = config_entry

    async def async_step_init(self, user_input=None):
        ...

After:

@staticmethod
@callback
def async_get_options_flow(config_entry):
    return OpenHASPOptionsFlowHandler()

class OpenHASPOptionsFlowHandler(config_entries.OptionsFlow):
    \"\"\"ConfigOptions flow for openHASP.\"\"\"

    async def async_step_init(self, user_input=None):
        ...

Testing

  • ✅ Tested on Home Assistant 2024.x
  • ✅ Verified options flow loads correctly for multiple openHASP plates
  • ✅ Confirmed all configuration options (idle brightness, pages path) work as expected
  • ✅ No regressions observed in plate functionality

Impact

This fix is backward compatible - the base class has provided config_entry automatically since HA introduced OptionsFlow. This change simply stops fighting against the framework.

Additional Notes

This is a minimal, targeted fix. The change:

  • Removes 4 lines of code (the __init__ method)
  • Changes 1 line (removes the parameter from constructor call)
  • Does not alter any functionality, only removes redundant/broken code

Author: William Nelson (@wjnelson78)
Affected versions: openHASP custom component 0.7.7 with Home Assistant 2024.x+

In Home Assistant 2024.x and later, the OptionsFlow base class provides
config_entry as a read-only property. The previous implementation tried
to set self.config_entry in __init__, which fails with:

    AttributeError: property 'config_entry' of 'OpenHASPOptionsFlowHandler'
    object has no setter

This caused a 500 Internal Server Error when clicking the gear icon to
configure any openHASP device in the integration settings.

Fix: Remove the custom __init__ method and don't pass config_entry to the
constructor. The base class automatically provides self.config_entry.
Copilot AI review requested due to automatic review settings December 15, 2025 20:46
Copy link

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 fixes a critical bug preventing users from accessing the configuration options for openHASP plates in Home Assistant 2024.x and later. The issue stems from Home Assistant's change to make config_entry a read-only property in the OptionsFlow base class, which conflicts with the custom __init__ method attempting to set this property.

Key Changes:

  • Removed the custom __init__ method from OpenHASPOptionsFlowHandler that was attempting to set the read-only config_entry property
  • Updated async_get_options_flow to instantiate OpenHASPOptionsFlowHandler without passing config_entry as a parameter
  • Relies on the base class to automatically provide self.config_entry to the subclass

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

@wjnelson78
Copy link
Contributor Author

@fvanroie - I wanted to add one clarifying note on impact: this issue doesn’t just surface as a stack trace — it fully breaks the Edit / Options UI path in Home Assistant.

Any attempt to click the gear icon on an existing openHASP config entry in HA 2024.x+ results in a 500 error, effectively preventing users from editing or updating device options after initial setup.

Because this occurs in the options flow constructor, it affects all existing installations once they upgrade Home Assistant, not just new setups.

This PR restores expected edit functionality by aligning with the updated OptionsFlow base class behavior and letting Home Assistant supply self.config_entry as intended.

Respectfully,
-Will

@fvanroie
Copy link
Collaborator

fvanroie commented Dec 17, 2025

Thank you for the PR and you comments. Please note that I am not able to review the proposed changes as I don't know the HA python code at all. I'm fully reliant on @dgomes for code review, or if this becomes critical I can publish a new version asap.
If it is reviewed in a timely fashion, I can add it to the pending 0.7.8 release. I just approved one PR, 2 are still pending.

@dgomes
Copy link
Collaborator

dgomes commented Dec 17, 2025

this is fine :) my setup is soo stable I haven't touched this in years 😓

@fvanroie fvanroie merged commit d3313d3 into HASwitchPlate:main Dec 17, 2025
2 checks passed
@fvanroie
Copy link
Collaborator

THanks! Version 0.7.8 of the Home Assistant Custom Component has been released.

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.

4 participants