Skip to content

Commit

Permalink
Merge branch 'main' of github.com:koush/scrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Feb 26, 2023
2 parents 68a9ec0 + f8a5484 commit 9307bbd
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions plugins/remote/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
// only permit the following device types through
const allowedTypes = [
ScryptedDeviceType.Camera,
ScryptedDeviceType.Doorbell,
ScryptedDeviceType.DeviceProvider,
ScryptedDeviceType.API,
]
if (!allowedTypes.includes(device.type)) {
return null;
}

// only permit the following interfaces through
// only permit the following functional interfaces through
const allowedInterfaces = [
ScryptedInterface.Readme,
ScryptedInterface.VideoCamera,
ScryptedInterface.Camera,
ScryptedInterface.RTCSignalingChannel,
Expand All @@ -69,8 +69,19 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
if (intersection.length == 0) {
return null;
}
device.interfaces = intersection;

// explicitly drop plugins if all they do is provide devices
if (device.interfaces.includes(ScryptedInterface.ScryptedPlugin) && intersection.length == 1 && intersection[0] == ScryptedInterface.DeviceProvider) {
return null;
}

// some extra interfaces that are nice to expose, but not needed
const nonessentialInterfaces = [
ScryptedInterface.Readme,
];
const nonessentialIntersection = nonessentialInterfaces.filter(i => device.interfaces.includes(i));

device.interfaces = intersection.concat(nonessentialIntersection);
return device;
}

Expand Down Expand Up @@ -175,6 +186,7 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
return
}

// construct initial (flat) list of devices from the remote server
const state = this.client.systemManager.getSystemState();
const devices = <Device[]>[];
for (const id in state) {
Expand All @@ -201,6 +213,15 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
devices.push(device)
}

// it may be that a parent device was filtered out, so reparent these child devices to
// the top level
devices.map(device => {
if (!this.devices.has(device.providerNativeId)) {
device.providerNativeId = this.nativeId;
}
});

// group devices by parent provider id
const providerDeviceMap = new Map<string, Device[]>();
devices.map(device => {
// group devices by parent provider id
Expand All @@ -211,8 +232,10 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
}
})

// first register the top level devices, then register the remaining
// devices by provider id
await deviceManager.onDevicesChanged(<DeviceManifest>{
devices: providerDeviceMap.get(this.nativeId), // first register the top level devices
devices: providerDeviceMap.get(this.nativeId),
providerNativeId: this.nativeId,
});
for (let [providerNativeId, devices] of providerDeviceMap) {
Expand All @@ -222,6 +245,7 @@ class ScryptedRemoteInstance extends ScryptedDeviceBase implements DeviceProvide
});
}

// setup relevant proxies and monkeypatches for all devices
devices.map(device => this.setupProxies(device, this.devices.get(device.nativeId)));
this.console.log(`Discovered ${devices.length} devices`);
}
Expand Down

0 comments on commit 9307bbd

Please sign in to comment.