Skip to content

Commit af9a284

Browse files
authored
Fix options flow handler. Fixes issue #229 (#233)
1 parent fd61b5c commit af9a284

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

custom_components/connectlife/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import logging
6+
57
from homeassistant.exceptions import ConfigEntryError
68
from homeassistant.config_entries import ConfigEntry
79
from homeassistant.const import Platform, CONF_USERNAME, CONF_PASSWORD
@@ -26,6 +28,8 @@
2628

2729
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
2830

31+
_LOGGER = logging.getLogger(__name__)
32+
2933

3034
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
3135
"""Set up ConnectLife."""
@@ -37,6 +41,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
3741

3842
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
3943
"""Set up ConnectLife from a config entry."""
44+
_LOGGER.debug("Setting up ConnectLife")
45+
_LOGGER.debug("Options: %s", entry.options)
4046
hass.data.setdefault(DOMAIN, {})
4147
test_server_url = (
4248
entry.options.get(CONF_TEST_SERVER_URL)
@@ -60,13 +66,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
6066

6167
return True
6268

63-
async def update_listener(hass, entry):
69+
async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> bool:
6470
"""Handle options update."""
71+
_LOGGER.debug(f"Reloading ConnectLife")
6572
await hass.config_entries.async_reload(entry.entry_id)
6673

6774

6875
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
6976
"""Unload a config entry."""
77+
_LOGGER.debug(f"Unloading ConnectLife")
7078

7179
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
7280
hass.data[DOMAIN].pop(entry.entry_id)

custom_components/connectlife/config_flow.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import copy
65
import logging
76
from typing import Any
87

@@ -82,7 +81,7 @@ def async_get_options_flow(
8281
config_entry: ConfigEntry,
8382
) -> OptionsFlow:
8483
"""Get the options flow for this handler."""
85-
return OptionsFlowHandler(config_entry)
84+
return OptionsFlowHandler()
8685

8786

8887
class CannotConnect(HomeAssistantError):
@@ -96,10 +95,6 @@ class InvalidAuth(HomeAssistantError):
9695
class OptionsFlowHandler(OptionsFlow):
9796
"""Handles options flow for the component."""
9897

99-
def __init__(self, config_entry: ConfigEntry) -> None:
100-
"""Initialize the options flow."""
101-
self.config_entry = config_entry
102-
10398
async def async_step_init(self, user_input=None):
10499
return self.async_show_menu(
105100
step_id="init",
@@ -167,10 +162,9 @@ async def async_step_development(self, user_input: dict[str, Any] | None = None)
167162
)
168163
return self.async_show_form(step_id="development", data_schema=schema, errors=errors)
169164

170-
data = copy.deepcopy(self.config_entry.options).update({
171-
CONF_DEVELOPMENT_MODE: development_mode,
172-
CONF_TEST_SERVER_URL: test_server_url
173-
})
165+
data = self.config_entry.options.copy()
166+
data[CONF_DEVELOPMENT_MODE] = development_mode
167+
data[CONF_TEST_SERVER_URL] = test_server_url
174168
return self.async_create_entry(title="", data=data)
175169

176170
development_mode = self.config_entry.options.get(CONF_DEVELOPMENT_MODE, False)

0 commit comments

Comments
 (0)