From 1484d53f8c2e78b1b21738d3e40a03b605995071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bachmann?= Date: Tue, 20 Jan 2026 05:47:00 +0000 Subject: [PATCH] 0.7.0 --- custom_components/bahmcloud_store/update.py | 40 +++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/custom_components/bahmcloud_store/update.py b/custom_components/bahmcloud_store/update.py index 17ac795..3770343 100644 --- a/custom_components/bahmcloud_store/update.py +++ b/custom_components/bahmcloud_store/update.py @@ -5,17 +5,26 @@ from dataclasses import dataclass from typing import Any from homeassistant.components.update import UpdateEntity, UpdateEntityFeature -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity import EntityCategory -from .core import DOMAIN, SIGNAL_UPDATED, BCSCore +from .const import DOMAIN +from .core import SIGNAL_UPDATED, BCSCore _LOGGER = logging.getLogger(__name__) +def _get_core(hass: HomeAssistant) -> BCSCore | None: + data = hass.data.get(DOMAIN) + if isinstance(data, dict): + c = data.get("_core") + return c if isinstance(c, BCSCore) else None + # Backwards compatibility (older versions used hass.data[DOMAIN] = core) + return data if isinstance(data, BCSCore) else None + + def _pretty_repo_name(core: BCSCore, repo_id: str) -> str: """Return a human-friendly name for a repo update entity.""" try: @@ -140,9 +149,14 @@ def _sync_entities(core: BCSCore, existing: dict[str, BCSRepoUpdateEntity], asyn ent.async_write_ha_state() -async def _async_setup(hass: HomeAssistant, async_add_entities: AddEntitiesCallback) -> None: - """Common update entity setup for both config entries and legacy YAML.""" - core: BCSCore | None = hass.data.get(DOMAIN) +async def async_setup_platform( + hass: HomeAssistant, + config, + async_add_entities: AddEntitiesCallback, + discovery_info=None, +): + """Set up BCS update entities.""" + core: BCSCore | None = _get_core(hass) if not core: _LOGGER.debug("BCS core not available, skipping update platform setup") return @@ -160,18 +174,8 @@ async def _async_setup(hass: HomeAssistant, async_add_entities: AddEntitiesCallb async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry, async_add_entities: AddEntitiesCallback, ) -> None: - """Set up update entities from a config entry.""" - await _async_setup(hass, async_add_entities) - - -async def async_setup_platform( - hass: HomeAssistant, - config, - async_add_entities: AddEntitiesCallback, - discovery_info=None, -): - """Legacy YAML setup (not supported, kept for safety).""" - await _async_setup(hass, async_add_entities) \ No newline at end of file + """Set up BCS update entities from a config entry.""" + await async_setup_platform(hass, {}, async_add_entities, None) \ No newline at end of file