Skip to content

Commit b22e008

Browse files
committed
use backwards compatible approach
1 parent b3e7bd8 commit b22e008

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

custom_components/pyscript/config_flow.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ class PyscriptOptionsConfigFlow(config_entries.OptionsFlow):
2121
def __init__(self, config_entry: ConfigEntry) -> None:
2222
"""Initialize pyscript options flow."""
2323
self.config_entry = config_entry
24+
self._show_form = False
2425

2526
async def async_step_init(self, user_input: Dict[str, Any] = None) -> Dict[str, Any]:
2627
"""Manage the pyscript options."""
2728
if self.config_entry.source == SOURCE_IMPORT:
28-
return self.async_abort(reason="no_ui_configuration_allowed")
29+
self._show_form = True
30+
return await self.async_step_no_ui_configuration_allowed()
2931

3032
if user_input is None:
3133
return self.async_show_form(
@@ -46,7 +48,26 @@ async def async_step_init(self, user_input: Dict[str, Any] = None) -> Dict[str,
4648
self.hass.config_entries.async_update_entry(entry=self.config_entry, data=updated_data)
4749
return self.async_create_entry(title="", data={})
4850

49-
return self.async_abort(reason="no_update")
51+
self._show_form = True
52+
return await self.async_step_no_update()
53+
54+
async def async_step_no_ui_configuration_allowed(
55+
self, user_input: Dict[str, Any] = None
56+
) -> Dict[str, Any]:
57+
"""Tell user no UI configuration is allowed."""
58+
if self._show_form:
59+
self._show_form = False
60+
return self.async_show_form(step_id="no_ui_configuration_allowed", data_schema=vol.Schema({}))
61+
62+
return self.async_create_entry(title="", data={})
63+
64+
async def async_step_no_update(self, user_input: Dict[str, Any] = None) -> Dict[str, Any]:
65+
"""Tell user no update to process."""
66+
if self._show_form:
67+
self._show_form = False
68+
return self.async_show_form(step_id="no_update", data_schema=vol.Schema({}))
69+
70+
return self.async_create_entry(title="", data={})
5071

5172

5273
class PyscriptConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

custom_components/pyscript/strings.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
"data": {
2323
"allow_all_imports": "Allow All Imports?"
2424
}
25+
},
26+
"no_ui_configuration_allowed": {
27+
"title": "No UI configuration allowed",
28+
"description": "This entry was created via `configuration.yaml`, so all configuration parameters must be updated there. The [`pyscript.reload`](developer-tools/service) service will allow you to apply the changes you make to `configuration.yaml` without restarting your Home Assistant instance."
29+
},
30+
"no_update": {
31+
"title": "No update needed",
32+
"description": "There is nothing to update."
2533
}
26-
},
27-
"abort": {
28-
"no_ui_configuration_allowed": "This entry was created via `configuration.yaml`, so all configuration parameters must be updated there. The [`pyscript.reload`](developer-tools/service) service will allow you to apply the changes you make to `configuration.yaml` without restarting your Home Assistant instance.",
29-
"no_update": "There is nothing to update."
3034
}
3135
}
3236
}

custom_components/pyscript/translations/en.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
"data": {
2323
"allow_all_imports": "Allow All Imports?"
2424
}
25+
},
26+
"no_ui_configuration_allowed": {
27+
"title": "No UI configuration allowed",
28+
"description": "This entry was created via `configuration.yaml`, so all configuration parameters must be updated there. The [`pyscript.reload`](developer-tools/service) service will allow you to apply the changes you make to `configuration.yaml` without restarting your Home Assistant instance."
29+
},
30+
"no_update": {
31+
"title": "No update needed",
32+
"description": "There is nothing to update."
2533
}
26-
},
27-
"abort": {
28-
"no_ui_configuration_allowed": "This entry was created via `configuration.yaml`, so all configuration parameters must be updated there. The [`pyscript.reload`](developer-tools/service) service will allow you to apply the changes you make to `configuration.yaml` without restarting your Home Assistant instance.",
29-
"no_update": "There is nothing to update."
3034
}
3135
}
3236
}

tests/test_config_flow.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,13 @@ async def test_options_flow_import(hass):
187187

188188
result = await hass.config_entries.options.async_init(entry.entry_id, data=None)
189189

190-
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
191-
assert result["reason"] == "no_ui_configuration_allowed"
190+
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
191+
assert result["step_id"] == "no_ui_configuration_allowed"
192+
193+
result = await hass.config_entries.options.async_configure(result["flow_id"], user_input=None)
194+
195+
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
196+
assert result["title"] == ""
192197

193198

194199
async def test_options_flow_user_change(hass):
@@ -234,5 +239,10 @@ async def test_options_flow_user_no_change(hass):
234239
result["flow_id"], user_input={CONF_ALLOW_ALL_IMPORTS: True}
235240
)
236241

237-
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
238-
assert result["reason"] == "no_update"
242+
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
243+
assert result["step_id"] == "no_update"
244+
245+
result = await hass.config_entries.options.async_configure(result["flow_id"], user_input=None)
246+
247+
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
248+
assert result["title"] == ""

0 commit comments

Comments
 (0)