Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote: allow doorbells and filter out irrelevant plugins #588

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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