custom_components/bahmcloud_store/providers.py aktualisiert
This commit is contained in:
@@ -13,6 +13,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
@dataclass
|
@dataclass
|
||||||
class RepoInfo:
|
class RepoInfo:
|
||||||
owner: str | None = None
|
owner: str | None = None
|
||||||
|
repo_name: str | None = None
|
||||||
description: str | None = None
|
description: str | None = None
|
||||||
provider: 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:
|
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.
|
This is best-effort and must never break the store if it fails.
|
||||||
"""
|
"""
|
||||||
provider = detect_provider(repo_url)
|
provider = detect_provider(repo_url)
|
||||||
owner, repo = _split_owner_repo(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:
|
if not owner or not repo:
|
||||||
return info
|
return info
|
||||||
@@ -67,6 +68,8 @@ async def fetch_repo_info(hass: HomeAssistant, repo_url: str) -> RepoInfo:
|
|||||||
return info
|
return info
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
info.description = data.get("description")
|
info.description = data.get("description")
|
||||||
|
info.repo_name = data.get("name") or repo
|
||||||
|
|
||||||
# Owner returned by API is canonical
|
# Owner returned by API is canonical
|
||||||
if isinstance(data.get("owner"), dict) and data["owner"].get("login"):
|
if isinstance(data.get("owner"), dict) and data["owner"].get("login"):
|
||||||
info.owner = data["owner"]["login"]
|
info.owner = data["owner"]["login"]
|
||||||
@@ -82,6 +85,8 @@ async def fetch_repo_info(hass: HomeAssistant, repo_url: str) -> RepoInfo:
|
|||||||
return info
|
return info
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
info.description = data.get("description")
|
info.description = data.get("description")
|
||||||
|
info.repo_name = data.get("name") or repo
|
||||||
|
|
||||||
if isinstance(data.get("owner"), dict) and data["owner"].get("login"):
|
if isinstance(data.get("owner"), dict) and data["owner"].get("login"):
|
||||||
info.owner = data["owner"]["login"]
|
info.owner = data["owner"]["login"]
|
||||||
return info
|
return info
|
||||||
|
|||||||
Reference in New Issue
Block a user