From 23a18b0a20371179a3396043436571ff6b0bbfa4 Mon Sep 17 00:00:00 2001 From: Guido Schmit Date: Tue, 5 May 2026 18:19:00 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20HA=20Update-Fallback=20auf=20delete+crea?= =?UTF-8?q?te=20wenn=20Integration=20nicht=20unterst=C3=BCtzt=20HA's=20Goo?= =?UTF-8?q?gle-Calendar-Integration=20unterst=C3=BCtzt=20kein=20calendar/e?= =?UTF-8?q?vent/update=20und=20gibt=20'not=5Fsupported:=20Calendar=20does?= =?UTF-8?q?=20not=20support=20event=20update'=20zur=C3=BCck.=20In=20dem=20?= =?UTF-8?q?Fall=20wird=20jetzt=20automatisch=20der=20Termin=20gel=C3=B6sch?= =?UTF-8?q?t=20und=20neu=20erstellt=20(beide=20Operationen=20werden=20von?= =?UTF-8?q?=20der=20Integration=20unterst=C3=BCtzt).=20Der=20Termin=20beko?= =?UTF-8?q?mmt=20dabei=20eine=20neue=20UID,=20aber=20f=C3=BCr=20den=20User?= =?UTF-8?q?=20sieht=20es=20wie=20ein=20Update=20aus.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/routers/homeassistant_router.py | 31 ++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/backend/routers/homeassistant_router.py b/backend/routers/homeassistant_router.py index b9b3f89..36447d8 100644 --- a/backend/routers/homeassistant_router.py +++ b/backend/routers/homeassistant_router.py @@ -249,11 +249,36 @@ def _ha_create_event(url: str, token: str, entity_id: str, data: dict) -> dict: def _ha_update_event(url: str, token: str, entity_id: str, uid: str, data: dict): - """Update an event via WebSocket command (the only reliable path).""" + """Update an event. Tries calendar/event/update first; if the integration + doesn't support update (e.g. Google Calendar via HA), falls back to + delete+create so the user still sees their changes.""" + try: + return _ha_ws_call(url, token, { + "type": "calendar/event/update", + "entity_id": entity_id, + "uid": uid, + "event": _ha_ws_event_payload(data), + }) + except Exception as exc: + msg = str(exc).lower() + if "not_supported" not in msg and "does not support" not in msg: + raise + logger.info("HA update not supported for %s, falling back to delete+create", entity_id) + + # Fallback: delete the old event, then create a new one + try: + _ha_ws_call(url, token, { + "type": "calendar/event/delete", + "entity_id": entity_id, + "uid": uid, + }) + except Exception as exc: + logger.warning("HA delete during update fallback failed: %s", exc) + # Continue anyway — try the create + return _ha_ws_call(url, token, { - "type": "calendar/event/update", + "type": "calendar/event/create", "entity_id": entity_id, - "uid": uid, "event": _ha_ws_event_payload(data), })