From 4baf881532b8853675a2889b26df0aa868075c5f Mon Sep 17 00:00:00 2001 From: bahmcloud Date: Wed, 14 Jan 2026 17:33:46 +0000 Subject: [PATCH] =?UTF-8?q?custom=5Fcomponents/bahmcloud=5Fstore/=5F=5Fini?= =?UTF-8?q?t=5F=5F.py=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/bahmcloud_store/__init__.py | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 custom_components/bahmcloud_store/__init__.py diff --git a/custom_components/bahmcloud_store/__init__.py b/custom_components/bahmcloud_store/__init__.py new file mode 100644 index 0000000..df43093 --- /dev/null +++ b/custom_components/bahmcloud_store/__init__.py @@ -0,0 +1,66 @@ +from __future__ import annotations + +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 .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" + + +async def async_setup(hass: HomeAssistant, config: dict) -> bool: + cfg = config.get(DOMAIN, {}) + store_url = cfg.get(CONF_STORE_URL, DEFAULT_STORE_URL) + + 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) + await store.register_http_views() + + # Initial 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) + async def periodic(_now) -> None: + try: + await store.refresh() + store.signal_entities_updated() + except StoreError as e: + _LOGGER.warning("Periodic refresh failed: %s", e) + + async_track_time_interval( + hass, + periodic, + timedelta(seconds=store.refresh_seconds or 300), + ) + + # Update entities laden (damit Updates in Settings erscheinen) + await hass.helpers.discovery.async_load_platform(Platform.UPDATE, DOMAIN, {}, config) + + return True