From ce4bd4f4f1d05663ca42a6ade6c743555ed70231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bachmann?= Date: Thu, 15 Jan 2026 13:05:07 +0000 Subject: [PATCH] custom_components/bahmcloud_store/views.py aktualisiert --- custom_components/bahmcloud_store/views.py | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/custom_components/bahmcloud_store/views.py b/custom_components/bahmcloud_store/views.py index 7fc79bf..fecd2f9 100644 --- a/custom_components/bahmcloud_store/views.py +++ b/custom_components/bahmcloud_store/views.py @@ -17,13 +17,11 @@ _LOGGER = logging.getLogger(__name__) def _render_markdown_server_side(md: str) -> str | None: - """Render Markdown -> sanitized HTML (server-side).""" text = (md or "").strip() if not text: return None html: str | None = None - try: import markdown as mdlib # type: ignore @@ -181,6 +179,39 @@ class BCSApiView(HomeAssistantView): return web.json_response({"ok": False, "message": "Unknown operation"}, status=400) +class BCSRefreshView(HomeAssistantView): + """ + Manual refresh endpoint to reload store.yaml/bcs.yaml immediately. + This avoids waiting for the auto-refresh interval. + """ + url = "/api/bcs/refresh" + name = "api:bcs_refresh" + requires_auth = True + + def __init__(self, core: Any) -> None: + self.core = core + + async def post(self, request: web.Request) -> web.Response: + try: + # We intentionally call a dedicated core method if present. + # Fallbacks are used to keep compatibility with older core versions. + if hasattr(self.core, "async_refresh_now"): + await self.core.async_refresh_now() + elif hasattr(self.core, "refresh_now"): + await self.core.hass.async_add_executor_job(self.core.refresh_now) + elif hasattr(self.core, "load_index"): + await self.core.hass.async_add_executor_job(self.core.load_index) + else: + _LOGGER.warning("No refresh method found on core; returning current cached data.") + except Exception as e: + _LOGGER.exception("Manual refresh failed: %s", e) + return web.json_response({"ok": False, "message": f"Refresh failed: {e}"}, status=500) + + return web.json_response( + {"ok": True, "repos": self.core.list_repos_public()} + ) + + class BCSCustomRepoView(HomeAssistantView): url = "/api/bcs/custom_repo" name = "api:bcs_custom_repo" @@ -231,10 +262,7 @@ class BCSReadmeView(HomeAssistantView): if not md or not md.strip(): return web.json_response( - { - "ok": False, - "message": "README not found (raw endpoint returned 404).", - }, + {"ok": False, "message": "README not found (raw endpoint returned 404)."}, status=404, )