revert custom_components/bahmcloud_store/__init__.py aktualisiert
This commit is contained in:
2026-01-15 14:37:48 +00:00
parent e867e82a2d
commit f3863ee227

View File

@@ -9,52 +9,51 @@ 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 from homeassistant.components.panel_custom import async_register_panel
from .core import BCSCore, BCSConfig, BCSError, DOMAIN from .core import BCSCore, BCSConfig, BCSError
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = "bahmcloud_store"
DEFAULT_STORE_URL = "https://git.bahmcloud.de/bahmcloud/ha_store/raw/branch/main/store.yaml" DEFAULT_STORE_URL = "https://git.bahmcloud.de/bahmcloud/ha_store/raw/branch/main/store.yaml"
CONF_STORE_URL = "store_url" CONF_STORE_URL = "store_url"
async def async_setup(hass: HomeAssistant, config: dict) -> bool: async def async_setup(hass: HomeAssistant, config: dict) -> bool:
domain_cfg = config.get(DOMAIN, {}) if isinstance(config.get(DOMAIN, {}), dict) else {} cfg = config.get(DOMAIN, {})
store_url = domain_cfg.get(CONF_STORE_URL, DEFAULT_STORE_URL) store_url = cfg.get(CONF_STORE_URL, DEFAULT_STORE_URL)
core = BCSCore(hass, BCSConfig(store_url=str(store_url))) core = BCSCore(hass, BCSConfig(store_url=store_url))
hass.data[DOMAIN] = core hass.data[DOMAIN] = core
await core.register_http_views() await core.register_http_views()
# Panel (works on HA 2026.1.x using panel_custom) # RESTORE: keep the module_url pattern that worked for you
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?v=1", module_url="/api/bahmcloud_store_static/panel.js?v=42",
sidebar_title="Bahmcloud Store", sidebar_title="Bahmcloud Store",
sidebar_icon="mdi:store", sidebar_icon="mdi:store",
require_admin=True, require_admin=True,
config={}, config={},
) )
# initial refresh
try: try:
await core.refresh() await core.refresh()
core.signal_updated()
except BCSError as e: except BCSError as e:
_LOGGER.warning("Initial refresh failed: %s", e) _LOGGER.error("Initial refresh failed: %s", e)
# auto refresh (only index list; no forced updates) async def periodic(_now) -> None:
async def _periodic(_now) -> None:
try: try:
await core.refresh() await core.refresh()
core.signal_updated() core.signal_updated()
except BCSError as e: except BCSError as e:
_LOGGER.debug("Periodic refresh failed: %s", e) _LOGGER.warning("Periodic refresh failed: %s", e)
async_track_time_interval(hass, _periodic, timedelta(seconds=int(core.refresh_seconds))) interval = timedelta(seconds=int(core.refresh_seconds or 300))
async_track_time_interval(hass, periodic, interval)
# Update entity platform (manual updates)
await async_load_platform(hass, Platform.UPDATE, DOMAIN, {}, config) await async_load_platform(hass, Platform.UPDATE, DOMAIN, {}, config)
return True return True