From 194fcd5fa2eaabb3378b9b0e7f138765c084c0e2 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Tue, 28 Jun 2022 16:39:16 -0700 Subject: [PATCH] sdk: add event reporting, report sdk version --- sdk/gen/build.ts | 5 +++- sdk/gen/types.input.ts | 19 +++++++++++++ sdk/index.js | 6 ++++ sdk/index.ts | 10 +++++-- sdk/scrypted_python/scrypted_sdk/types.py | 27 ++++++++++++++++++ sdk/types/index.d.ts | 17 +++++++++++ sdk/types/index.js | 11 +++++++- sdk/types/index.ts | 28 +++++++++++++++++++ .../scrypted_python/scrypted_sdk/types.py | 27 ++++++++++++++++++ 9 files changed, 146 insertions(+), 4 deletions(-) diff --git a/sdk/gen/build.ts b/sdk/gen/build.ts index 94baa5cb8..9261a89bd 100644 --- a/sdk/gen/build.ts +++ b/sdk/gen/build.ts @@ -1,9 +1,10 @@ import stringifyObject from 'stringify-object'; import { ScryptedInterface, ScryptedInterfaceDescriptor } from "./types.input"; import path from 'path'; -import fs, { mkdir } from "fs"; +import fs from "fs"; const schema = JSON.parse(fs.readFileSync(path.join(__dirname, '../schema.json')).toString()); +const typesVersion = JSON.parse(fs.readFileSync(path.join(__dirname, '../types/package.json')).toString()).version; const ScryptedInterfaceDescriptors: { [scryptedInterface: string]: ScryptedInterfaceDescriptor } = {}; const allProperties: { [property: string]: any } = {}; @@ -48,6 +49,8 @@ ${properties.map(property => ' ' + property + ' = \"' + property + '",\n').join `; const contents = ` +export const TYPES_VERSION = "${typesVersion}"; + ${deviceStateContents} ${propertyContents} diff --git a/sdk/gen/types.input.ts b/sdk/gen/types.input.ts index 1b5464583..e87820868 100644 --- a/sdk/gen/types.input.ts +++ b/sdk/gen/types.input.ts @@ -522,6 +522,24 @@ export interface VideoRecorder { getRecordingStreamThumbnail(time: number): Promise; } +export interface RecordedEvent { + id: string; + details: EventDetails; + data: any; +} + +export interface RecordedEventOptions { + startTime?: number; + endTime?: number; + startId?: string; + count?: number; + reverseOrder?: boolean; +} + +export interface EventRecorder { + getRecordedEvents(options: RecordedEventOptions): Promise; +} + export interface VideoClip { id: string; startTime: number; @@ -1426,6 +1444,7 @@ export enum ScryptedInterface { Display = "Display", VideoCamera = "VideoCamera", VideoRecorder = "VideoRecorder", + EventRecorder = "EventRecorder", VideoClips = "VideoClips", VideoCameraConfiguration = "VideoCameraConfiguration", Intercom = "Intercom", diff --git a/sdk/index.js b/sdk/index.js index a47b8c655..4f7e8efec 100644 --- a/sdk/index.js +++ b/sdk/index.js @@ -9,6 +9,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; +var _a, _b, _c; Object.defineProperty(exports, "__esModule", { value: true }); exports.MixinDeviceBase = exports.ScryptedDeviceBase = void 0; __exportStar(require("./types/index"), exports); @@ -153,6 +154,11 @@ try { systemManager, pluginHostAPI, }); + try { + (_c = (_b = (_a = systemManager).setScryptedInterfaceDescriptors) === null || _b === void 0 ? void 0 : _b.call(_a, index_1.TYPES_VERSION, index_1.ScryptedInterfaceDescriptors)) === null || _c === void 0 ? void 0 : _c.catch(() => { }); + } + catch (e) { + } } catch (e) { console.error('sdk initialization error, import @scrypted/types or use @scrypted/web-sdk instead', e); diff --git a/sdk/index.ts b/sdk/index.ts index 1499076a9..c3ee4af19 100644 --- a/sdk/index.ts +++ b/sdk/index.ts @@ -1,5 +1,5 @@ export * from './types/index' -import { ScryptedInterfaceProperty, DeviceBase, MediaObject } from './types/index'; +import { ScryptedInterfaceProperty, DeviceBase, MediaObject, ScryptedInterfaceDescriptors, TYPES_VERSION } from './types/index'; import type { ScryptedNativeId, DeviceManager, SystemManager, MediaManager, EndpointManager, EventListenerRegister } from './types/index'; import type { ScryptedInterface, ScryptedStatic, Logger, DeviceState } from './types/index'; @@ -191,7 +191,13 @@ try { mediaManager, systemManager, pluginHostAPI, - }); + });  + + try { + (systemManager as any).setScryptedInterfaceDescriptors?.(TYPES_VERSION, ScryptedInterfaceDescriptors)?.catch(() => {}); + } + catch (e) { + } } catch (e) { console.error('sdk initialization error, import @scrypted/types or use @scrypted/web-sdk instead', e); diff --git a/sdk/scrypted_python/scrypted_sdk/types.py b/sdk/scrypted_python/scrypted_sdk/types.py index 083462ac0..a61d4a52f 100644 --- a/sdk/scrypted_python/scrypted_sdk/types.py +++ b/sdk/scrypted_python/scrypted_sdk/types.py @@ -91,6 +91,7 @@ class ScryptedInterface(Enum): EngineIOHandler = "EngineIOHandler" Entry = "Entry" EntrySensor = "EntrySensor" + EventRecorder = "EventRecorder" Fan = "Fan" FloodSensor = "FloodSensor" HttpRequestHandler = "HttpRequestHandler" @@ -419,6 +420,20 @@ class RTCSessionControl(TypedDict): class RTCSignalingSession(TypedDict): pass +class RecordedEvent(TypedDict): + data: Any + details: EventDetails + id: str + pass + +class RecordedEventOptions(TypedDict): + count: float + endTime: float + reverseOrder: bool + startId: str + startTime: float + pass + class RequestMediaStreamOptions(TypedDict): audio: AudioStreamOptions container: str @@ -662,6 +677,11 @@ class EntrySensor: entryOpen: bool pass +class EventRecorder: + async def getRecordedEvents(self, options: RecordedEventOptions) -> list[RecordedEvent]: + pass + pass + class Fan: fan: FanStatus async def setFan(self, fan: FanState) -> None: @@ -1737,6 +1757,13 @@ ScryptedInterfaceDescriptors = { ], "properties": [] }, + "EventRecorder": { + "name": "EventRecorder", + "methods": [ + "getRecordedEvents" + ], + "properties": [] + }, "VideoClips": { "name": "VideoClips", "methods": [ diff --git a/sdk/types/index.d.ts b/sdk/types/index.d.ts index 900b861ee..b11edf376 100644 --- a/sdk/types/index.d.ts +++ b/sdk/types/index.d.ts @@ -1,4 +1,5 @@ /// +export declare const TYPES_VERSION = "0.0.47"; export interface DeviceState { id?: string; info?: DeviceInformation; @@ -650,6 +651,21 @@ export interface VideoRecorder { getRecordingStreamOptions(): Promise; getRecordingStreamThumbnail(time: number): Promise; } +export interface RecordedEvent { + id: string; + details: EventDetails; + data: any; +} +export interface RecordedEventOptions { + startTime?: number; + endTime?: number; + startId?: string; + count?: number; + reverseOrder?: boolean; +} +export interface EventRecorder { + getRecordedEvents(options: RecordedEventOptions): Promise; +} export interface VideoClip { id: string; startTime: number; @@ -1466,6 +1482,7 @@ export declare enum ScryptedInterface { Display = "Display", VideoCamera = "VideoCamera", VideoRecorder = "VideoRecorder", + EventRecorder = "EventRecorder", VideoClips = "VideoClips", VideoCameraConfiguration = "VideoCameraConfiguration", Intercom = "Intercom", diff --git a/sdk/types/index.js b/sdk/types/index.js index 8b2c518c3..d52994f25 100644 --- a/sdk/types/index.js +++ b/sdk/types/index.js @@ -1,6 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.ScryptedMimeTypes = exports.ScryptedInterface = exports.MediaPlayerState = exports.SecuritySystemObstruction = exports.SecuritySystemMode = exports.AirQuality = exports.LockState = exports.ThermostatMode = exports.TemperatureUnit = exports.FanMode = exports.HumidityMode = exports.ScryptedDeviceType = exports.ScryptedInterfaceDescriptors = exports.ScryptedInterfaceProperty = exports.DeviceBase = void 0; +exports.ScryptedMimeTypes = exports.ScryptedInterface = exports.MediaPlayerState = exports.SecuritySystemObstruction = exports.SecuritySystemMode = exports.AirQuality = exports.LockState = exports.ThermostatMode = exports.TemperatureUnit = exports.FanMode = exports.HumidityMode = exports.ScryptedDeviceType = exports.ScryptedInterfaceDescriptors = exports.ScryptedInterfaceProperty = exports.DeviceBase = exports.TYPES_VERSION = void 0; +exports.TYPES_VERSION = "0.0.47"; class DeviceBase { } exports.DeviceBase = DeviceBase; @@ -253,6 +254,13 @@ exports.ScryptedInterfaceDescriptors = { ], properties: [] }, + EventRecorder: { + name: 'EventRecorder', + methods: [ + 'getRecordedEvents' + ], + properties: [] + }, VideoClips: { name: 'VideoClips', methods: [ @@ -766,6 +774,7 @@ var ScryptedInterface; ScryptedInterface["Display"] = "Display"; ScryptedInterface["VideoCamera"] = "VideoCamera"; ScryptedInterface["VideoRecorder"] = "VideoRecorder"; + ScryptedInterface["EventRecorder"] = "EventRecorder"; ScryptedInterface["VideoClips"] = "VideoClips"; ScryptedInterface["VideoCameraConfiguration"] = "VideoCameraConfiguration"; ScryptedInterface["Intercom"] = "Intercom"; diff --git a/sdk/types/index.ts b/sdk/types/index.ts index ffc9ecf74..5865b75a5 100644 --- a/sdk/types/index.ts +++ b/sdk/types/index.ts @@ -1,4 +1,6 @@ +export const TYPES_VERSION = "0.0.47"; + export interface DeviceState { id?: string @@ -368,6 +370,13 @@ export const ScryptedInterfaceDescriptors: { [scryptedInterface: string]: Scrypt ], properties: [] }, + EventRecorder: { + name: 'EventRecorder', + methods: [ + 'getRecordedEvents' + ], + properties: [] + }, VideoClips: { name: 'VideoClips', methods: [ @@ -1276,6 +1285,24 @@ export interface VideoRecorder { getRecordingStreamThumbnail(time: number): Promise; } +export interface RecordedEvent { + id: string; + details: EventDetails; + data: any; +} + +export interface RecordedEventOptions { + startTime?: number; + endTime?: number; + startId?: string; + count?: number; + reverseOrder?: boolean; +} + +export interface EventRecorder { + getRecordedEvents(options: RecordedEventOptions): Promise; +} + export interface VideoClip { id: string; startTime: number; @@ -2180,6 +2207,7 @@ export enum ScryptedInterface { Display = "Display", VideoCamera = "VideoCamera", VideoRecorder = "VideoRecorder", + EventRecorder = "EventRecorder", VideoClips = "VideoClips", VideoCameraConfiguration = "VideoCameraConfiguration", Intercom = "Intercom", diff --git a/sdk/types/scrypted_python/scrypted_sdk/types.py b/sdk/types/scrypted_python/scrypted_sdk/types.py index 083462ac0..a61d4a52f 100644 --- a/sdk/types/scrypted_python/scrypted_sdk/types.py +++ b/sdk/types/scrypted_python/scrypted_sdk/types.py @@ -91,6 +91,7 @@ class ScryptedInterface(Enum): EngineIOHandler = "EngineIOHandler" Entry = "Entry" EntrySensor = "EntrySensor" + EventRecorder = "EventRecorder" Fan = "Fan" FloodSensor = "FloodSensor" HttpRequestHandler = "HttpRequestHandler" @@ -419,6 +420,20 @@ class RTCSessionControl(TypedDict): class RTCSignalingSession(TypedDict): pass +class RecordedEvent(TypedDict): + data: Any + details: EventDetails + id: str + pass + +class RecordedEventOptions(TypedDict): + count: float + endTime: float + reverseOrder: bool + startId: str + startTime: float + pass + class RequestMediaStreamOptions(TypedDict): audio: AudioStreamOptions container: str @@ -662,6 +677,11 @@ class EntrySensor: entryOpen: bool pass +class EventRecorder: + async def getRecordedEvents(self, options: RecordedEventOptions) -> list[RecordedEvent]: + pass + pass + class Fan: fan: FanStatus async def setFan(self, fan: FanState) -> None: @@ -1737,6 +1757,13 @@ ScryptedInterfaceDescriptors = { ], "properties": [] }, + "EventRecorder": { + "name": "EventRecorder", + "methods": [ + "getRecordedEvents" + ], + "properties": [] + }, "VideoClips": { "name": "VideoClips", "methods": [