add v 0.2.0
This commit is contained in:
@@ -5,11 +5,11 @@ from datetime import timedelta
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
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 .store import BahmcloudStore, StoreConfig, StoreError
|
||||
from .core import BCSCore, BCSConfig, BCSError
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -20,46 +20,48 @@ CONF_STORE_URL = "store_url"
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
||||
# YAML-based config for now:
|
||||
# bahmcloud_store:
|
||||
# store_url: "https://.../store.yaml"
|
||||
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
|
||||
core = BCSCore(hass, BCSConfig(store_url=store_url))
|
||||
hass.data[DOMAIN] = core
|
||||
|
||||
# HTTP Views (Panel static + JSON API)
|
||||
await store.register_http_views()
|
||||
# Register HTTP views (static panel assets + API)
|
||||
await core.register_http_views()
|
||||
|
||||
# Sidebar Panel (Custom Panel + JS module)
|
||||
# Register custom panel (no iframe; uses hass.callApi)
|
||||
await async_register_panel(
|
||||
hass,
|
||||
frontend_url_path="bahmcloud-store",
|
||||
webcomponent_name="bahmcloud-store-panel",
|
||||
module_url="/api/bahmcloud_store_static/panel.js",
|
||||
module_url="/api/bahmcloud_store_static/panel.js?v=1",
|
||||
sidebar_title="Bahmcloud Store",
|
||||
sidebar_icon="mdi:store",
|
||||
require_admin=True,
|
||||
config={},
|
||||
)
|
||||
|
||||
# Initialer Index-Load
|
||||
# Initial refresh (index + custom repos)
|
||||
try:
|
||||
await store.refresh()
|
||||
except StoreError as e:
|
||||
_LOGGER.error("Initial store refresh failed: %s", e)
|
||||
await core.refresh()
|
||||
except BCSError as e:
|
||||
_LOGGER.error("Initial refresh failed: %s", e)
|
||||
|
||||
# Nur Liste + Latest-Versionen regelmäßig aktualisieren (keine Auto-Install)
|
||||
# Periodic refresh (data only; no auto installs)
|
||||
async def periodic(_now) -> None:
|
||||
try:
|
||||
await store.refresh()
|
||||
store.signal_entities_updated()
|
||||
except StoreError as e:
|
||||
await core.refresh()
|
||||
core.signal_updated()
|
||||
except BCSError as e:
|
||||
_LOGGER.warning("Periodic refresh failed: %s", e)
|
||||
|
||||
# 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)))
|
||||
interval = timedelta(seconds=int(core.refresh_seconds or 300))
|
||||
async_track_time_interval(hass, periodic, interval)
|
||||
|
||||
# Update platform laden (damit Updates in Settings erscheinen)
|
||||
# Update platform is a stub in 0.2.0 (keeps integration stable)
|
||||
await async_load_platform(hass, Platform.UPDATE, DOMAIN, {}, config)
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user