core: Fix notificaiton automation

This commit is contained in:
Koushik Dutta
2024-07-31 21:06:22 -07:00
parent 3ae6079615
commit de44217f65
3 changed files with 22 additions and 5 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/core",
"version": "0.3.61",
"version": "0.3.62",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/core",
"version": "0.3.61",
"version": "0.3.62",
"license": "Apache-2.0",
"dependencies": {
"@scrypted/common": "file:../../common",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/core",
"version": "0.3.61",
"version": "0.3.62",
"description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.",
"author": "Scrypted",
"license": "Apache-2.0",

View File

@@ -1,5 +1,6 @@
import { Brightness, Lock, LockState, Notifier, OnOff, Program, ScryptedDevice, ScryptedInterface, StartStop } from "@scrypted/sdk";
import { Brightness, Camera, Lock, LockState, Notifier, OnOff, Program, ScryptedDevice, ScryptedInterface, StartStop, VideoCamera } from "@scrypted/sdk";
import { StorageSettingsDict } from "@scrypted/sdk/storage-settings";
import sdk from '@scrypted/sdk';
interface InvokeStorage<T extends string> {
settings: StorageSettingsDict<T>;
@@ -81,7 +82,23 @@ addAction(ScryptedInterface.Notifier, {
deviceFilter: `deviceInterface === '${ScryptedInterface.VideoCamera}' || deviceInterface === '${ScryptedInterface.Camera}'`,
},
}, async function invoke(device: ScryptedDevice & Notifier, storageSettings) {
let { notificationMediaUrl } = storageSettings;
if (notificationMediaUrl && !notificationMediaUrl?.includes('://')) {
const [id,iface] = notificationMediaUrl.split('#');
if (iface === ScryptedInterface.Camera) {
const mediaDevice = sdk.systemManager.getDeviceById<Camera>(id);
notificationMediaUrl = await mediaDevice.takePicture({
reason: 'event',
});
}
else {
const mediaDevice = sdk.systemManager.getDeviceById<VideoCamera>(id);
notificationMediaUrl = mediaDevice.getVideoStream();
}
}
return device.sendNotification(storageSettings.notificationTitle as string, {
body: storageSettings.notificationBody as string,
});
}, notificationMediaUrl);
});