|
|
|
|
@@ -26,7 +26,6 @@ def _pretty_repo_name(core: BCSCore, repo_id: str) -> str:
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# Fallbacks
|
|
|
|
|
if repo_id.startswith("index:"):
|
|
|
|
|
return f"BCS Index {repo_id.split(':', 1)[1]}"
|
|
|
|
|
if repo_id.startswith("custom:"):
|
|
|
|
|
@@ -53,11 +52,11 @@ class BCSRepoUpdateEntity(UpdateEntity):
|
|
|
|
|
# Stable unique id (do NOT change)
|
|
|
|
|
self._attr_unique_id = f"{DOMAIN}:{repo_id}"
|
|
|
|
|
|
|
|
|
|
# Human-friendly name in UI
|
|
|
|
|
pretty = _pretty_repo_name(core, repo_id)
|
|
|
|
|
self._attr_name = pretty
|
|
|
|
|
self._refresh_display_name()
|
|
|
|
|
|
|
|
|
|
# Title shown in the entity dialog
|
|
|
|
|
def _refresh_display_name(self) -> None:
|
|
|
|
|
pretty = _pretty_repo_name(self._core, self._repo_id)
|
|
|
|
|
self._attr_name = pretty
|
|
|
|
|
self._attr_title = pretty
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
@@ -102,9 +101,7 @@ class BCSRepoUpdateEntity(UpdateEntity):
|
|
|
|
|
|
|
|
|
|
async def async_install(self, version: str | None, backup: bool, **kwargs: Any) -> None:
|
|
|
|
|
if version is not None:
|
|
|
|
|
_LOGGER.debug(
|
|
|
|
|
"BCS update entity requested specific version=%s (ignored)", version
|
|
|
|
|
)
|
|
|
|
|
_LOGGER.debug("BCS update entity requested specific version=%s (ignored)", version)
|
|
|
|
|
|
|
|
|
|
self._in_progress = True
|
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
@@ -117,19 +114,18 @@ class BCSRepoUpdateEntity(UpdateEntity):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
|
def _sync_entities(
|
|
|
|
|
core: BCSCore,
|
|
|
|
|
existing: dict[str, BCSRepoUpdateEntity],
|
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Ensure there is one update entity per installed repo."""
|
|
|
|
|
def _sync_entities(core: BCSCore, existing: dict[str, BCSRepoUpdateEntity], async_add_entities: AddEntitiesCallback) -> None:
|
|
|
|
|
"""Ensure there is one update entity per installed repo AND keep names in sync."""
|
|
|
|
|
installed_map = getattr(core, "_installed_cache", {}) or {}
|
|
|
|
|
new_entities: list[BCSRepoUpdateEntity] = []
|
|
|
|
|
|
|
|
|
|
for repo_id, data in installed_map.items():
|
|
|
|
|
if not isinstance(data, dict):
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if repo_id in existing:
|
|
|
|
|
# IMPORTANT: Update display name after refresh, when repo.name becomes available.
|
|
|
|
|
existing[repo_id]._refresh_display_name()
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
ent = BCSRepoUpdateEntity(core, repo_id)
|
|
|
|
|
|