Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fff1b2692 | |||
| c8356c7603 | |||
| 0c49a50fc9 | |||
| fa48841645 | |||
| 1445fff739 | |||
| 5cf365f354 | |||
| f73ce4095c | |||
| 1484d53f8c | |||
| 0e99c9c59e | |||
| 644e61aab0 | |||
| 4c2a104af7 | |||
| 95dd8b9dc2 | |||
| 8b01c04a4c |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -11,6 +11,22 @@ Sections:
|
||||
|
||||
---
|
||||
|
||||
## 0.7.1 – 2026-01-20
|
||||
|
||||
### Fixed
|
||||
- GitHub version provider now reliably fetches the latest 20 releases/tags using authenticated API requests.
|
||||
- Repositories that were previously fetched in a degraded state (only `latest` and `branch`) are now automatically refreshed on repository view.
|
||||
- Cached version lists with incomplete data are no longer reused and are re-fetched from the provider.
|
||||
|
||||
## [0.7.0] - 2026-01-20
|
||||
|
||||
### Added
|
||||
- Options dialog (gear icon) for the Bahmcloud Store integration.
|
||||
- Optional GitHub token can now be set, changed or removed via the Home Assistant UI.
|
||||
|
||||
### Fixed
|
||||
- Fixed missing options flow when clicking the integration settings button.
|
||||
|
||||
## [0.6.9] – 2026-01-19
|
||||
### Added
|
||||
- New Home Assistant **GUI setup** (Config Flow) – no YAML configuration required.
|
||||
|
||||
@@ -6,48 +6,53 @@ from datetime import timedelta
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.components.panel_custom import async_register_panel
|
||||
from homeassistant.helpers.event import async_track_time_interval, async_call_later
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED
|
||||
from homeassistant.helpers.event import async_call_later, async_track_time_interval
|
||||
|
||||
from .core import BCSCore, BCSConfig, BCSError
|
||||
from .config_flow import CONF_GITHUB_TOKEN
|
||||
from .const import CONF_GITHUB_TOKEN, DEFAULT_STORE_URL, DOMAIN
|
||||
from .core import BCSError, BCSConfig, BCSCore
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "bahmcloud_store"
|
||||
|
||||
# Fixed store index URL (not configurable by users)
|
||||
DEFAULT_STORE_URL = "https://git.bahmcloud.de/bahmcloud/ha_store/raw/branch/main/store.yaml"
|
||||
|
||||
PLATFORMS: list[str] = ["update"]
|
||||
|
||||
DATA_ENTRY = f"{DOMAIN}_entry_runtime"
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
||||
"""Set up Bahmcloud Store.
|
||||
|
||||
YAML configuration is intentionally not supported.
|
||||
Setup must happen via the UI (Config Flow).
|
||||
We intentionally do NOT support YAML configuration.
|
||||
This method is kept so we can log a helpful message if someone tries.
|
||||
"""
|
||||
if DOMAIN in (config or {}):
|
||||
_LOGGER.warning(
|
||||
"BCS does not support configuration.yaml setup. "
|
||||
"Please remove 'bahmcloud_store:' from configuration.yaml and set up the integration via Settings -> Devices & Services."
|
||||
"BCS YAML configuration is no longer supported. "
|
||||
"Please remove 'bahmcloud_store:' from configuration.yaml and set up the integration via the UI."
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Bahmcloud Store from a config entry."""
|
||||
token = (entry.options.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
||||
"""Set up Bahmcloud Store from a config entry (UI setup)."""
|
||||
# Only one instance.
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
core = BCSCore(hass, BCSConfig(store_url=DEFAULT_STORE_URL, github_token=token))
|
||||
hass.data[DOMAIN] = core
|
||||
github_token = (entry.options.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
||||
|
||||
core = BCSCore(
|
||||
hass,
|
||||
BCSConfig(
|
||||
store_url=DEFAULT_STORE_URL,
|
||||
github_token=github_token,
|
||||
),
|
||||
)
|
||||
|
||||
hass.data[DOMAIN][entry.entry_id] = core
|
||||
# Keep a convenient shortcut for platforms that previously used hass.data[DOMAIN] directly.
|
||||
hass.data[DOMAIN]["_core"] = core
|
||||
|
||||
await core.async_initialize()
|
||||
|
||||
# Register HTTP views + static assets
|
||||
# HTTP views + panel (registered once per entry; we only allow one entry).
|
||||
from .views import (
|
||||
StaticAssetsView,
|
||||
BCSApiView,
|
||||
@@ -78,7 +83,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
hass.http.register_view(BCSRestoreView(core))
|
||||
hass.http.register_view(BCSRestartView(core))
|
||||
|
||||
# Sidebar panel
|
||||
await async_register_panel(
|
||||
hass,
|
||||
frontend_url_path="bahmcloud-store",
|
||||
@@ -91,16 +95,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
config={},
|
||||
)
|
||||
|
||||
# Forward platform setup (Update entities)
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
async def _do_startup_refresh(_now=None) -> None:
|
||||
try:
|
||||
await core.full_refresh(source="startup")
|
||||
except BCSError as e:
|
||||
_LOGGER.error("Initial refresh failed: %s", e)
|
||||
|
||||
# Do not block HA startup: schedule refresh after HA started.
|
||||
# Do not block startup; refresh after HA is up.
|
||||
def _on_ha_started(_event) -> None:
|
||||
async_call_later(hass, 30, _do_startup_refresh)
|
||||
|
||||
@@ -115,30 +116,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
_LOGGER.exception("Unexpected error during periodic refresh: %s", e)
|
||||
|
||||
interval_seconds = int(getattr(core, "refresh_seconds", 300) or 300)
|
||||
unsub = async_track_time_interval(hass, periodic, timedelta(seconds=interval_seconds))
|
||||
async_track_time_interval(hass, periodic, timedelta(seconds=interval_seconds))
|
||||
|
||||
# Store unload callbacks safely
|
||||
runtimes = hass.data.setdefault(DATA_ENTRY, {})
|
||||
runtimes[entry.entry_id] = {"unsub_interval": unsub}
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
try:
|
||||
runtimes = hass.data.get(DATA_ENTRY, {}) or {}
|
||||
rt = runtimes.pop(entry.entry_id, {}) if isinstance(runtimes, dict) else {}
|
||||
unsub = rt.get("unsub_interval")
|
||||
if callable(unsub):
|
||||
unsub()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data.pop(DOMAIN, None)
|
||||
try:
|
||||
hass.data.get(DOMAIN, {}).pop(entry.entry_id, None)
|
||||
except Exception:
|
||||
pass
|
||||
return unload_ok
|
||||
|
||||
|
||||
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
@@ -1,87 +1,71 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.core import callback
|
||||
|
||||
DOMAIN = "bahmcloud_store"
|
||||
from .const import CONF_GITHUB_TOKEN, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_GITHUB_TOKEN = "github_token"
|
||||
|
||||
def _schema(default_token: str | None = None) -> vol.Schema:
|
||||
default_token = (default_token or "").strip()
|
||||
return vol.Schema({vol.Optional(CONF_GITHUB_TOKEN, default=default_token): str})
|
||||
|
||||
|
||||
class BCSConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
class BahmcloudStoreConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Config flow for Bahmcloud Store.
|
||||
|
||||
Design goals:
|
||||
- GUI setup only (no YAML config)
|
||||
- store index URL is fixed (not configurable)
|
||||
- optional GitHub token to raise API rate limits
|
||||
The store index URL is fixed and not user-configurable.
|
||||
The only optional setting is a GitHub token to increase API rate limits.
|
||||
"""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input: dict[str, Any] | None = None):
|
||||
"""Handle the initial step."""
|
||||
# Single instance only
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason="single_instance_allowed")
|
||||
async def async_step_user(self, user_input: dict | None = None):
|
||||
# Allow only one instance.
|
||||
await self.async_set_unique_id(DOMAIN)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
if user_input is not None:
|
||||
token = (user_input.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
||||
data: dict[str, Any] = {}
|
||||
options: dict[str, Any] = {}
|
||||
if token:
|
||||
options[CONF_GITHUB_TOKEN] = token
|
||||
if user_input is None:
|
||||
return self.async_show_form(step_id="user", data_schema=_schema(None))
|
||||
|
||||
return self.async_create_entry(title="Bahmcloud Store", data=data, options=options)
|
||||
token = str(user_input.get(CONF_GITHUB_TOKEN, "")).strip() or None
|
||||
|
||||
schema = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_GITHUB_TOKEN, default=""): str,
|
||||
}
|
||||
)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=schema,
|
||||
description_placeholders={
|
||||
"rate_limit": "GitHub API is rate-limited without a token (recommended for large indexes / HACS).",
|
||||
},
|
||||
return self.async_create_entry(
|
||||
title="Bahmcloud Store",
|
||||
data={},
|
||||
options={CONF_GITHUB_TOKEN: token} if token else {},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(config_entry: config_entries.ConfigEntry):
|
||||
return BCSOptionsFlowHandler(config_entry)
|
||||
return BahmcloudStoreOptionsFlowHandler(config_entry)
|
||||
|
||||
|
||||
class BCSOptionsFlowHandler(config_entries.OptionsFlow):
|
||||
"""Handle options for Bahmcloud Store."""
|
||||
class BahmcloudStoreOptionsFlowHandler(config_entries.OptionsFlow):
|
||||
"""Options flow to manage optional GitHub token."""
|
||||
|
||||
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
|
||||
self.config_entry = config_entry
|
||||
self._config_entry = config_entry
|
||||
|
||||
async def async_step_init(self, user_input: dict[str, Any] | None = None):
|
||||
if user_input is not None:
|
||||
token = (user_input.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
||||
opts: dict[str, Any] = dict(self.config_entry.options)
|
||||
async def async_step_init(self, user_input: dict | None = None):
|
||||
if user_input is None:
|
||||
current = self._config_entry.options.get(CONF_GITHUB_TOKEN) or ""
|
||||
return self.async_show_form(step_id="init", data_schema=_schema(str(current)))
|
||||
|
||||
token = str(user_input.get(CONF_GITHUB_TOKEN, "")).strip() or None
|
||||
options = dict(self._config_entry.options)
|
||||
|
||||
# Allow clearing the token.
|
||||
if token:
|
||||
opts[CONF_GITHUB_TOKEN] = token
|
||||
options[CONF_GITHUB_TOKEN] = token
|
||||
else:
|
||||
opts.pop(CONF_GITHUB_TOKEN, None)
|
||||
return self.async_create_entry(title="", data=opts)
|
||||
options.pop(CONF_GITHUB_TOKEN, None)
|
||||
|
||||
cur = (self.config_entry.options.get(CONF_GITHUB_TOKEN) or "").strip()
|
||||
schema = vol.Schema({vol.Optional(CONF_GITHUB_TOKEN, default=cur): str})
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="init",
|
||||
data_schema=schema,
|
||||
description_placeholders={
|
||||
"rate_limit": "Optional. Adds GitHub authorization to avoid rate limits.",
|
||||
},
|
||||
)
|
||||
return self.async_create_entry(title="", data=options)
|
||||
|
||||
11
custom_components/bahmcloud_store/const.py
Normal file
11
custom_components/bahmcloud_store/const.py
Normal file
@@ -0,0 +1,11 @@
|
||||
"""Constants for Bahmcloud Store."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
DOMAIN = "bahmcloud_store"
|
||||
|
||||
# Fixed store index URL (not user-configurable).
|
||||
DEFAULT_STORE_URL = "https://git.bahmcloud.de/bahmcloud/ha_store/raw/branch/main/store.yaml"
|
||||
|
||||
# Config entry option keys
|
||||
CONF_GITHUB_TOKEN = "github_token"
|
||||
@@ -697,11 +697,7 @@ class BCSCore:
|
||||
|
||||
async def process_one(r: RepoItem) -> None:
|
||||
async with sem:
|
||||
info: RepoInfo = await fetch_repo_info(
|
||||
self.hass,
|
||||
r.url,
|
||||
github_token=self.config.github_token,
|
||||
)
|
||||
info: RepoInfo = await fetch_repo_info(self.hass, r.url, github_token=self.config.github_token)
|
||||
|
||||
r.provider = info.provider or r.provider
|
||||
r.owner = info.owner or r.owner
|
||||
@@ -760,11 +756,7 @@ class BCSCore:
|
||||
|
||||
async def _enrich_one_repo(self, r: RepoItem) -> None:
|
||||
"""Fetch provider info + metadata for a single repo item."""
|
||||
info: RepoInfo = await fetch_repo_info(
|
||||
self.hass,
|
||||
r.url,
|
||||
github_token=self.config.github_token,
|
||||
)
|
||||
info: RepoInfo = await fetch_repo_info(self.hass, r.url, github_token=self.config.github_token)
|
||||
|
||||
r.provider = info.provider or r.provider
|
||||
r.owner = info.owner or r.owner
|
||||
@@ -816,13 +808,21 @@ class BCSCore:
|
||||
_LOGGER.debug("BCS ensure_repo_details failed for %s", repo_id, exc_info=True)
|
||||
return r
|
||||
|
||||
async def list_repo_versions(self, repo_id: str, *, limit: int = 20) -> list[dict[str, str]]:
|
||||
async def list_repo_versions(
|
||||
self,
|
||||
repo_id: str,
|
||||
*,
|
||||
limit: int = 20,
|
||||
force_refresh: bool = False,
|
||||
) -> list[dict[str, Any]]:
|
||||
repo = self.get_repo(repo_id)
|
||||
if not repo:
|
||||
return []
|
||||
|
||||
# Prefer cached version lists to avoid hammering provider APIs (notably GitHub unauthenticated
|
||||
# rate limits). We refresh on-demand when the user opens the selector.
|
||||
# rate limits). However, if the cached list is clearly a degraded fallback (e.g. only
|
||||
# "Latest" + "Branch"), we treat it as stale and retry immediately when the user requests
|
||||
# versions again.
|
||||
cached = None
|
||||
cached_ts = 0
|
||||
async with self._repo_cache_lock:
|
||||
@@ -831,8 +831,17 @@ class BCSCore:
|
||||
cached_ts = int(cached.get("versions_ts", 0) or 0)
|
||||
|
||||
now = int(time.time())
|
||||
if isinstance(cached, dict) and cached.get("versions") and (now - cached_ts) < VERSIONS_CACHE_TTL_SECONDS:
|
||||
return list(cached.get("versions") or [])
|
||||
cached_versions = list(cached.get("versions") or []) if isinstance(cached, dict) else []
|
||||
cache_fresh = (now - cached_ts) < VERSIONS_CACHE_TTL_SECONDS
|
||||
|
||||
# Cache hit if it's fresh and not degraded, unless the caller explicitly wants a refresh.
|
||||
if (
|
||||
not force_refresh
|
||||
and cached_versions
|
||||
and cache_fresh
|
||||
and len(cached_versions) > 2
|
||||
):
|
||||
return cached_versions
|
||||
|
||||
try:
|
||||
versions = await fetch_repo_versions(
|
||||
@@ -840,8 +849,8 @@ class BCSCore:
|
||||
repo.url,
|
||||
provider=repo.provider,
|
||||
default_branch=repo.default_branch,
|
||||
github_token=self.config.github_token,
|
||||
limit=limit,
|
||||
github_token=self.config.github_token,
|
||||
)
|
||||
except Exception:
|
||||
versions = []
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"domain": "bahmcloud_store",
|
||||
"name": "Bahmcloud Store",
|
||||
"version": "0.6.9",
|
||||
"version": "0.7.1",
|
||||
"documentation": "https://git.bahmcloud.de/bahmcloud/bahmcloud_store",
|
||||
"config_flow": true,
|
||||
"platforms": ["update"],
|
||||
"requirements": [],
|
||||
"codeowners": ["@bahmcloud"],
|
||||
|
||||
@@ -16,17 +16,6 @@ _LOGGER = logging.getLogger(__name__)
|
||||
UA = "BahmcloudStore (Home Assistant)"
|
||||
|
||||
|
||||
def _github_headers(github_token: str | None = None) -> dict[str, str]:
|
||||
headers = {
|
||||
"Accept": "application/vnd.github+json",
|
||||
"User-Agent": UA,
|
||||
}
|
||||
token = (github_token or "").strip()
|
||||
if token:
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
return headers
|
||||
|
||||
|
||||
@dataclass
|
||||
class RepoInfo:
|
||||
owner: str | None = None
|
||||
@@ -331,6 +320,15 @@ async def _gitlab_latest_version(
|
||||
return None, None
|
||||
|
||||
|
||||
def _github_headers(github_token: str | None = None) -> dict:
|
||||
headers = {"Accept": "application/vnd.github+json", "User-Agent": UA}
|
||||
token = (github_token or "").strip()
|
||||
if token:
|
||||
# PAT or fine-grained token
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
return headers
|
||||
|
||||
|
||||
async def fetch_repo_info(hass: HomeAssistant, repo_url: str, *, github_token: str | None = None) -> RepoInfo:
|
||||
provider = detect_provider(repo_url)
|
||||
owner, repo = _split_owner_repo(repo_url)
|
||||
@@ -539,7 +537,7 @@ async def fetch_repo_versions(
|
||||
- source: release|tag|branch
|
||||
|
||||
Notes:
|
||||
- Uses public endpoints (no tokens) for public repositories.
|
||||
- Uses provider APIs; for GitHub we include the configured token (if any) to avoid unauthenticated rate limits.
|
||||
- We prefer releases first (if available), then tags.
|
||||
"""
|
||||
|
||||
@@ -557,6 +555,8 @@ async def fetch_repo_versions(
|
||||
|
||||
session = async_get_clientsession(hass)
|
||||
headers = {"User-Agent": UA}
|
||||
if prov == "github":
|
||||
headers = _github_headers(github_token)
|
||||
|
||||
out: list[dict[str, str]] = []
|
||||
seen: set[str] = set()
|
||||
@@ -575,11 +575,13 @@ async def fetch_repo_versions(
|
||||
|
||||
try:
|
||||
if prov == "github":
|
||||
# Releases
|
||||
# Releases (prefer these over tags)
|
||||
# Use the configured GitHub token (if any) to avoid unauthenticated rate limits.
|
||||
gh_headers = _github_headers(github_token)
|
||||
per_page = max(1, min(int(limit), 100))
|
||||
data, _ = await _safe_json(
|
||||
session,
|
||||
f"https://api.github.com/repos/{owner}/{repo}/releases?per_page={int(limit)}",
|
||||
f"https://api.github.com/repos/{owner}/{repo}/releases?per_page={per_page}",
|
||||
headers=gh_headers,
|
||||
)
|
||||
if isinstance(data, list):
|
||||
@@ -597,7 +599,7 @@ async def fetch_repo_versions(
|
||||
# Tags
|
||||
data, _ = await _safe_json(
|
||||
session,
|
||||
f"https://api.github.com/repos/{owner}/{repo}/tags?per_page={int(limit)}",
|
||||
f"https://api.github.com/repos/{owner}/{repo}/tags?per_page={per_page}",
|
||||
headers=gh_headers,
|
||||
)
|
||||
if isinstance(data, list):
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"config": {
|
||||
"abort": {
|
||||
"single_instance_allowed": "Bahmcloud Store is already configured."
|
||||
"single_instance_allowed": "Only one Bahmcloud Store instance can be configured."
|
||||
},
|
||||
"step": {
|
||||
"user": {
|
||||
"title": "Set up Bahmcloud Store",
|
||||
"description": "The store index is fixed to the official Bahmcloud Store.\n\nOptional: Add a GitHub token to increase API rate limits for GitHub/HACS repositories.",
|
||||
"title": "Bahmcloud Store",
|
||||
"description": "Bahmcloud Store uses a fixed official store index. You can optionally add a GitHub token to increase API rate limits.",
|
||||
"data": {
|
||||
"github_token": "GitHub token (optional)"
|
||||
}
|
||||
@@ -16,8 +16,8 @@
|
||||
"options": {
|
||||
"step": {
|
||||
"init": {
|
||||
"title": "Bahmcloud Store options",
|
||||
"description": "Optional: Configure a GitHub token to increase API rate limits.",
|
||||
"title": "Bahmcloud Store Options",
|
||||
"description": "Optionally set or clear your GitHub token to reduce rate limiting.",
|
||||
"data": {
|
||||
"github_token": "GitHub token (optional)"
|
||||
}
|
||||
|
||||
@@ -5,17 +5,26 @@ from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
||||
from .core import DOMAIN, SIGNAL_UPDATED, BCSCore
|
||||
from .const import DOMAIN
|
||||
from .core import SIGNAL_UPDATED, BCSCore
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_core(hass: HomeAssistant) -> BCSCore | None:
|
||||
data = hass.data.get(DOMAIN)
|
||||
if isinstance(data, dict):
|
||||
c = data.get("_core")
|
||||
return c if isinstance(c, BCSCore) else None
|
||||
# Backwards compatibility (older versions used hass.data[DOMAIN] = core)
|
||||
return data if isinstance(data, BCSCore) else None
|
||||
|
||||
|
||||
def _pretty_repo_name(core: BCSCore, repo_id: str) -> str:
|
||||
"""Return a human-friendly name for a repo update entity."""
|
||||
try:
|
||||
@@ -140,9 +149,14 @@ def _sync_entities(core: BCSCore, existing: dict[str, BCSRepoUpdateEntity], asyn
|
||||
ent.async_write_ha_state()
|
||||
|
||||
|
||||
async def _async_setup(hass: HomeAssistant, async_add_entities: AddEntitiesCallback) -> None:
|
||||
"""Common update entity setup for both config entries and legacy YAML."""
|
||||
core: BCSCore | None = hass.data.get(DOMAIN)
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info=None,
|
||||
):
|
||||
"""Set up BCS update entities."""
|
||||
core: BCSCore | None = _get_core(hass)
|
||||
if not core:
|
||||
_LOGGER.debug("BCS core not available, skipping update platform setup")
|
||||
return
|
||||
@@ -160,18 +174,8 @@ async def _async_setup(hass: HomeAssistant, async_add_entities: AddEntitiesCallb
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up update entities from a config entry."""
|
||||
await _async_setup(hass, async_add_entities)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info=None,
|
||||
):
|
||||
"""Legacy YAML setup (not supported, kept for safety)."""
|
||||
await _async_setup(hass, async_add_entities)
|
||||
"""Set up BCS update entities from a config entry."""
|
||||
await async_setup_platform(hass, {}, async_add_entities, None)
|
||||
Reference in New Issue
Block a user