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.core import HomeAssistant
|
||||||
from homeassistant.const import Platform
|
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.discovery import async_load_platform
|
||||||
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
from homeassistant.components.panel_custom import async_register_panel
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -20,46 +20,48 @@ CONF_STORE_URL = "store_url"
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
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, {})
|
cfg = config.get(DOMAIN, {})
|
||||||
store_url = cfg.get(CONF_STORE_URL, DEFAULT_STORE_URL)
|
store_url = cfg.get(CONF_STORE_URL, DEFAULT_STORE_URL)
|
||||||
|
|
||||||
store = BahmcloudStore(hass, StoreConfig(store_url=store_url))
|
core = BCSCore(hass, BCSConfig(store_url=store_url))
|
||||||
hass.data[DOMAIN] = store
|
hass.data[DOMAIN] = core
|
||||||
|
|
||||||
# HTTP Views (Panel static + JSON API)
|
# Register HTTP views (static panel assets + API)
|
||||||
await store.register_http_views()
|
await core.register_http_views()
|
||||||
|
|
||||||
# Sidebar Panel (Custom Panel + JS module)
|
# Register custom panel (no iframe; uses hass.callApi)
|
||||||
await async_register_panel(
|
await async_register_panel(
|
||||||
hass,
|
hass,
|
||||||
frontend_url_path="bahmcloud-store",
|
frontend_url_path="bahmcloud-store",
|
||||||
webcomponent_name="bahmcloud-store-panel",
|
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_title="Bahmcloud Store",
|
||||||
sidebar_icon="mdi:store",
|
sidebar_icon="mdi:store",
|
||||||
require_admin=True,
|
require_admin=True,
|
||||||
config={},
|
config={},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initialer Index-Load
|
# Initial refresh (index + custom repos)
|
||||||
try:
|
try:
|
||||||
await store.refresh()
|
await core.refresh()
|
||||||
except StoreError as e:
|
except BCSError as e:
|
||||||
_LOGGER.error("Initial store refresh failed: %s", 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:
|
async def periodic(_now) -> None:
|
||||||
try:
|
try:
|
||||||
await store.refresh()
|
await core.refresh()
|
||||||
store.signal_entities_updated()
|
core.signal_updated()
|
||||||
except StoreError as e:
|
except BCSError as e:
|
||||||
_LOGGER.warning("Periodic refresh failed: %s", e)
|
_LOGGER.warning("Periodic refresh failed: %s", e)
|
||||||
|
|
||||||
# Falls store.yaml refresh_seconds enthält, nutze das, sonst 300s
|
interval = timedelta(seconds=int(core.refresh_seconds or 300))
|
||||||
interval_seconds = store.refresh_seconds if getattr(store, "refresh_seconds", None) else 300
|
async_track_time_interval(hass, periodic, interval)
|
||||||
async_track_time_interval(hass, periodic, timedelta(seconds=int(interval_seconds)))
|
|
||||||
|
|
||||||
# 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)
|
await async_load_platform(hass, Platform.UPDATE, DOMAIN, {}, config)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user