diff --git a/custom_components/bahmcloud_store/__init__.py b/custom_components/bahmcloud_store/__init__.py index df43093..79efe02 100644 --- a/custom_components/bahmcloud_store/__init__.py +++ b/custom_components/bahmcloud_store/__init__.py @@ -4,16 +4,16 @@ import logging from datetime import timedelta from homeassistant.core import HomeAssistant -from homeassistant.components import frontend from homeassistant.const import Platform from homeassistant.helpers.event import async_track_time_interval +from homeassistant.helpers.discovery import async_load_platform +from homeassistant.components.panel_custom import async_register_panel from .store import BahmcloudStore, StoreConfig, StoreError _LOGGER = logging.getLogger(__name__) DOMAIN = "bahmcloud_store" -PLATFORMS = [Platform.UPDATE] DEFAULT_STORE_URL = "https://git.bahmcloud.de/bahmcloud/ha_store/raw/branch/main/store.yaml" CONF_STORE_URL = "store_url" @@ -26,27 +26,28 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool: store = BahmcloudStore(hass, StoreConfig(store_url=store_url)) hass.data[DOMAIN] = store - # Sidebar Panel - frontend.async_register_built_in_panel( - hass, - component_name=DOMAIN, - sidebar_title="Bahmcloud Store", - sidebar_icon="mdi:store", - frontend_url_path="bahmcloud-store", - config={}, - require_admin=True, - ) - - # HTTP (Panel static + API) + # HTTP Views (Panel static + JSON API) await store.register_http_views() - # Initial load + # Sidebar Panel (Custom Panel + JS module) + await async_register_panel( + hass, + frontend_url_path="bahmcloud-store", + webcomponent_name="bahmcloud-store-panel", + module_url="/api/bahmcloud_store_static/panel.js", + sidebar_title="Bahmcloud Store", + sidebar_icon="mdi:store", + require_admin=True, + config={}, + ) + + # Initialer Index-Load try: await store.refresh() except StoreError as e: _LOGGER.error("Initial store refresh failed: %s", e) - # Periodisch NUR index+latest versions refresh (keine Auto-Install) + # Nur Liste + Latest-Versionen regelmäßig aktualisieren (keine Auto-Install) async def periodic(_now) -> None: try: await store.refresh() @@ -54,13 +55,11 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool: except StoreError as e: _LOGGER.warning("Periodic refresh failed: %s", e) - async_track_time_interval( - hass, - periodic, - timedelta(seconds=store.refresh_seconds or 300), - ) + # Falls store.yaml refresh_seconds enthält, nutze das, sonst 300s + interval_seconds = store.refresh_seconds if getattr(store, "refresh_seconds", None) else 300 + async_track_time_interval(hass, periodic, timedelta(seconds=int(interval_seconds))) - # Update entities laden (damit Updates in Settings erscheinen) - await hass.helpers.discovery.async_load_platform(Platform.UPDATE, DOMAIN, {}, config) + # Update platform laden (damit Updates in Settings erscheinen) + await async_load_platform(hass, Platform.UPDATE, DOMAIN, {}, config) return True