custom_components/bahmcloud_store/providers.py aktualisiert
This commit is contained in:
@@ -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}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user