custom_components/bahmcloud_store/__init__.py aktualisiert

This commit is contained in:
2026-01-15 07:52:18 +00:00
parent d04bf2a3f1
commit b40e509362

View File

@@ -7,7 +7,9 @@ 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
from homeassistant.components.panel_custom import async_register_panel
# Built-in panel registration (keeps HA header/sidebar on mobile)
from homeassistant.components.frontend import async_register_built_in_panel
from .core import BCSCore, BCSConfig, BCSError
@@ -26,25 +28,35 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
core = BCSCore(hass, BCSConfig(store_url=store_url))
hass.data[DOMAIN] = core
# Register HTTP views (static assets + API)
await core.register_http_views()
# Custom panel registration (compatible across HA versions)
await async_register_panel(
# IMPORTANT:
# In HA 2026.1.x, async_register_built_in_panel does not accept module_url.
# The supported way is to use _panel_custom with js_url.
# This keeps the HA chrome (header/sidebar) on mobile.
async_register_built_in_panel(
hass,
frontend_url_path="bahmcloud-store",
webcomponent_name="bahmcloud-store-panel",
module_url="/api/bahmcloud_store_static/panel.js?v=32",
component_name="custom",
sidebar_title="Bahmcloud Store",
sidebar_icon="mdi:store",
frontend_url_path="bahmcloud-store",
require_admin=True,
config={},
config={
"_panel_custom": {
"name": "bahmcloud-store-panel",
"js_url": "/api/bahmcloud_store_static/panel.js?v=33",
}
},
)
# 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()
@@ -55,5 +67,7 @@ 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 still a stub in 0.3.x
await async_load_platform(hass, Platform.UPDATE, DOMAIN, {}, config)
return True