Skip to content

Commit 0b4d4e2

Browse files
Fix OptionsFlow config_entry access pattern
Add config_entry property to OptionsFlowHandler for proper access to the config entry. This ensures compatibility across different Home Assistant versions and testing frameworks.
1 parent c6df3ab commit 0b4d4e2

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

custom_components/mitsubishi/config_flow.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,13 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
133133

134134
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
135135
"""Initialize options flow."""
136-
super().__init__()
137136
self._config_entry = config_entry
138137

138+
@property
139+
def config_entry(self) -> config_entries.ConfigEntry:
140+
"""Return the config entry."""
141+
return self._config_entry
142+
139143
async def async_step_init(self, user_input: dict[str, Any] | None = None) -> Any:
140144
"""Manage the options."""
141145
errors: dict[str, str] = {}
@@ -154,12 +158,12 @@ async def async_step_init(self, user_input: dict[str, Any] | None = None) -> Any
154158

155159
# Update the config entry data (connection settings)
156160
self.hass.config_entries.async_update_entry(
157-
self._config_entry,
161+
self.config_entry,
158162
data=user_input,
159163
)
160164

161165
# Trigger reload of the integration to apply changes
162-
await self.hass.config_entries.async_reload(self._config_entry.entry_id)
166+
await self.hass.config_entries.async_reload(self.config_entry.entry_id)
163167

164168
# Build new options, preserving remote_temp_mode if it exists
165169
new_options = {
@@ -168,8 +172,8 @@ async def async_step_init(self, user_input: dict[str, Any] | None = None) -> Any
168172
if experimental_features and external_temp_entity:
169173
new_options[CONF_EXTERNAL_TEMP_ENTITY] = external_temp_entity
170174
# Preserve remote_temp_mode from existing options
171-
if CONF_REMOTE_TEMP_MODE in self._config_entry.options:
172-
new_options[CONF_REMOTE_TEMP_MODE] = self._config_entry.options[
175+
if CONF_REMOTE_TEMP_MODE in self.config_entry.options:
176+
new_options[CONF_REMOTE_TEMP_MODE] = self.config_entry.options[
173177
CONF_REMOTE_TEMP_MODE
174178
]
175179

@@ -183,21 +187,21 @@ async def async_step_init(self, user_input: dict[str, Any] | None = None) -> Any
183187
errors["base"] = "unknown"
184188

185189
# Create options schema with current values as defaults
186-
current_host = self._config_entry.data.get(CONF_HOST, "")
187-
current_encryption_key = self._config_entry.data.get(
190+
current_host = self.config_entry.data.get(CONF_HOST, "")
191+
current_encryption_key = self.config_entry.data.get(
188192
CONF_ENCRYPTION_KEY, DEFAULT_ENCRYPTION_KEY
189193
)
190-
current_admin_username = self._config_entry.data.get(
194+
current_admin_username = self.config_entry.data.get(
191195
CONF_ADMIN_USERNAME, DEFAULT_ADMIN_USERNAME
192196
)
193-
current_admin_password = self._config_entry.data.get(
197+
current_admin_password = self.config_entry.data.get(
194198
CONF_ADMIN_PASSWORD, DEFAULT_ADMIN_PASSWORD
195199
)
196-
current_scan_interval = self._config_entry.data.get(
200+
current_scan_interval = self.config_entry.data.get(
197201
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
198202
)
199-
current_experimental = self._config_entry.options.get(CONF_EXPERIMENTAL_FEATURES, False)
200-
current_external_temp_entity = self._config_entry.options.get(CONF_EXTERNAL_TEMP_ENTITY, "")
203+
current_experimental = self.config_entry.options.get(CONF_EXPERIMENTAL_FEATURES, False)
204+
current_external_temp_entity = self.config_entry.options.get(CONF_EXTERNAL_TEMP_ENTITY, "")
201205

202206
# Base schema with connection settings
203207
schema_dict = {

0 commit comments

Comments
 (0)