wallpanell/custom_components/wall_panel/__init__.py
2026-03-25 13:49:13 +03:00

49 lines
1.5 KiB
Python
Executable File

"""Wall Panel integration."""
from __future__ import annotations
from homeassistant.core import HomeAssistant
from .const import CONF_CONFIG, DOMAIN
from .frontend import async_setup_frontend
from .helpers import current_entry_config
from .views import WallPanelConfigView
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
if not state.get("_config_view_registered"):
hass.http.register_view(WallPanelConfigView)
state["_config_view_registered"] = True
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)