custom_components/bahmcloud_store/__init__.py aktualisiert

This commit is contained in:
2026-01-15 13:05:24 +00:00
parent ce4bd4f4f1
commit b84ab944b3

View File

@@ -1,59 +1,37 @@
from __future__ import annotations
import logging
from datetime import timedelta
from homeassistant.core import HomeAssistant
from homeassistant.const import Platform
from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.components.panel_custom import async_register_panel
from .core import BCSCore, BCSConfig, BCSError
from .const import DOMAIN
from .core import BCSCore
from .views import (
StaticAssetsView,
BCSApiView,
BCSCustomRepoView,
BCSReadmeView,
BCSRefreshView,
)
_LOGGER = logging.getLogger(__name__)
DOMAIN = "bahmcloud_store"
DEFAULT_STORE_URL = "https://git.bahmcloud.de/bahmcloud/ha_store/raw/branch/main/store.yaml"
CONF_STORE_URL = "store_url"
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
cfg = config.get(DOMAIN, {})
store_url = cfg.get(CONF_STORE_URL, DEFAULT_STORE_URL)
core = BCSCore(hass)
await core.async_setup()
core = BCSCore(hass, BCSConfig(store_url=store_url))
hass.data[DOMAIN] = core
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN]["core"] = core
await core.register_http_views()
# Register HTTP views
hass.http.register_view(StaticAssetsView())
hass.http.register_view(BCSApiView(core))
hass.http.register_view(BCSCustomRepoView(core))
hass.http.register_view(BCSReadmeView(core))
hass.http.register_view(BCSRefreshView(core))
# RESTORE: keep the module_url pattern that worked for you
await async_register_panel(
hass,
frontend_url_path="bahmcloud-store",
webcomponent_name="bahmcloud-store-panel",
module_url="/api/bahmcloud_store_static/panel.js?v=42",
sidebar_title="Bahmcloud Store",
sidebar_icon="mdi:store",
require_admin=True,
config={},
)
# Panel registration stays in your existing file (unchanged) if you already have it elsewhere.
# If you register the panel here already, keep your current working code.
try:
await core.refresh()
except BCSError as e:
_LOGGER.error("Initial refresh failed: %s", e)
async def periodic(_now) -> None:
try:
await core.refresh()
core.signal_updated()
except BCSError as e:
_LOGGER.warning("Periodic refresh failed: %s", e)
interval = timedelta(seconds=int(core.refresh_seconds or 300))
async_track_time_interval(hass, periodic, interval)
await async_load_platform(hass, Platform.UPDATE, DOMAIN, {}, config)
return True