fix: create missing devices during peer sync

- bulk_update_devices now creates devices if they don't exist locally
  but have useful metadata (floor, label, or favorite status)
- Sync trigger endpoint now reports both pulled and pushed device counts
- Enables full bidirectional sync of device metadata between peers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
User
2026-02-01 04:15:36 +01:00
parent 6a3e3e8448
commit 827830b043
2 changed files with 23 additions and 6 deletions

View File

@@ -1025,9 +1025,24 @@ class DeviceDatabase:
if cursor.rowcount > 0:
updated_count += 1
else:
# Device doesn't exist locally - we can only sync metadata for
# devices we've seen, so skip unknown devices
pass
# Device doesn't exist locally - create it if it has useful metadata
if dev.get("assigned_floor") is not None or dev.get("custom_label") or dev.get("is_favorite"):
device_type = dev.get("device_type", "bluetooth")
name = dev.get("name") or dev.get("ssid") or device_id
now = datetime.now().isoformat()
cursor.execute("""
INSERT INTO devices (device_id, device_type, name, ssid, manufacturer,
custom_label, assigned_floor, is_favorite, notes,
first_seen, last_seen, total_observations, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?)
""", (
device_id, device_type, name, dev.get("ssid"), dev.get("manufacturer"),
dev.get("custom_label"), dev.get("assigned_floor"),
1 if dev.get("is_favorite") else 0, dev.get("notes"),
now, now, dev.get("updated_at", now)
))
updated_count += 1
conn.commit()
return updated_count