custom_components/bahmcloud_store/providers.py aktualisiert

This commit is contained in:
2026-01-15 07:17:51 +00:00
parent d226edaac8
commit b4b6b2b987

View File

@@ -13,6 +13,7 @@ _LOGGER = logging.getLogger(__name__)
@dataclass
class RepoInfo:
owner: str | None = None
repo_name: str | None = None
description: str | None = None
provider: str | None = None
@@ -41,13 +42,13 @@ def detect_provider(repo_url: str) -> str:
async def fetch_repo_info(hass: HomeAssistant, repo_url: str) -> RepoInfo:
"""
Fetch owner/description from a provider API if possible.
Fetch owner/name/description from a provider API if possible.
This is best-effort and must never break the store if it fails.
"""
provider = detect_provider(repo_url)
owner, repo = _split_owner_repo(repo_url)
info = RepoInfo(owner=owner, description=None, provider=provider)
info = RepoInfo(owner=owner, repo_name=repo, description=None, provider=provider)
if not owner or not repo:
return info
@@ -67,6 +68,8 @@ async def fetch_repo_info(hass: HomeAssistant, repo_url: str) -> RepoInfo:
return info
data = await resp.json()
info.description = data.get("description")
info.repo_name = data.get("name") or repo
# Owner returned by API is canonical
if isinstance(data.get("owner"), dict) and data["owner"].get("login"):
info.owner = data["owner"]["login"]
@@ -82,6 +85,8 @@ async def fetch_repo_info(hass: HomeAssistant, repo_url: str) -> RepoInfo:
return info
data = await resp.json()
info.description = data.get("description")
info.repo_name = data.get("name") or repo
if isinstance(data.get("owner"), dict) and data["owner"].get("login"):
info.owner = data["owner"]["login"]
return info