From 2a2599de88a7e67174f30f709d67b59d6c6b64a1 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Sat, 8 Nov 2025 04:40:59 +0100 Subject: [PATCH] Add sidebar default visible flag to panels (#155506) --- homeassistant/components/frontend/__init__.py | 9 +++++ tests/components/frontend/test_init.py | 40 +++++++++++++++++++ tests/components/hassio/test_init.py | 7 ++-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index ebd354c5e83..8108038f6cb 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -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 diff --git a/tests/components/frontend/test_init.py b/tests/components/frontend/test_init.py index e5cd6fa3089..008aaf49008 100644 --- a/tests/components/frontend/test_init.py +++ b/tests/components/frontend/test_init.py @@ -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( diff --git a/tests/components/hassio/test_init.py b/tests/components/hassio/test_init.py index 16f2f3e95ea..b4a23202f9d 100644 --- a/tests/components/hassio/test_init.py +++ b/tests/components/hassio/test_init.py @@ -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, }