Skip to content

Commit

Permalink
core: Fix notificaiton automation
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Aug 1, 2024
1 parent 3ae6079 commit de44217
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions plugins/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 19 additions & 2 deletions plugins/core/src/automation-actions.ts
Original file line number Diff line number Diff line change
@@ -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>;
Expand Down Expand Up @@ -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);
});

0 comments on commit de44217

Please sign in to comment.