Allow opting out of warnings when removing unknown frontend panel (#119824)
This commit is contained in:
parent
12f812d6da
commit
a10f9a5f6d
2 changed files with 19 additions and 3 deletions
|
@ -323,12 +323,16 @@ def async_register_built_in_panel(
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
@callback
|
@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."""
|
"""Remove a built-in panel."""
|
||||||
panel = hass.data.get(DATA_PANELS, {}).pop(frontend_url_path, None)
|
panel = hass.data.get(DATA_PANELS, {}).pop(frontend_url_path, None)
|
||||||
|
|
||||||
if panel is None:
|
if panel is None:
|
||||||
|
if warn_if_unknown:
|
||||||
_LOGGER.warning("Removing unknown panel %s", frontend_url_path)
|
_LOGGER.warning("Removing unknown panel %s", frontend_url_path)
|
||||||
|
return
|
||||||
|
|
||||||
hass.bus.async_fire(EVENT_PANELS_UPDATED)
|
hass.bus.async_fire(EVENT_PANELS_UPDATED)
|
||||||
|
|
||||||
|
|
|
@ -495,7 +495,10 @@ async def test_extra_js(
|
||||||
|
|
||||||
|
|
||||||
async def test_get_panels(
|
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:
|
) -> None:
|
||||||
"""Test get_panels command."""
|
"""Test get_panels command."""
|
||||||
events = async_capture_events(hass, EVENT_PANELS_UPDATED)
|
events = async_capture_events(hass, EVENT_PANELS_UPDATED)
|
||||||
|
@ -533,6 +536,15 @@ async def test_get_panels(
|
||||||
|
|
||||||
assert len(events) == 2
|
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(
|
async def test_get_panels_non_admin(
|
||||||
hass: HomeAssistant, ws_client, hass_admin_user: MockUser
|
hass: HomeAssistant, ws_client, hass_admin_user: MockUser
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue