alexa: motion events

This commit is contained in:
Koushik Dutta
2022-04-01 21:53:21 -07:00
parent 9cc8e9c323
commit 6ab0fb001d
3 changed files with 60 additions and 14 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/alexa",
"version": "0.0.3",
"version": "0.0.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/alexa",
"version": "0.0.3",
"version": "0.0.4",
"dependencies": {
"@types/node": "^16.6.1",
"alexa-smarthome-ts": "^0.0.1",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/alexa",
"version": "0.0.3",
"version": "0.0.4",
"scripts": {
"prepublishOnly": "NODE_ENV=production scrypted-webpack",
"prescrypted-vscode-launch": "scrypted-webpack",

View File

@@ -1,9 +1,11 @@
import sdk, { FFMpegInput, HttpResponse, RTCAVSignalingSetup, RTCSignalingChannel, RTCSignalingOptions, RTCSignalingSendIceCandidate, RTCSignalingSession, ScryptedDevice, ScryptedDeviceType, ScryptedInterface, ScryptedMimeTypes, VideoCamera } from "@scrypted/sdk";
import { addSupportedType, AlexaCapabilityHandler, capabilityHandlers } from "./common";
import sdk, { FFMpegInput, HttpResponse, MotionSensor, RTCAVSignalingSetup, RTCSignalingChannel, RTCSignalingOptions, RTCSignalingSendIceCandidate, RTCSignalingSession, ScryptedDevice, ScryptedDeviceType, ScryptedInterface, ScryptedMimeTypes, VideoCamera } from "@scrypted/sdk";
import { addSupportedType, AlexaCapabilityHandler, capabilityHandlers, EventReport } from "./common";
import { startRTCPeerConnectionFFmpegInput } from '@scrypted/common/src/ffmpeg-to-wrtc';
import { BrowserSignalingSession, startRTCSignalingSession } from '@scrypted/common/src/rtc-signaling';
import crypto from 'crypto';
import { createMessageId } from "../message";
import { Capability } from "alexa-smarthome-ts/lib/skill/Capability";
import { DiscoveryEndpoint } from "alexa-smarthome-ts";
const { mediaManager } = sdk;
@@ -12,22 +14,66 @@ addSupportedType(ScryptedDeviceType.Camera, {
if (!device.interfaces.includes(ScryptedInterface.VideoCamera))
return;
return {
displayCategories: ['CAMERA'],
capabilities: [
const capabilities: Capability<any>[] = [
{
"type": "AlexaInterface",
"interface": "Alexa.RTCSessionController",
"version": "3",
"configuration": {
"isFullDuplexAudioSupported": false,
}
} as any,
];
if (device.interfaces.includes(ScryptedInterface.MotionSensor)) {
capabilities.push(
{
"type": "AlexaInterface",
"interface": "Alexa.RTCSessionController",
"interface": "Alexa.MotionSensor",
"version": "3",
"configuration": {
"isFullDuplexAudioSupported": false,
"properties": {
"supported": [
{
"name": "detectionState"
}
],
"proactivelyReported": true,
"retrievable": true
}
},
],
)
}
return {
displayCategories: ['CAMERA'],
capabilities,
}
},
async reportState() {
return undefined;
async reportState(eventSource: ScryptedDevice & MotionSensor, eventDetails, eventData): Promise<EventReport> {
if (eventDetails.eventInterface !== ScryptedInterface.MotionSensor)
return undefined;
return {
type: 'event',
namespace: 'Alexa',
name: 'ChangeReport',
payload: {
change: {
cause: {
type: "PHYSICAL_INTERACTION"
},
properties: [
{
"namespace": "Alexa.MotionSensor",
"name": "detectionState",
"value": eventData ? "DETECTED" : "NOT_DETECTED",
"timeOfSample": new Date().toISOString(),
"uncertaintyInMilliseconds": 0
}
]
}
},
};
}
});