custom_components/bahmcloud_store/__init__.py aktualisiert

This commit is contained in:
2026-01-15 17:18:45 +00:00
parent 32946c1a98
commit f861b2490a

View File

@@ -18,16 +18,23 @@ CONF_STORE_URL = "store_url"
async def async_setup(hass: HomeAssistant, config: dict) -> bool: async def async_setup(hass: HomeAssistant, config: dict) -> bool:
"""Set up the Bahmcloud Store integration."""
cfg = config.get(DOMAIN, {}) or {} cfg = config.get(DOMAIN, {}) or {}
store_url = cfg.get(CONF_STORE_URL, DEFAULT_STORE_URL) store_url = cfg.get(CONF_STORE_URL, DEFAULT_STORE_URL)
core = BCSCore(hass, BCSConfig(store_url=store_url)) core = BCSCore(hass, BCSConfig(store_url=store_url))
hass.data[DOMAIN] = core hass.data[DOMAIN] = core
await core.register_http_views() # Avoid blocking IO during setup
await core.async_initialize()
# Register HTTP views and panel
from .views import StaticAssetsView, BCSApiView, BCSReadmeView, BCSCustomRepoView
hass.http.register_view(StaticAssetsView())
hass.http.register_view(BCSApiView(core))
hass.http.register_view(BCSReadmeView(core))
hass.http.register_view(BCSCustomRepoView(core))
# Keep the exact module_url pattern that worked reliably (cache-busted via v=42)
await async_register_panel( await async_register_panel(
hass, hass,
frontend_url_path="bahmcloud-store", frontend_url_path="bahmcloud-store",
@@ -39,7 +46,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
config={}, config={},
) )
# Initial load at startup # Initial refresh
try: try:
await core.full_refresh(source="startup") await core.full_refresh(source="startup")
except BCSError as e: except BCSError as e:
@@ -53,7 +60,6 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
except Exception as e: except Exception as e:
_LOGGER.exception("Unexpected error during periodic refresh: %s", e) _LOGGER.exception("Unexpected error during periodic refresh: %s", e)
# Start with the configured refresh interval (default: 300 seconds)
interval_seconds = int(getattr(core, "refresh_seconds", 300) or 300) interval_seconds = int(getattr(core, "refresh_seconds", 300) or 300)
async_track_time_interval(hass, periodic, timedelta(seconds=interval_seconds)) async_track_time_interval(hass, periodic, timedelta(seconds=interval_seconds))