Allow opting out of warnings when removing unknown frontend panel (#119824)
parent
12f812d6da
commit
a10f9a5f6d
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue