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:
G Johansson 2024-02-16 15:51:51 +01:00 committed by GitHub
parent 23e81a45c8
commit cb776593cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View file

@ -157,6 +157,12 @@ class ConfigManagerFlowIndexView(FlowManagerIndexView):
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(
self, result: data_entry_flow.FlowResult
) -> data_entry_flow.FlowResult:

View file

@ -8,7 +8,7 @@ from aiohttp import web
import voluptuous as vol
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.data_validator import RequestDataValidator
@ -70,10 +70,7 @@ class FlowManagerIndexView(_BaseFlowManagerView):
try:
result = await self._flow_mgr.async_init(
handler, # type: ignore[arg-type]
context={
"source": config_entries.SOURCE_USER,
"show_advanced_options": data["show_advanced_options"],
},
context=self.get_context(data),
)
except data_entry_flow.UnknownHandler:
return self.json_message("Invalid handler specified", HTTPStatus.NOT_FOUND)
@ -86,6 +83,10 @@ class FlowManagerIndexView(_BaseFlowManagerView):
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):
"""View to interact with the flow manager."""