Make context in data entry flow possible to modify for subclasses (#110561)
* Make context in data entry flow possible to modify for subclasses * mypy * Make get_context * base view * Review comments * Remove context from options flow
This commit is contained in:
parent
23e81a45c8
commit
cb776593cf
2 changed files with 12 additions and 5 deletions
|
@ -157,6 +157,12 @@ class ConfigManagerFlowIndexView(FlowManagerIndexView):
|
||||||
status=HTTPStatus.BAD_REQUEST,
|
status=HTTPStatus.BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_context(self, data: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
"""Return context."""
|
||||||
|
context = super().get_context(data)
|
||||||
|
context["source"] = config_entries.SOURCE_USER
|
||||||
|
return context
|
||||||
|
|
||||||
def _prepare_result_json(
|
def _prepare_result_json(
|
||||||
self, result: data_entry_flow.FlowResult
|
self, result: data_entry_flow.FlowResult
|
||||||
) -> data_entry_flow.FlowResult:
|
) -> data_entry_flow.FlowResult:
|
||||||
|
|
|
@ -8,7 +8,7 @@ from aiohttp import web
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
import voluptuous_serialize
|
import voluptuous_serialize
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.components.http.data_validator import RequestDataValidator
|
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||||
|
|
||||||
|
@ -70,10 +70,7 @@ class FlowManagerIndexView(_BaseFlowManagerView):
|
||||||
try:
|
try:
|
||||||
result = await self._flow_mgr.async_init(
|
result = await self._flow_mgr.async_init(
|
||||||
handler, # type: ignore[arg-type]
|
handler, # type: ignore[arg-type]
|
||||||
context={
|
context=self.get_context(data),
|
||||||
"source": config_entries.SOURCE_USER,
|
|
||||||
"show_advanced_options": data["show_advanced_options"],
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
except data_entry_flow.UnknownHandler:
|
except data_entry_flow.UnknownHandler:
|
||||||
return self.json_message("Invalid handler specified", HTTPStatus.NOT_FOUND)
|
return self.json_message("Invalid handler specified", HTTPStatus.NOT_FOUND)
|
||||||
|
@ -86,6 +83,10 @@ class FlowManagerIndexView(_BaseFlowManagerView):
|
||||||
|
|
||||||
return self.json(result)
|
return self.json(result)
|
||||||
|
|
||||||
|
def get_context(self, data: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
"""Return context."""
|
||||||
|
return {"show_advanced_options": data["show_advanced_options"]}
|
||||||
|
|
||||||
|
|
||||||
class FlowManagerResourceView(_BaseFlowManagerView):
|
class FlowManagerResourceView(_BaseFlowManagerView):
|
||||||
"""View to interact with the flow manager."""
|
"""View to interact with the flow manager."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue