fix: HA Update-Fallback auf delete+create wenn Integration nicht unterstützt
HA's Google-Calendar-Integration unterstützt kein calendar/event/update und gibt 'not_supported: Calendar does not support event update' zurück. In dem Fall wird jetzt automatisch der Termin gelöscht und neu erstellt (beide Operationen werden von der Integration unterstützt). Der Termin bekommt dabei eine neue UID, aber für den User sieht es wie ein Update aus.
This commit is contained in:
@@ -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),
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user