custom_components/bahmcloud_store/__init__.py aktualisiert

This commit is contained in:
2026-01-15 13:52:57 +00:00
parent 6ca193580d
commit dbcac9df86

View File

@@ -3,45 +3,66 @@ from __future__ import annotations
import logging import logging
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.components import frontend
from .core import BCSCore from .core import DOMAIN, BahmcloudStore, StoreConfig
from .views import (
StaticAssetsView,
BCSApiView,
BCSCustomRepoView,
BCSReadmeView,
)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = "bahmcloud_store"
async def async_setup(hass: HomeAssistant, config: dict) -> bool: async def async_setup(hass: HomeAssistant, config: dict) -> bool:
# Your BCSCore requires config in __init__ # Read configuration from configuration.yaml:
core = BCSCore(hass, config) # bahmcloud_store:
# store_url: "https://....../store.yaml"
domain_cfg = config.get(DOMAIN) or {}
# Call optional setup methods if they exist (keep compatibility with your working core) store_url = None
try: if isinstance(domain_cfg, dict):
if hasattr(core, "setup"): store_url = domain_cfg.get("store_url") or domain_cfg.get("store") or domain_cfg.get("url")
res = core.setup()
if hasattr(res, "__await__"): if not store_url or not isinstance(store_url, str):
await res _LOGGER.error(
elif hasattr(core, "start"): "Missing configuration for %s. Please set %s: {store_url: 'https://.../store.yaml'}",
res = core.start() DOMAIN,
if hasattr(res, "__await__"): DOMAIN,
await res )
except Exception as e:
_LOGGER.exception("BCSCore setup/start failed: %s", e)
return False return False
hass.data.setdefault(DOMAIN, {}) store = BahmcloudStore(hass, StoreConfig(store_url=store_url))
hass.data[DOMAIN]["core"] = core
# Register HTTP views # Register API + static panel assets (these are defined in core.py)
hass.http.register_view(StaticAssetsView()) await store.register_http_views()
hass.http.register_view(BCSApiView(core))
hass.http.register_view(BCSCustomRepoView(core)) # Store reference
hass.http.register_view(BCSReadmeView(core)) hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN]["store"] = store
# Register sidebar panel (compat layer for different HA versions)
panel_js = "/api/bahmcloud_store_static/panel.js"
try:
# Some HA versions use module_url
frontend.async_register_panel(
hass,
"custom",
DOMAIN,
sidebar_title="Bahmcloud Store",
sidebar_icon="mdi:store",
module_url=panel_js,
config={},
)
except TypeError:
# Fallback: some HA versions use js_url instead
try:
frontend.async_register_panel(
hass,
"custom",
DOMAIN,
sidebar_title="Bahmcloud Store",
sidebar_icon="mdi:store",
js_url=panel_js,
config={},
)
except Exception as e:
_LOGGER.warning("Panel registration failed (store will still work via API): %s", e)
return True return True