Allow integrations to register custom config panels (#96245)

This commit is contained in:
Franck Nijhof 2023-07-18 11:35:44 +02:00 committed by GitHub
parent a69b5a8d3b
commit 1a9e27cdaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 1 deletions

View file

@ -222,6 +222,9 @@ class Panel:
# If the panel should only be visible to admins
require_admin = False
# If the panel is a configuration panel for a integration
config_panel_domain: str | None = None
def __init__(
self,
component_name: str,
@ -230,6 +233,7 @@ class Panel:
frontend_url_path: str | None,
config: dict[str, Any] | None,
require_admin: bool,
config_panel_domain: str | None,
) -> None:
"""Initialize a built-in panel."""
self.component_name = component_name
@ -238,6 +242,7 @@ class Panel:
self.frontend_url_path = frontend_url_path or component_name
self.config = config
self.require_admin = require_admin
self.config_panel_domain = config_panel_domain
@callback
def to_response(self) -> PanelRespons:
@ -249,6 +254,7 @@ class Panel:
"config": self.config,
"url_path": self.frontend_url_path,
"require_admin": self.require_admin,
"config_panel_domain": self.config_panel_domain,
}
@ -264,6 +270,7 @@ def async_register_built_in_panel(
require_admin: bool = False,
*,
update: bool = False,
config_panel_domain: str | None = None,
) -> None:
"""Register a built-in panel."""
panel = Panel(
@ -273,6 +280,7 @@ def async_register_built_in_panel(
frontend_url_path,
config,
require_admin,
config_panel_domain,
)
panels = hass.data.setdefault(DATA_PANELS, {})
@ -720,3 +728,4 @@ class PanelRespons(TypedDict):
config: dict[str, Any] | None
url_path: str | None
require_admin: bool
config_panel_domain: str | None