feat(zigbee): import as background scan run

Mirrors IP scan flow: POST /zigbee/import-pending now creates a
ScanRun(kind=zigbee, status=running) and returns immediately.
Networkmap fetch + pending upsert run in the background, status
transitions to done/error when finished.

Frontend: import modal closes on submit, scan history shows the
run with a ZIG/IP kind chip and toasts on completion. Pending
modal auto-refreshes when run finishes.

scan_runs.kind column added (default 'ip', idempotent migration).
Existing zigbee tests refactored to exercise _persist_pending_import
directly (background tasks don't see the test session); route test
verifies the run is created with kind=zigbee.
This commit is contained in:
Pouzor
2026-05-10 00:45:21 +02:00
parent b17299f531
commit 0863c2db94
10 changed files with 143 additions and 160 deletions
+3 -19
View File
@@ -541,25 +541,9 @@ export default function App() {
open={zigbeeImportOpen}
onClose={() => setZigbeeImportOpen(false)}
onAddToCanvas={handleZigbeeAddToCanvas}
onPendingImported={(coordinator) => {
useCanvasStore.getState().notifyScanDeviceFound()
if (coordinator) {
const exists = useCanvasStore.getState().nodes.some((n) => n.id === coordinator.id)
if (!exists) {
addNode({
id: coordinator.id,
type: 'zigbee_coordinator',
position: { x: 600, y: 100 },
data: {
label: coordinator.label,
type: 'zigbee_coordinator' as NodeData['type'],
status: 'unknown' as const,
services: [],
},
})
markUnsaved()
}
}
onPendingImported={() => {
setSidebarForceView(undefined)
setTimeout(() => setSidebarForceView('history'), 0)
}}
/>
)}