custom_components/bahmcloud_store/__init__.py aktualisiert
This commit is contained in:
@@ -7,11 +7,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
|
||||
# IMPORTANT:
|
||||
# Use the frontend panel registration to keep HA header/sidebar working on mobile,
|
||||
# similar to how HACS registers its panel.
|
||||
from homeassistant.components.frontend import async_register_built_in_panel
|
||||
from homeassistant.components.panel_custom import async_register_panel
|
||||
|
||||
from .core import BCSCore, BCSConfig, BCSError
|
||||
|
||||
@@ -24,39 +20,31 @@ 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)
|
||||
|
||||
core = BCSCore(hass, BCSConfig(store_url=store_url))
|
||||
hass.data[DOMAIN] = core
|
||||
|
||||
# Register HTTP views (static panel assets + API)
|
||||
await core.register_http_views()
|
||||
|
||||
# Register panel via frontend (keeps navigation/header on mobile)
|
||||
async_register_built_in_panel(
|
||||
# Custom panel registration (compatible across HA versions)
|
||||
await async_register_panel(
|
||||
hass,
|
||||
component_name="custom",
|
||||
frontend_url_path="bahmcloud-store",
|
||||
webcomponent_name="bahmcloud-store-panel",
|
||||
module_url="/api/bahmcloud_store_static/panel.js?v=32",
|
||||
sidebar_title="Bahmcloud Store",
|
||||
sidebar_icon="mdi:store",
|
||||
frontend_url_path="bahmcloud-store",
|
||||
config={},
|
||||
require_admin=True,
|
||||
# module_url must be reachable without auth (we already serve it public)
|
||||
# Cache-busting is fine here.
|
||||
module_url="/api/bahmcloud_store_static/panel.js?v=31",
|
||||
config={},
|
||||
)
|
||||
|
||||
# Initial refresh (index + custom repos + enrichment)
|
||||
try:
|
||||
await core.refresh()
|
||||
except BCSError as e:
|
||||
_LOGGER.error("Initial refresh failed: %s", e)
|
||||
|
||||
# Periodic refresh (data only; no auto installs)
|
||||
async def periodic(_now) -> None:
|
||||
try:
|
||||
await core.refresh()
|
||||
@@ -67,7 +55,5 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
||||
interval = timedelta(seconds=int(core.refresh_seconds or 300))
|
||||
async_track_time_interval(hass, periodic, interval)
|
||||
|
||||
# Update platform is a stub in 0.3.x (keeps integration stable)
|
||||
await async_load_platform(hass, Platform.UPDATE, DOMAIN, {}, config)
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user