"""Wall Panel integration.""" from __future__ import annotations import logging from homeassistant.core import HomeAssistant from .const import DOMAIN from .frontend import async_setup_frontend from .helpers import current_entry_config from .views import handle_config_request, handle_panel_request, handle_proxy_request _LOGGER = logging.getLogger(__name__) async def async_setup(hass: HomeAssistant, config: dict) -> bool: """Set up the integration-level HTTP views.""" state = hass.data.setdefault(DOMAIN, {}) if not state.get("_direct_routes_registered"): app = hass.http.app app.router.add_route("*", "/api/wall_panel/config/{entry_id}", handle_config_request) app.router.add_route("*", "/api/wall_panel/panel", handle_panel_request) app.router.add_route("*", "/api/wall_panel/proxy/{entry_id}/{path:.*}", handle_proxy_request) state["_direct_routes_registered"] = True _LOGGER.warning("Wall Panel direct routes registered") _LOGGER.warning("Wall Panel integration views registered") return True async def async_setup_entry(hass: HomeAssistant, entry) -> bool: """Set up Wall Panel from a config entry.""" state = hass.data.setdefault(DOMAIN, {}) state[entry.entry_id] = { "entry": entry, "config": current_entry_config(entry), } panel_url_path = await async_setup_frontend(hass, entry) state[entry.entry_id]["panel_url_path"] = panel_url_path entry.async_on_unload(entry.add_update_listener(_async_options_updated)) return True async def async_unload_entry(hass: HomeAssistant, entry) -> bool: """Unload Wall Panel.""" from homeassistant.components.frontend import async_remove_panel state = hass.data.get(DOMAIN, {}) panel_url_path = str(state.get(entry.entry_id, {}).get("panel_url_path") or entry.options.get("frontend_url_path", "wall-panel") or "wall-panel").strip() async_remove_panel(hass, panel_url_path) state.pop(entry.entry_id, None) return True async def _async_options_updated(hass: HomeAssistant, entry) -> None: """Reload the integration when options change.""" await hass.config_entries.async_reload(entry.entry_id)