Repository: home-assistant/core
File: homeassistant/components/frontend/__init__.py (Python)

Code before:
        subscribers.remove((connection, msg["id"]))

    connection.subscriptions[msg["id"]] = cancel_subscription
    connection.send_message(websocket_api.result_message(msg["id"]))


@websocket_api.websocket_command(
    {
        vol.Required("type"): "frontend/update_panel",
        vol.Required("url_path"): str,
        vol.Optional("title"): vol.Any(cv.string, None),
        vol.Optional("icon"): vol.Any(cv.icon, None),
        vol.Optional("require_admin"): vol.Any(cv.boolean, None),
        vol.Optional("show_in_sidebar"): vol.Any(cv.boolean, None),
    }
)
@websocket_api.require_admin
@websocket_api.async_response
async def websocket_update_panel(
    hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
    """Handle update panel command."""
    url_path: str = msg["url_path"]

    if url_path not in hass.data.get(DATA_PANELS, {}):
        connection.send_error(msg["id"], "not_found", "Panel not found")
        return

    panels_config = hass.data[DATA_PANELS_CONFIG]
    panel_config = dict(panels_config.get(url_path, {}))

    for key in ("title", "icon", "require_admin", "show_in_sidebar"):
        if key in msg:
            if msg[key] is None:
                panel_config.pop(key, None)
            else:
                panel_config[key] = msg[key]

    if panel_config:
        panels_config[url_path] = panel_config
    else:
        panels_config.pop(url_path, None)

    hass.data[DATA_PANELS_STORE].async_delay_save(
        lambda: hass.data[DATA_PANELS_CONFIG], PANELS_SAVE_DELAY
    )
    hass.bus.async_fire(EVENT_PANELS_UPDATED)
    connection.send_result(msg["id"])


class PanelResponse(TypedDict):

Review comment (suggestion):
We have a constant for the not_found error (`ERR_NOT_FOUND`) in the websocket api integration I believe.

Code after:
        subscribers.remove((connection, msg["id"]))

    connection.subscriptions[msg["id"]] = cancel_subscription
    connection.send_message(websocket_api.result_message(msg["id"]))


@websocket_api.websocket_command(
    {
        vol.Required("type"): "frontend/update_panel",
        vol.Required("url_path"): str,
        vol.Optional("title"): vol.Any(cv.string, None),
        vol.Optional("icon"): vol.Any(cv.icon, None),
        vol.Optional("require_admin"): vol.Any(cv.boolean, None),
        vol.Optional("show_in_sidebar"): vol.Any(cv.boolean, None),
    }
)
@websocket_api.require_admin
@websocket_api.async_response
async def websocket_update_panel(
    hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
    """Handle update panel command."""
    url_path: str = msg["url_path"]

    if url_path not in hass.data.get(DATA_PANELS, {}):
        connection.send_error(msg["id"], ERR_NOT_FOUND, "Panel not found")
        return

    panels_config = hass.data[DATA_PANELS_CONFIG]
    panel_config = dict(panels_config.get(url_path, {}))

    for key in ("title", "icon", "require_admin", "show_in_sidebar"):
        if key in msg:
            if (value := msg[key]) is None:
                panel_config.pop(key, None)
            else:
                panel_config[key] = value

    if panel_config:
        panels_config[url_path] = panel_config
    else:
        panels_config.pop(url_path, None)

    hass.data[DATA_PANELS_STORE].async_delay_save(
        lambda: hass.data[DATA_PANELS_CONFIG], PANELS_SAVE_DELAY
    )
    hass.bus.async_fire(EVENT_PANELS_UPDATED)
    connection.send_result(msg["id"])


class PanelResponse(TypedDict):