custom_components/bahmcloud_store/core.py aktualisiert

This commit is contained in:
2026-01-15 16:58:31 +00:00
parent 4ca80a9c88
commit 85cc97b557

View File

@@ -88,6 +88,16 @@ class BCSCore:
except Exception: except Exception:
pass pass
async def full_refresh(self, source: str = "manual") -> None:
"""Run a full store refresh and notify listeners.
This is the single entry-point used by both the periodic timer and
the manual refresh button.
"""
_LOGGER.info("BCS full refresh triggered (source=%s)", source)
await self.refresh()
self.signal_updated()
async def register_http_views(self) -> None: async def register_http_views(self) -> None:
self.hass.http.register_view(StaticAssetsView()) self.hass.http.register_view(StaticAssetsView())
self.hass.http.register_view(BCSApiView(self)) self.hass.http.register_view(BCSApiView(self))
@@ -157,7 +167,6 @@ class BCSCore:
await asyncio.gather(*(process_one(r) for r in merged.values()), return_exceptions=True) await asyncio.gather(*(process_one(r) for r in merged.values()), return_exceptions=True)
def _add_cache_buster(self, url: str) -> str: def _add_cache_buster(self, url: str) -> str:
"""Append a timestamp query parameter safely (works with existing query params)."""
parts = urlsplit(url) parts = urlsplit(url)
q = dict(parse_qsl(parts.query, keep_blank_values=True)) q = dict(parse_qsl(parts.query, keep_blank_values=True))
q["t"] = str(int(time.time())) q["t"] = str(int(time.time()))
@@ -165,9 +174,6 @@ class BCSCore:
return urlunsplit((parts.scheme, parts.netloc, parts.path, new_query, parts.fragment)) return urlunsplit((parts.scheme, parts.netloc, parts.path, new_query, parts.fragment))
def _gitea_src_to_raw(self, url: str) -> str: def _gitea_src_to_raw(self, url: str) -> str:
"""If the URL points to a Gitea 'src' page, convert it to a raw file URL."""
# Example:
# /owner/repo/src/branch/main/store.yaml -> /owner/repo/raw/branch/main/store.yaml
parts = urlsplit(url) parts = urlsplit(url)
path = parts.path path = parts.path
path2 = path.replace("/src/branch/", "/raw/branch/") path2 = path.replace("/src/branch/", "/raw/branch/")
@@ -191,7 +197,6 @@ class BCSCore:
return await resp.text() return await resp.text()
async def _load_index_repos(self) -> tuple[list[RepoItem], int]: async def _load_index_repos(self) -> tuple[list[RepoItem], int]:
# ---- Phase B: force an actual remote reload of store.yaml ----
store_url = (self.config.store_url or "").strip() store_url = (self.config.store_url or "").strip()
if not store_url: if not store_url:
raise BCSError("store_url is empty") raise BCSError("store_url is empty")
@@ -201,8 +206,6 @@ class BCSCore:
try: try:
raw = await self._fetch_store_text(url) raw = await self._fetch_store_text(url)
# If we accidentally fetched a HTML "src" page, try converting to raw.
# This makes the system robust even if someone configures a /src/branch/ URL.
if "<html" in raw.lower() or "<!doctype html" in raw.lower(): if "<html" in raw.lower() or "<!doctype html" in raw.lower():
fallback = self._add_cache_buster(self._gitea_src_to_raw(store_url)) fallback = self._add_cache_buster(self._gitea_src_to_raw(store_url))
if fallback != url: if fallback != url:
@@ -211,7 +214,6 @@ class BCSCore:
except Exception as e: except Exception as e:
raise BCSError(f"Failed fetching store index: {e}") from e raise BCSError(f"Failed fetching store index: {e}") from e
# ---- end Phase B fix ----
try: try:
data = ha_yaml.parse_yaml(raw) data = ha_yaml.parse_yaml(raw)