mirror of
https://github.com/home-assistant/core.git
synced 2025-11-10 19:40:11 +00:00
Add sidebar default visible flag to panels (#155506)
This commit is contained in:
@@ -263,6 +263,9 @@ class Panel:
|
|||||||
# Title to show in the sidebar
|
# Title to show in the sidebar
|
||||||
sidebar_title: str | None = None
|
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
|
# Url to show the panel in the frontend
|
||||||
frontend_url_path: str
|
frontend_url_path: str
|
||||||
|
|
||||||
@@ -280,6 +283,7 @@ class Panel:
|
|||||||
component_name: str,
|
component_name: str,
|
||||||
sidebar_title: str | None,
|
sidebar_title: str | None,
|
||||||
sidebar_icon: str | None,
|
sidebar_icon: str | None,
|
||||||
|
sidebar_default_visible: bool,
|
||||||
frontend_url_path: str | None,
|
frontend_url_path: str | None,
|
||||||
config: dict[str, Any] | None,
|
config: dict[str, Any] | None,
|
||||||
require_admin: bool,
|
require_admin: bool,
|
||||||
@@ -293,6 +297,7 @@ class Panel:
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.require_admin = require_admin
|
self.require_admin = require_admin
|
||||||
self.config_panel_domain = config_panel_domain
|
self.config_panel_domain = config_panel_domain
|
||||||
|
self.sidebar_default_visible = sidebar_default_visible
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def to_response(self) -> PanelResponse:
|
def to_response(self) -> PanelResponse:
|
||||||
@@ -301,6 +306,7 @@ class Panel:
|
|||||||
"component_name": self.component_name,
|
"component_name": self.component_name,
|
||||||
"icon": self.sidebar_icon,
|
"icon": self.sidebar_icon,
|
||||||
"title": self.sidebar_title,
|
"title": self.sidebar_title,
|
||||||
|
"default_visible": self.sidebar_default_visible,
|
||||||
"config": self.config,
|
"config": self.config,
|
||||||
"url_path": self.frontend_url_path,
|
"url_path": self.frontend_url_path,
|
||||||
"require_admin": self.require_admin,
|
"require_admin": self.require_admin,
|
||||||
@@ -315,6 +321,7 @@ def async_register_built_in_panel(
|
|||||||
component_name: str,
|
component_name: str,
|
||||||
sidebar_title: str | None = None,
|
sidebar_title: str | None = None,
|
||||||
sidebar_icon: str | None = None,
|
sidebar_icon: str | None = None,
|
||||||
|
sidebar_default_visible: bool = True,
|
||||||
frontend_url_path: str | None = None,
|
frontend_url_path: str | None = None,
|
||||||
config: dict[str, Any] | None = None,
|
config: dict[str, Any] | None = None,
|
||||||
require_admin: bool = False,
|
require_admin: bool = False,
|
||||||
@@ -327,6 +334,7 @@ def async_register_built_in_panel(
|
|||||||
component_name,
|
component_name,
|
||||||
sidebar_title,
|
sidebar_title,
|
||||||
sidebar_icon,
|
sidebar_icon,
|
||||||
|
sidebar_default_visible,
|
||||||
frontend_url_path,
|
frontend_url_path,
|
||||||
config,
|
config,
|
||||||
require_admin,
|
require_admin,
|
||||||
@@ -879,6 +887,7 @@ class PanelResponse(TypedDict):
|
|||||||
component_name: str
|
component_name: str
|
||||||
icon: str | None
|
icon: str | None
|
||||||
title: str | None
|
title: str | None
|
||||||
|
default_visible: bool
|
||||||
config: dict[str, Any] | None
|
config: dict[str, Any] | None
|
||||||
url_path: str
|
url_path: str
|
||||||
require_admin: bool
|
require_admin: bool
|
||||||
|
|||||||
@@ -645,6 +645,7 @@ async def test_get_panels(
|
|||||||
assert msg["result"]["map"]["icon"] == "mdi:tooltip-account"
|
assert msg["result"]["map"]["icon"] == "mdi:tooltip-account"
|
||||||
assert msg["result"]["map"]["title"] == "Map"
|
assert msg["result"]["map"]["title"] == "Map"
|
||||||
assert msg["result"]["map"]["require_admin"] is True
|
assert msg["result"]["map"]["require_admin"] is True
|
||||||
|
assert msg["result"]["map"]["default_visible"] is True
|
||||||
|
|
||||||
async_remove_panel(hass, "map")
|
async_remove_panel(hass, "map")
|
||||||
|
|
||||||
@@ -685,6 +686,45 @@ async def test_get_panels_non_admin(
|
|||||||
assert "map" not in msg["result"]
|
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:
|
async def test_get_translations(ws_client: MockHAClientWebSocket) -> None:
|
||||||
"""Test get_translations command."""
|
"""Test get_translations command."""
|
||||||
with patch(
|
with patch(
|
||||||
|
|||||||
@@ -253,9 +253,7 @@ async def test_setup_api_panel(
|
|||||||
"component_name": "custom",
|
"component_name": "custom",
|
||||||
"icon": None,
|
"icon": None,
|
||||||
"title": None,
|
"title": None,
|
||||||
"url_path": "hassio",
|
"default_visible": True,
|
||||||
"require_admin": True,
|
|
||||||
"config_panel_domain": None,
|
|
||||||
"config": {
|
"config": {
|
||||||
"_panel_custom": {
|
"_panel_custom": {
|
||||||
"embed_iframe": True,
|
"embed_iframe": True,
|
||||||
@@ -264,6 +262,9 @@ async def test_setup_api_panel(
|
|||||||
"trust_external": False,
|
"trust_external": False,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"url_path": "hassio",
|
||||||
|
"require_admin": True,
|
||||||
|
"config_panel_domain": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user