diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 5f68ebeac18..dac0f51f608 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -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) diff --git a/tests/components/frontend/test_init.py b/tests/components/frontend/test_init.py index a9c24d256e5..83c82abea35 100644 --- a/tests/components/frontend/test_init.py +++ b/tests/components/frontend/test_init.py @@ -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