Return config entry details for 1-step config flows (#48585)
parent
2bf91fa359
commit
d26d2a8446
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue