From 6c8949f20f11bf5619dd09bdb6a9e23e7e1db3fd Mon Sep 17 00:00:00 2001 From: Eric FELIXINE Date: Mon, 4 May 2026 23:03:02 -0400 Subject: [PATCH] Fix publish_orion: PATCH sends attrs only (not id/type/@context) - PATCH /entities/{eid}/attrs now sends only attributes - This allows updating entities with new fields (source, mqttTopic) --- simulator.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/simulator.py b/simulator.py index 1fea8648..a1191f08 100644 --- a/simulator.py +++ b/simulator.py @@ -519,7 +519,7 @@ def publish_orion(sid: str, sensor: dict) -> bool: try: body = json.dumps(entity).encode() req = urllib.request.Request(f"{base}/entities", data=body, - headers={"Content-Type": "application/ld+json", "Accept": "application/ld+json"}, method="POST") + headers={"Content-Type": "application/ld+json", "Accept": "application/ld+json"}, method="POST") with urllib.request.urlopen(req, timeout=8) as resp: print(f" 🌐 Orion-LD: ✅ (HTTP {resp.status} created)") return True @@ -527,17 +527,19 @@ def publish_orion(sid: str, sensor: dict) -> bool: if e.code != 409: print(f" ⚠️ Orion-LD → {e.code}: {e.read().decode()[:200]}") return False - # 2. Déjà existant (409) → PATCH sur les attributs + # 2. Déjà existant (409) → PATCH sur les attributs (sans id/type/@context) try: + # PATCH ne doit contenir que les attributs (pas id/type/@context) + attrs = {k: v for k, v in entity.items() if k not in ("id", "type", "@context")} eid = urllib.parse.quote(entity['id'], safe='') patch_url = f"{base}/entities/{eid}/attrs" - req2 = urllib.request.Request(patch_url, data=body, + req2 = urllib.request.Request(patch_url, data=json.dumps(attrs).encode(), headers={"Content-Type": "application/ld+json", "Accept": "application/ld+json"}, method="PATCH") with urllib.request.urlopen(req2, timeout=8) as resp2: print(f" 🌐 Orion-LD: ✅ (HTTP {resp2.status} updated)") return True except Exception as e2: - print(f" ⚠️ Orion-LD → update failed: {e2}") + print(f" ⚠️ Orion-LD PATCH failed: {e2}") return False except Exception as e: print(f" ⚠️ Orion-LD → {e}")