diff --git a/homeassistant/components/config/config_entries.py b/homeassistant/components/config/config_entries.py index af90cdcba4b..edf94268741 100644 --- a/homeassistant/components/config/config_entries.py +++ b/homeassistant/components/config/config_entries.py @@ -97,6 +97,17 @@ class ConfigManagerEntryResourceReloadView(HomeAssistantView): return self.json({"require_restart": not result}) +def _prepare_config_flow_result_json(result, prepare_result_json): + """Convert result to JSON.""" + if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY: + return prepare_result_json(result) + + data = result.copy() + data["result"] = entry_json(result["result"]) + data.pop("data") + return data + + class ConfigManagerFlowIndexView(FlowManagerIndexView): """View to create config flows.""" @@ -118,13 +129,7 @@ class ConfigManagerFlowIndexView(FlowManagerIndexView): def _prepare_result_json(self, result): """Convert result to JSON.""" - if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY: - return super()._prepare_result_json(result) - - data = result.copy() - data["result"] = data["result"].entry_id - data.pop("data") - return data + return _prepare_config_flow_result_json(result, super()._prepare_result_json) class ConfigManagerFlowResourceView(FlowManagerResourceView): @@ -151,13 +156,7 @@ class ConfigManagerFlowResourceView(FlowManagerResourceView): def _prepare_result_json(self, result): """Convert result to JSON.""" - if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY: - return super()._prepare_result_json(result) - - data = result.copy() - data["result"] = entry_json(result["result"]) - data.pop("data") - return data + return _prepare_config_flow_result_json(result, super()._prepare_result_json) class ConfigManagerAvailableFlowView(HomeAssistantView): diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 7e4df556fa5..128d0798b66 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -320,7 +320,17 @@ async def test_create_account(hass, client): "title": "Test Entry", "type": "create_entry", "version": 1, - "result": entries[0].entry_id, + "result": { + "connection_class": "unknown", + "disabled_by": None, + "domain": "test", + "entry_id": entries[0].entry_id, + "source": "user", + "state": "loaded", + "supports_options": False, + "supports_unload": False, + "title": "Test Entry", + }, "description": None, "description_placeholders": None, }