From 67297bfc9cbc2294cc869d5adc54092af84b3d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bachmann?= Date: Thu, 15 Jan 2026 15:43:05 +0000 Subject: [PATCH] custom_components/bahmcloud_store/providers.py aktualisiert --- .../bahmcloud_store/providers.py | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/custom_components/bahmcloud_store/providers.py b/custom_components/bahmcloud_store/providers.py index a7432b7..191d65e 100644 --- a/custom_components/bahmcloud_store/providers.py +++ b/custom_components/bahmcloud_store/providers.py @@ -77,21 +77,13 @@ async def _safe_text(session, url: str, *, headers: dict | None = None, timeout: def _extract_tag_from_github_url(url: str) -> str | None: - # Example: https://github.com/owner/repo/releases/tag/v1.2.3 m = re.search(r"/releases/tag/([^/?#]+)", url or "") if not m: return None return m.group(1).strip() or None -def _strip_html(s: str) -> str: - if not s: - return "" - return re.sub(r"<[^>]+>", "", s).strip() - - def _extract_meta(html: str, *, prop: str | None = None, name: str | None = None) -> str | None: - # Try common meta tags if not html: return None if prop: @@ -112,13 +104,11 @@ async def _github_description_html(hass: HomeAssistant, owner: str, repo: str) - if status != 200 or not html: return None - # Prefer og:description desc = _extract_meta(html, prop="og:description") if desc: return desc - desc = _extract_meta(html, name="description") - return desc + return _extract_meta(html, name="description") async def _github_latest_version_atom(hass: HomeAssistant, owner: str, repo: str) -> tuple[str | None, str | None]: @@ -151,7 +141,6 @@ async def _github_latest_version_atom(hass: HomeAssistant, owner: str, repo: str async def _github_latest_version_redirect(hass: HomeAssistant, owner: str, repo: str) -> tuple[str | None, str | None]: - # Use the /latest redirect (no API token needed), then parse tag out of final URL session = async_get_clientsession(hass) url = f"https://github.com/{owner}/{repo}/releases/latest" try: @@ -176,7 +165,6 @@ async def _github_latest_version_api(hass: HomeAssistant, owner: str, repo: str) if isinstance(data, dict) and data.get("tag_name"): return str(data["tag_name"]), "release" - # No releases -> tags if status == 404: data, _ = await _safe_json(session, f"https://api.github.com/repos/{owner}/{repo}/tags?per_page=1", headers=headers) if isinstance(data, list) and data: @@ -188,10 +176,6 @@ async def _github_latest_version_api(hass: HomeAssistant, owner: str, repo: str) async def _github_latest_version(hass: HomeAssistant, owner: str, repo: str) -> tuple[str | None, str | None]: - # Order: - # 1) redirect /latest - # 2) API (may rate-limit) - # 3) Atom feed fallback tag, src = await _github_latest_version_redirect(hass, owner, repo) if tag: return tag, src @@ -221,7 +205,9 @@ async def _gitea_latest_version(hass: HomeAssistant, base: str, owner: str, repo return None, None -async def _gitlab_latest_version(hass: HomeAssistant, base: ...str, owner: str, repo: str) -> tuple[str | None, str | None]: +async def _gitlab_latest_version( + hass: HomeAssistant, base: str, owner: str, repo: str +) -> tuple[str | None, str | None]: session = async_get_clientsession(hass) headers = {"User-Agent": UA}