From c61d7fd698a8b19783d374f8847ccb4afda60345 Mon Sep 17 00:00:00 2001 From: Scarriffle Date: Wed, 29 Apr 2026 19:55:04 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20HA=20Delete=20=E2=80=93=20Fallback=20auf?= =?UTF-8?q?=20REST=20DELETE=20und=20klarere=20Fehlermeldung=20calendar.del?= =?UTF-8?q?ete=5Fevent=20schl=C3=A4gt=20mit=20400=20fehl,=20wenn=20die=20H?= =?UTF-8?q?A-Integration=20das=20Feature=20nicht=20unterst=C3=BCtzt=20(z.B?= =?UTF-8?q?.=20Google-Calendar=20via=20HA=20hat=20nur=20CREATE=5FEVENT,=20?= =?UTF-8?q?kein=20DELETE/UPDATE).=20-=20Versucht=20erst=20Service-Call,=20?= =?UTF-8?q?dann=20REST=20DELETE=20als=20Fallback=20-=20Bei=20400=20wird=20?= =?UTF-8?q?der=20User=20aufgekl=C3=A4rt,=20dass=20die=20Integration=20verm?= =?UTF-8?q?utlich=20=20=20kein=20L=C3=B6schen=20unterst=C3=BCtzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/routers/homeassistant_router.py | 29 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/backend/routers/homeassistant_router.py b/backend/routers/homeassistant_router.py index 868a0ca..35abd78 100644 --- a/backend/routers/homeassistant_router.py +++ b/backend/routers/homeassistant_router.py @@ -220,13 +220,28 @@ def _ha_delete_event(url: str, token: str, entity_id: str, uid: str): f"{base}/api/services/calendar/delete_event", headers=headers, json=body, timeout=15, verify=False, ) - if not resp.ok: - try: - detail = resp.json().get("message", resp.text[:500]) - except Exception: - detail = resp.text[:500] if resp.text else f"HTTP {resp.status_code}" - raise Exception(f"HA delete_event ({resp.status_code}): {detail}") - return resp + if resp.ok: + return resp + + # Try REST API DELETE as fallback (works for some integrations) + from urllib.parse import quote + encoded_uid = quote(uid, safe="") + rest_resp = http_requests.delete( + f"{base}/api/calendars/{entity_id}/{encoded_uid}", + headers={"Authorization": f"Bearer {token}"}, + timeout=15, verify=False, + ) + if rest_resp.ok: + return rest_resp + + # Both failed – build a helpful error message + try: + detail = resp.json().get("message", resp.text[:500]) + except Exception: + detail = resp.text[:500] if resp.text else f"HTTP {resp.status_code}" + if resp.status_code == 400: + detail = f"{detail} (Diese HA-Kalender-Integration unterstützt kein Löschen — z.B. Google-Calendar via HA ist read-only für Updates/Löschen)" + raise Exception(f"HA delete_event ({resp.status_code}): {detail}") def _parse_ha_event(ev: dict, cal_db_id: int, cal_name: str, cal_color: str) -> dict: