Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1445fff739 | |||
| 5cf365f354 | |||
| f73ce4095c | |||
| 1484d53f8c | |||
| 0e99c9c59e | |||
| 644e61aab0 | |||
| 4c2a104af7 | |||
| 95dd8b9dc2 | |||
| 8b01c04a4c |
@@ -11,6 +11,15 @@ Sections:
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [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
|
## [0.6.9] – 2026-01-19
|
||||||
### Added
|
### Added
|
||||||
- New Home Assistant **GUI setup** (Config Flow) – no YAML configuration required.
|
- 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.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.components.panel_custom import async_register_panel
|
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.const import EVENT_HOMEASSISTANT_STARTED
|
||||||
|
from homeassistant.helpers.event import async_call_later, async_track_time_interval
|
||||||
|
|
||||||
from .core import BCSCore, BCSConfig, BCSError
|
from .const import CONF_GITHUB_TOKEN, DEFAULT_STORE_URL, DOMAIN
|
||||||
from .config_flow import CONF_GITHUB_TOKEN
|
from .core import BCSError, BCSConfig, BCSCore
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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"]
|
PLATFORMS: list[str] = ["update"]
|
||||||
|
|
||||||
DATA_ENTRY = f"{DOMAIN}_entry_runtime"
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
||||||
"""Set up Bahmcloud Store.
|
"""Set up Bahmcloud Store.
|
||||||
|
|
||||||
YAML configuration is intentionally not supported.
|
We intentionally do NOT support YAML configuration.
|
||||||
Setup must happen via the UI (Config Flow).
|
This method is kept so we can log a helpful message if someone tries.
|
||||||
"""
|
"""
|
||||||
if DOMAIN in (config or {}):
|
if DOMAIN in (config or {}):
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"BCS does not support configuration.yaml setup. "
|
"BCS YAML configuration is no longer supported. "
|
||||||
"Please remove 'bahmcloud_store:' from configuration.yaml and set up the integration via Settings -> Devices & Services."
|
"Please remove 'bahmcloud_store:' from configuration.yaml and set up the integration via the UI."
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Bahmcloud Store from a config entry."""
|
"""Set up Bahmcloud Store from a config entry (UI setup)."""
|
||||||
token = (entry.options.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
# Only one instance.
|
||||||
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
|
||||||
core = BCSCore(hass, BCSConfig(store_url=DEFAULT_STORE_URL, github_token=token))
|
github_token = (entry.options.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
||||||
hass.data[DOMAIN] = core
|
|
||||||
|
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()
|
await core.async_initialize()
|
||||||
|
|
||||||
# Register HTTP views + static assets
|
# HTTP views + panel (registered once per entry; we only allow one entry).
|
||||||
from .views import (
|
from .views import (
|
||||||
StaticAssetsView,
|
StaticAssetsView,
|
||||||
BCSApiView,
|
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(BCSRestoreView(core))
|
||||||
hass.http.register_view(BCSRestartView(core))
|
hass.http.register_view(BCSRestartView(core))
|
||||||
|
|
||||||
# Sidebar panel
|
|
||||||
await async_register_panel(
|
await async_register_panel(
|
||||||
hass,
|
hass,
|
||||||
frontend_url_path="bahmcloud-store",
|
frontend_url_path="bahmcloud-store",
|
||||||
@@ -91,16 +95,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
config={},
|
config={},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Forward platform setup (Update entities)
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
||||||
|
|
||||||
async def _do_startup_refresh(_now=None) -> None:
|
async def _do_startup_refresh(_now=None) -> None:
|
||||||
try:
|
try:
|
||||||
await core.full_refresh(source="startup")
|
await core.full_refresh(source="startup")
|
||||||
except BCSError as e:
|
except BCSError as e:
|
||||||
_LOGGER.error("Initial refresh failed: %s", 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:
|
def _on_ha_started(_event) -> None:
|
||||||
async_call_later(hass, 30, _do_startup_refresh)
|
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)
|
_LOGGER.exception("Unexpected error during periodic refresh: %s", e)
|
||||||
|
|
||||||
interval_seconds = int(getattr(core, "refresh_seconds", 300) or 300)
|
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
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
runtimes = hass.data.setdefault(DATA_ENTRY, {})
|
|
||||||
runtimes[entry.entry_id] = {"unsub_interval": unsub}
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""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)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data.pop(DOMAIN, None)
|
try:
|
||||||
|
hass.data.get(DOMAIN, {}).pop(entry.entry_id, None)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return unload_ok
|
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
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.core import callback
|
||||||
|
|
||||||
DOMAIN = "bahmcloud_store"
|
from .const import CONF_GITHUB_TOKEN, DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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.
|
"""Config flow for Bahmcloud Store.
|
||||||
|
|
||||||
Design goals:
|
The store index URL is fixed and not user-configurable.
|
||||||
- GUI setup only (no YAML config)
|
The only optional setting is a GitHub token to increase API rate limits.
|
||||||
- store index URL is fixed (not configurable)
|
|
||||||
- optional GitHub token to raise API rate limits
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
async def async_step_user(self, user_input: dict[str, Any] | None = None):
|
async def async_step_user(self, user_input: dict | None = None):
|
||||||
"""Handle the initial step."""
|
# Allow only one instance.
|
||||||
# Single instance only
|
await self.async_set_unique_id(DOMAIN)
|
||||||
if self._async_current_entries():
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_abort(reason="single_instance_allowed")
|
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is None:
|
||||||
token = (user_input.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
return self.async_show_form(step_id="user", data_schema=_schema(None))
|
||||||
data: dict[str, Any] = {}
|
|
||||||
options: dict[str, Any] = {}
|
|
||||||
if token:
|
|
||||||
options[CONF_GITHUB_TOKEN] = token
|
|
||||||
|
|
||||||
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(
|
return self.async_create_entry(
|
||||||
{
|
title="Bahmcloud Store",
|
||||||
vol.Optional(CONF_GITHUB_TOKEN, default=""): str,
|
data={},
|
||||||
}
|
options={CONF_GITHUB_TOKEN: token} if token else {},
|
||||||
)
|
|
||||||
|
|
||||||
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).",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@callback
|
||||||
def async_get_options_flow(config_entry: config_entries.ConfigEntry):
|
def async_get_options_flow(config_entry: config_entries.ConfigEntry):
|
||||||
return BCSOptionsFlowHandler(config_entry)
|
return BahmcloudStoreOptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
|
|
||||||
class BCSOptionsFlowHandler(config_entries.OptionsFlow):
|
class BahmcloudStoreOptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
"""Handle options for Bahmcloud Store."""
|
"""Options flow to manage optional GitHub token."""
|
||||||
|
|
||||||
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
|
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):
|
async def async_step_init(self, user_input: dict | None = None):
|
||||||
if user_input is not None:
|
if user_input is None:
|
||||||
token = (user_input.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
current = self._config_entry.options.get(CONF_GITHUB_TOKEN) or ""
|
||||||
opts: dict[str, Any] = dict(self.config_entry.options)
|
return self.async_show_form(step_id="init", data_schema=_schema(str(current)))
|
||||||
if token:
|
|
||||||
opts[CONF_GITHUB_TOKEN] = token
|
|
||||||
else:
|
|
||||||
opts.pop(CONF_GITHUB_TOKEN, None)
|
|
||||||
return self.async_create_entry(title="", data=opts)
|
|
||||||
|
|
||||||
cur = (self.config_entry.options.get(CONF_GITHUB_TOKEN) or "").strip()
|
token = str(user_input.get(CONF_GITHUB_TOKEN, "")).strip() or None
|
||||||
schema = vol.Schema({vol.Optional(CONF_GITHUB_TOKEN, default=cur): str})
|
options = dict(self._config_entry.options)
|
||||||
|
|
||||||
return self.async_show_form(
|
# Allow clearing the token.
|
||||||
step_id="init",
|
if token:
|
||||||
data_schema=schema,
|
options[CONF_GITHUB_TOKEN] = token
|
||||||
description_placeholders={
|
else:
|
||||||
"rate_limit": "Optional. Adds GitHub authorization to avoid rate limits.",
|
options.pop(CONF_GITHUB_TOKEN, None)
|
||||||
},
|
|
||||||
)
|
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 def process_one(r: RepoItem) -> None:
|
||||||
async with sem:
|
async with sem:
|
||||||
info: RepoInfo = await fetch_repo_info(
|
info: RepoInfo = await fetch_repo_info(self.hass, r.url, github_token=self.config.github_token)
|
||||||
self.hass,
|
|
||||||
r.url,
|
|
||||||
github_token=self.config.github_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
r.provider = info.provider or r.provider
|
r.provider = info.provider or r.provider
|
||||||
r.owner = info.owner or r.owner
|
r.owner = info.owner or r.owner
|
||||||
@@ -760,11 +756,7 @@ class BCSCore:
|
|||||||
|
|
||||||
async def _enrich_one_repo(self, r: RepoItem) -> None:
|
async def _enrich_one_repo(self, r: RepoItem) -> None:
|
||||||
"""Fetch provider info + metadata for a single repo item."""
|
"""Fetch provider info + metadata for a single repo item."""
|
||||||
info: RepoInfo = await fetch_repo_info(
|
info: RepoInfo = await fetch_repo_info(self.hass, r.url, github_token=self.config.github_token)
|
||||||
self.hass,
|
|
||||||
r.url,
|
|
||||||
github_token=self.config.github_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
r.provider = info.provider or r.provider
|
r.provider = info.provider or r.provider
|
||||||
r.owner = info.owner or r.owner
|
r.owner = info.owner or r.owner
|
||||||
@@ -816,7 +808,7 @@ class BCSCore:
|
|||||||
_LOGGER.debug("BCS ensure_repo_details failed for %s", repo_id, exc_info=True)
|
_LOGGER.debug("BCS ensure_repo_details failed for %s", repo_id, exc_info=True)
|
||||||
return r
|
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) -> list[dict[str, Any]]:
|
||||||
repo = self.get_repo(repo_id)
|
repo = self.get_repo(repo_id)
|
||||||
if not repo:
|
if not repo:
|
||||||
return []
|
return []
|
||||||
@@ -840,8 +832,8 @@ class BCSCore:
|
|||||||
repo.url,
|
repo.url,
|
||||||
provider=repo.provider,
|
provider=repo.provider,
|
||||||
default_branch=repo.default_branch,
|
default_branch=repo.default_branch,
|
||||||
github_token=self.config.github_token,
|
|
||||||
limit=limit,
|
limit=limit,
|
||||||
|
github_token=self.config.github_token,
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
versions = []
|
versions = []
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"domain": "bahmcloud_store",
|
"domain": "bahmcloud_store",
|
||||||
"name": "Bahmcloud Store",
|
"name": "Bahmcloud Store",
|
||||||
"version": "0.6.9",
|
"version": "0.7.0",
|
||||||
"documentation": "https://git.bahmcloud.de/bahmcloud/bahmcloud_store",
|
"documentation": "https://git.bahmcloud.de/bahmcloud/bahmcloud_store",
|
||||||
|
"config_flow": true,
|
||||||
"platforms": ["update"],
|
"platforms": ["update"],
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
"codeowners": ["@bahmcloud"],
|
"codeowners": ["@bahmcloud"],
|
||||||
|
|||||||
@@ -16,17 +16,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
UA = "BahmcloudStore (Home Assistant)"
|
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
|
@dataclass
|
||||||
class RepoInfo:
|
class RepoInfo:
|
||||||
owner: str | None = None
|
owner: str | None = None
|
||||||
@@ -331,6 +320,15 @@ async def _gitlab_latest_version(
|
|||||||
return None, None
|
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:
|
async def fetch_repo_info(hass: HomeAssistant, repo_url: str, *, github_token: str | None = None) -> RepoInfo:
|
||||||
provider = detect_provider(repo_url)
|
provider = detect_provider(repo_url)
|
||||||
owner, repo = _split_owner_repo(repo_url)
|
owner, repo = _split_owner_repo(repo_url)
|
||||||
@@ -557,6 +555,8 @@ async def fetch_repo_versions(
|
|||||||
|
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass)
|
||||||
headers = {"User-Agent": UA}
|
headers = {"User-Agent": UA}
|
||||||
|
if prov == "github":
|
||||||
|
headers = _github_headers(github_token)
|
||||||
|
|
||||||
out: list[dict[str, str]] = []
|
out: list[dict[str, str]] = []
|
||||||
seen: set[str] = set()
|
seen: set[str] = set()
|
||||||
@@ -576,7 +576,7 @@ async def fetch_repo_versions(
|
|||||||
try:
|
try:
|
||||||
if prov == "github":
|
if prov == "github":
|
||||||
# Releases
|
# Releases
|
||||||
gh_headers = _github_headers(github_token)
|
gh_headers = {"Accept": "application/vnd.github+json", "User-Agent": UA}
|
||||||
data, _ = await _safe_json(
|
data, _ = await _safe_json(
|
||||||
session,
|
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={int(limit)}",
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"abort": {
|
||||||
"single_instance_allowed": "Bahmcloud Store is already configured."
|
"single_instance_allowed": "Only one Bahmcloud Store instance can be configured."
|
||||||
},
|
},
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"title": "Set up Bahmcloud Store",
|
"title": "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.",
|
"description": "Bahmcloud Store uses a fixed official store index. You can optionally add a GitHub token to increase API rate limits.",
|
||||||
"data": {
|
"data": {
|
||||||
"github_token": "GitHub token (optional)"
|
"github_token": "GitHub token (optional)"
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
"options": {
|
"options": {
|
||||||
"step": {
|
"step": {
|
||||||
"init": {
|
"init": {
|
||||||
"title": "Bahmcloud Store options",
|
"title": "Bahmcloud Store Options",
|
||||||
"description": "Optional: Configure a GitHub token to increase API rate limits.",
|
"description": "Optionally set or clear your GitHub token to reduce rate limiting.",
|
||||||
"data": {
|
"data": {
|
||||||
"github_token": "GitHub token (optional)"
|
"github_token": "GitHub token (optional)"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,26 @@ from dataclasses import dataclass
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
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__)
|
_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:
|
def _pretty_repo_name(core: BCSCore, repo_id: str) -> str:
|
||||||
"""Return a human-friendly name for a repo update entity."""
|
"""Return a human-friendly name for a repo update entity."""
|
||||||
try:
|
try:
|
||||||
@@ -140,9 +149,14 @@ def _sync_entities(core: BCSCore, existing: dict[str, BCSRepoUpdateEntity], asyn
|
|||||||
ent.async_write_ha_state()
|
ent.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
async def _async_setup(hass: HomeAssistant, async_add_entities: AddEntitiesCallback) -> None:
|
async def async_setup_platform(
|
||||||
"""Common update entity setup for both config entries and legacy YAML."""
|
hass: HomeAssistant,
|
||||||
core: BCSCore | None = hass.data.get(DOMAIN)
|
config,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
discovery_info=None,
|
||||||
|
):
|
||||||
|
"""Set up BCS update entities."""
|
||||||
|
core: BCSCore | None = _get_core(hass)
|
||||||
if not core:
|
if not core:
|
||||||
_LOGGER.debug("BCS core not available, skipping update platform setup")
|
_LOGGER.debug("BCS core not available, skipping update platform setup")
|
||||||
return
|
return
|
||||||
@@ -160,18 +174,8 @@ async def _async_setup(hass: HomeAssistant, async_add_entities: AddEntitiesCallb
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up update entities from a config entry."""
|
"""Set up BCS update entities from a config entry."""
|
||||||
await _async_setup(hass, async_add_entities)
|
await async_setup_platform(hass, {}, async_add_entities, None)
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
Reference in New Issue
Block a user