Fix OptionsFlow config_entry setter error in Home Assistant 2024.x+#165
Conversation
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.
There was a problem hiding this comment.
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 fromOpenHASPOptionsFlowHandlerthat was attempting to set the read-onlyconfig_entryproperty - Updated
async_get_options_flowto instantiateOpenHASPOptionsFlowHandlerwithout passingconfig_entryas a parameter - Relies on the base class to automatically provide
self.config_entryto the subclass
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@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, |
|
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. |
|
this is fine :) my setup is soo stable I haven't touched this in years 😓 |
|
THanks! Version 0.7.8 of the Home Assistant Custom Component has been released. |
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:
The underlying error in the logs:
Root Cause
Starting with Home Assistant 2024.x, the
config_entries.OptionsFlowbase class changedconfig_entryfrom a regular attribute to a read-only property. The base class now automatically providesself.config_entryto subclasses.The current code in
OpenHASPOptionsFlowHandlertries to setself.config_entry = config_entryin its__init__method, which fails because you cannot assign to a read-only property.Solution
Remove the custom
__init__method fromOpenHASPOptionsFlowHandlerand rely on the base class to provideself.config_entryautomatically. Theasync_get_options_flowmethod no longer needs to passconfig_entryto the constructor.Changes Made
Before:
After:
Testing
Impact
This fix is backward compatible - the base class has provided
config_entryautomatically since HA introduced OptionsFlow. This change simply stops fighting against the framework.Additional Notes
This is a minimal, targeted fix. The change:
__init__method)Author: William Nelson (@wjnelson78)
Affected versions: openHASP custom component 0.7.7 with Home Assistant 2024.x+