From bcfbf7151c8afca7da5216a3465e80c1b933d1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bachmann?= Date: Thu, 15 Jan 2026 16:04:59 +0000 Subject: [PATCH] custom_components/bahmcloud_store/views.py aktualisiert --- custom_components/bahmcloud_store/views.py | 43 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/custom_components/bahmcloud_store/views.py b/custom_components/bahmcloud_store/views.py index fdb1b70..bfb323b 100644 --- a/custom_components/bahmcloud_store/views.py +++ b/custom_components/bahmcloud_store/views.py @@ -161,7 +161,6 @@ def _extract_text_recursive(obj: Any, depth: int = 0) -> str | None: # content may already be plain text if isinstance(content, str) and (not isinstance(encoding, str) or not encoding.strip()): - # Heuristic: treat as markdown if it has typical markdown chars, otherwise still return return content # 2) direct text keys (readme/markdown/text/body/data) @@ -247,7 +246,7 @@ class BCSApiView(HomeAssistantView): requires_auth = True def __init__(self, core: Any) -> None: - self.core = core + self.core: BCSCore = core async def get(self, request: web.Request) -> web.Response: return web.json_response( @@ -255,7 +254,40 @@ class BCSApiView(HomeAssistantView): ) async def post(self, request: web.Request) -> web.Response: - data = await request.json() + """ + Supported operations: + + 1) Full refresh: + POST /api/bcs?action=refresh + + 2) JSON operations (body based): + { + "op": "add_custom_repo", + "url": "...", + "name": "..." + } + """ + + # --- Phase B: Manual full refresh trigger --- + action = request.query.get("action") + if action == "refresh": + _LOGGER.info("BCS manual refresh triggered via API") + try: + await self.core.refresh() + self.core.signal_updated() + return web.json_response({"ok": True}) + except Exception as e: + _LOGGER.error("BCS manual refresh failed: %s", e) + return web.json_response( + {"ok": False, "message": "Refresh failed"}, status=500 + ) + + # --- Existing JSON based operations --- + try: + data = await request.json() + except Exception: + data = {} + op = data.get("op") if op == "add_custom_repo": @@ -276,7 +308,7 @@ class BCSCustomRepoView(HomeAssistantView): requires_auth = True def __init__(self, core: Any) -> None: - self.core = core + self.core: BCSCore = core async def delete(self, request: web.Request) -> web.Response: repo_id = request.query.get("id") @@ -292,7 +324,7 @@ class BCSReadmeView(HomeAssistantView): requires_auth = True def __init__(self, core: Any) -> None: - self.core = core + self.core: BCSCore = core async def get(self, request: web.Request) -> web.Response: repo_id = request.query.get("repo_id") @@ -309,7 +341,6 @@ class BCSReadmeView(HomeAssistantView): status=404, ) - # Ensure strict JSON string output (avoid accidental objects) md_str = str(md) html = _render_markdown_server_side(md_str)