From ea54684e304a17b981df9a282572de13fb965a60 Mon Sep 17 00:00:00 2001 From: Luke Hoersten Date: Sun, 14 Jun 2026 19:31:21 -0500 Subject: scrypted: re-discover children at start so their storage rehydrates on script reload --- scrypted/scrypted-viewport.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'scrypted') diff --git a/scrypted/scrypted-viewport.ts b/scrypted/scrypted-viewport.ts index e29100a..fd846ae 100644 --- a/scrypted/scrypted-viewport.ts +++ b/scrypted/scrypted-viewport.ts @@ -221,11 +221,23 @@ class ScryptedViewportProvider extends ScryptedDeviceBase this.scryptedBase = raw.replace(/\/$/, ""); this.console.log(`Scrypted Viewport up. Callback URL base: ${this.scryptedBase}`); - // Eagerly instantiate every known child so its registration + camera - // event subscription happen at plugin load (rather than waiting for - // some other part of Scrypted to touch the child). + // Re-discover every known child so Scrypted reattaches its storage + // to the nativeId. Without this, `new Viewport(...)` instantiates + // with `this.storage === undefined` and every storage-backed getter + // (host / cameraId / orientation / ...) throws on script reload. + // Then eagerly instantiate so each child's registration + camera + // event subscription happen at plugin load. for (const nativeId of this.childIds) { - try { await this.getDevice(nativeId); } + try { + await deviceManager.onDeviceDiscovered({ + providerNativeId: this.nativeId, + nativeId, + name: nativeId, // overridden by Scrypted from its existing record + type: ScryptedDeviceType.Sensor, + interfaces: [ScryptedInterface.Settings], + }); + await this.getDevice(nativeId); + } catch (e) { this.console.warn(`load child ${nativeId} failed:`, (e as Error).message); } } -- cgit v1.2.3