Return config entry details for 1-step config flows (#48585)

pull/48593/head
Erik Montnemery 2021-04-01 16:20:53 +02:00 committed by GitHub
parent 2bf91fa359
commit d26d2a8446
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 15 deletions

View File

@ -97,6 +97,17 @@ class ConfigManagerEntryResourceReloadView(HomeAssistantView):
return self.json({"require_restart": not result}) 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): class ConfigManagerFlowIndexView(FlowManagerIndexView):
"""View to create config flows.""" """View to create config flows."""
@ -118,13 +129,7 @@ class ConfigManagerFlowIndexView(FlowManagerIndexView):
def _prepare_result_json(self, result): def _prepare_result_json(self, result):
"""Convert result to JSON.""" """Convert result to JSON."""
if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY: return _prepare_config_flow_result_json(result, super()._prepare_result_json)
return super()._prepare_result_json(result)
data = result.copy()
data["result"] = data["result"].entry_id
data.pop("data")
return data
class ConfigManagerFlowResourceView(FlowManagerResourceView): class ConfigManagerFlowResourceView(FlowManagerResourceView):
@ -151,13 +156,7 @@ class ConfigManagerFlowResourceView(FlowManagerResourceView):
def _prepare_result_json(self, result): def _prepare_result_json(self, result):
"""Convert result to JSON.""" """Convert result to JSON."""
if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY: return _prepare_config_flow_result_json(result, super()._prepare_result_json)
return super()._prepare_result_json(result)
data = result.copy()
data["result"] = entry_json(result["result"])
data.pop("data")
return data
class ConfigManagerAvailableFlowView(HomeAssistantView): class ConfigManagerAvailableFlowView(HomeAssistantView):

View File

@ -320,7 +320,17 @@ async def test_create_account(hass, client):
"title": "Test Entry", "title": "Test Entry",
"type": "create_entry", "type": "create_entry",
"version": 1, "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": None,
"description_placeholders": None, "description_placeholders": None,
} }