Allow opting out of warnings when removing unknown frontend panel (#119824)

pull/120103/head
Erik Montnemery 2024-06-21 15:56:22 +02:00 committed by GitHub
parent 12f812d6da
commit a10f9a5f6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -323,12 +323,16 @@ def async_register_built_in_panel(
@bind_hass
@callback
def async_remove_panel(hass: HomeAssistant, frontend_url_path: str) -> None:
def async_remove_panel(
hass: HomeAssistant, frontend_url_path: str, *, warn_if_unknown: bool = True
) -> None:
"""Remove a built-in panel."""
panel = hass.data.get(DATA_PANELS, {}).pop(frontend_url_path, None)
if panel is None:
_LOGGER.warning("Removing unknown panel %s", frontend_url_path)
if warn_if_unknown:
_LOGGER.warning("Removing unknown panel %s", frontend_url_path)
return
hass.bus.async_fire(EVENT_PANELS_UPDATED)

View File

@ -495,7 +495,10 @@ async def test_extra_js(
async def test_get_panels(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, mock_http_client
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
mock_http_client,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test get_panels command."""
events = async_capture_events(hass, EVENT_PANELS_UPDATED)
@ -533,6 +536,15 @@ async def test_get_panels(
assert len(events) == 2
# Remove again, will warn but not trigger event
async_remove_panel(hass, "map")
assert "Removing unknown panel map" in caplog.text
caplog.clear()
# Remove again, without warning
async_remove_panel(hass, "map", warn_if_unknown=False)
assert "Removing unknown panel map" not in caplog.text
async def test_get_panels_non_admin(
hass: HomeAssistant, ws_client, hass_admin_user: MockUser