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.const import Platform
|
||||||
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.helpers.event import async_track_time_interval
|
||||||
|
from homeassistant.components.panel_custom import async_register_panel
|
||||||
# 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 .core import BCSCore, BCSConfig, BCSError
|
from .core import BCSCore, BCSConfig, BCSError
|
||||||
|
|
||||||
@@ -24,39 +20,31 @@ 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)
|
||||||
|
|
||||||
core = BCSCore(hass, BCSConfig(store_url=store_url))
|
core = BCSCore(hass, BCSConfig(store_url=store_url))
|
||||||
hass.data[DOMAIN] = core
|
hass.data[DOMAIN] = core
|
||||||
|
|
||||||
# Register HTTP views (static panel assets + API)
|
|
||||||
await core.register_http_views()
|
await core.register_http_views()
|
||||||
|
|
||||||
# Register panel via frontend (keeps navigation/header on mobile)
|
# Custom panel registration (compatible across HA versions)
|
||||||
async_register_built_in_panel(
|
await async_register_panel(
|
||||||
hass,
|
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_title="Bahmcloud Store",
|
||||||
sidebar_icon="mdi:store",
|
sidebar_icon="mdi:store",
|
||||||
frontend_url_path="bahmcloud-store",
|
|
||||||
config={},
|
|
||||||
require_admin=True,
|
require_admin=True,
|
||||||
# module_url must be reachable without auth (we already serve it public)
|
config={},
|
||||||
# Cache-busting is fine here.
|
|
||||||
module_url="/api/bahmcloud_store_static/panel.js?v=31",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initial refresh (index + custom repos + enrichment)
|
|
||||||
try:
|
try:
|
||||||
await core.refresh()
|
await core.refresh()
|
||||||
except BCSError as e:
|
except BCSError as e:
|
||||||
_LOGGER.error("Initial refresh failed: %s", e)
|
_LOGGER.error("Initial refresh failed: %s", e)
|
||||||
|
|
||||||
# Periodic refresh (data only; no auto installs)
|
|
||||||
async def periodic(_now) -> None:
|
async def periodic(_now) -> None:
|
||||||
try:
|
try:
|
||||||
await core.refresh()
|
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))
|
interval = timedelta(seconds=int(core.refresh_seconds or 300))
|
||||||
async_track_time_interval(hass, periodic, interval)
|
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)
|
await async_load_platform(hass, Platform.UPDATE, DOMAIN, {}, config)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user