Add sidebar default visible flag to panels (#155506)

This commit is contained in:
Paul Bottein
2025-11-08 04:40:59 +01:00
committed by GitHub
parent aac25fa480
commit 2a2599de88
3 changed files with 53 additions and 3 deletions

View File

@@ -263,6 +263,9 @@ class Panel:
# Title to show in the sidebar
sidebar_title: str | None = None
# If the panel should be visible by default in the sidebar
sidebar_default_visible: bool = True
# Url to show the panel in the frontend
frontend_url_path: str
@@ -280,6 +283,7 @@ class Panel:
component_name: str,
sidebar_title: str | None,
sidebar_icon: str | None,
sidebar_default_visible: bool,
frontend_url_path: str | None,
config: dict[str, Any] | None,
require_admin: bool,
@@ -293,6 +297,7 @@ class Panel:
self.config = config
self.require_admin = require_admin
self.config_panel_domain = config_panel_domain
self.sidebar_default_visible = sidebar_default_visible
@callback
def to_response(self) -> PanelResponse:
@@ -301,6 +306,7 @@ class Panel:
"component_name": self.component_name,
"icon": self.sidebar_icon,
"title": self.sidebar_title,
"default_visible": self.sidebar_default_visible,
"config": self.config,
"url_path": self.frontend_url_path,
"require_admin": self.require_admin,
@@ -315,6 +321,7 @@ def async_register_built_in_panel(
component_name: str,
sidebar_title: str | None = None,
sidebar_icon: str | None = None,
sidebar_default_visible: bool = True,
frontend_url_path: str | None = None,
config: dict[str, Any] | None = None,
require_admin: bool = False,
@@ -327,6 +334,7 @@ def async_register_built_in_panel(
component_name,
sidebar_title,
sidebar_icon,
sidebar_default_visible,
frontend_url_path,
config,
require_admin,
@@ -879,6 +887,7 @@ class PanelResponse(TypedDict):
component_name: str
icon: str | None
title: str | None
default_visible: bool
config: dict[str, Any] | None
url_path: str
require_admin: bool

View File

@@ -645,6 +645,7 @@ async def test_get_panels(
assert msg["result"]["map"]["icon"] == "mdi:tooltip-account"
assert msg["result"]["map"]["title"] == "Map"
assert msg["result"]["map"]["require_admin"] is True
assert msg["result"]["map"]["default_visible"] is True
async_remove_panel(hass, "map")
@@ -685,6 +686,45 @@ async def test_get_panels_non_admin(
assert "map" not in msg["result"]
async def test_panel_sidebar_default_visible(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
mock_http_client: TestClient,
) -> None:
"""Test sidebar_default_visible property in panels."""
async_register_built_in_panel(
hass,
"default_panel",
"Default Panel",
)
async_register_built_in_panel(
hass,
"visible_panel",
"Visible Panel",
"mdi:eye",
sidebar_default_visible=True,
)
async_register_built_in_panel(
hass,
"hidden_panel",
"Hidden Panel",
"mdi:eye-off",
sidebar_default_visible=False,
)
client = await hass_ws_client(hass)
await client.send_json({"id": 5, "type": "get_panels"})
msg = await client.receive_json()
assert msg["id"] == 5
assert msg["type"] == TYPE_RESULT
assert msg["success"]
assert msg["result"]["default_panel"]["default_visible"] is True
assert msg["result"]["visible_panel"]["default_visible"] is True
assert msg["result"]["hidden_panel"]["default_visible"] is False
async def test_get_translations(ws_client: MockHAClientWebSocket) -> None:
"""Test get_translations command."""
with patch(

View File

@@ -253,9 +253,7 @@ async def test_setup_api_panel(
"component_name": "custom",
"icon": None,
"title": None,
"url_path": "hassio",
"require_admin": True,
"config_panel_domain": None,
"default_visible": True,
"config": {
"_panel_custom": {
"embed_iframe": True,
@@ -264,6 +262,9 @@ async def test_setup_api_panel(
"trust_external": False,
}
},
"url_path": "hassio",
"require_admin": True,
"config_panel_domain": None,
}