From b71f6e8b7ef8d883cfb7d4b47770487567e6145a Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 4 Oct 2024 15:23:46 -0700 Subject: [PATCH] onvif: preset support --- plugins/onvif/package-lock.json | 4 +- plugins/onvif/package.json | 2 +- plugins/onvif/src/onvif-ptz.ts | 38 +++++++++++++++++-- .../scrypted_python/scrypted_sdk/types.py | 5 ++- sdk/types/src/types.input.ts | 8 +++- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/plugins/onvif/package-lock.json b/plugins/onvif/package-lock.json index 58c13c60cc..4a3b2bb907 100644 --- a/plugins/onvif/package-lock.json +++ b/plugins/onvif/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/onvif", - "version": "0.1.25", + "version": "0.1.27", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/onvif", - "version": "0.1.25", + "version": "0.1.27", "license": "Apache", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/onvif/package.json b/plugins/onvif/package.json index 0495b75599..6c884ecd32 100644 --- a/plugins/onvif/package.json +++ b/plugins/onvif/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/onvif", - "version": "0.1.25", + "version": "0.1.27", "description": "ONVIF Camera Plugin for Scrypted", "author": "Scrypted", "license": "Apache", diff --git a/plugins/onvif/src/onvif-ptz.ts b/plugins/onvif/src/onvif-ptz.ts index 51fe1ba7ae..af11b20a72 100644 --- a/plugins/onvif/src/onvif-ptz.ts +++ b/plugins/onvif/src/onvif-ptz.ts @@ -79,23 +79,53 @@ export class OnvifPtzMixin extends SettingsMixinDeviceBase implements if (e) return f(e); r(); - }) + }); }) } else if (movement === PanTiltZoomMovement.Continuous) { + let x= command.pan; + let y = command.tilt; + let zoom = command.zoom; + if (command.speed?.pan) + x *= command.speed.pan; + if (command.speed?.tilt) + y *= command.speed.tilt; + if (command.speed?.zoom) + zoom *= command.speed.zoom; return new Promise((r, f) => { client.cam.continuousMove({ x: command.pan, y: command.tilt, zoom: command.zoom, - speed: speed, timeout: command.timeout || 1000, }, (e, result, xml) => { if (e) return f(e); r(); }) - }) + }); + } + else if (movement === PanTiltZoomMovement.Home) { + return new Promise((r, f) => { + client.cam.gotoHomePosition({ + speed: speed, + }, (e, result, xml) => { + if (e) + return f(e); + r(); + }) + }); + } + else if (movement === PanTiltZoomMovement.Preset) { + return new Promise((r, f) => { + client.cam.gotoPreset({ + preset: command.preset, + }, (e, result, xml) => { + if (e) + return f(e); + r(); + }) + }); } else { // relative movement is default. @@ -110,7 +140,7 @@ export class OnvifPtzMixin extends SettingsMixinDeviceBase implements return f(e); r(); }) - }) + }); } } diff --git a/sdk/types/scrypted_python/scrypted_sdk/types.py b/sdk/types/scrypted_python/scrypted_sdk/types.py index 4e334bc44c..180242daed 100644 --- a/sdk/types/scrypted_python/scrypted_sdk/types.py +++ b/sdk/types/scrypted_python/scrypted_sdk/types.py @@ -65,6 +65,8 @@ class PanTiltZoomMovement(str, Enum): Absolute = "Absolute" Continuous = "Continuous" + Home = "Home" + Preset = "Preset" Relative = "Relative" class ScryptedDeviceType(str, Enum): @@ -709,8 +711,9 @@ class PanTiltZoomCapabilities(TypedDict): class PanTiltZoomCommand(TypedDict): - movement: PanTiltZoomMovement # Specify the movement origin. If unspecified, the movement will be relative to the current position. + movement: PanTiltZoomMovement # Specify the movement type. If unspecified, the movement will be relative to the current position. pan: float # Ranges between -1 and 1. + preset: str # The preset to move to. speed: Any # The speed of the movement. tilt: float # Ranges between -1 and 1. timeout: float # The duration of the movement in milliseconds. diff --git a/sdk/types/src/types.input.ts b/sdk/types/src/types.input.ts index d85481551c..760ec2e738 100644 --- a/sdk/types/src/types.input.ts +++ b/sdk/types/src/types.input.ts @@ -951,11 +951,13 @@ export enum PanTiltZoomMovement { Absolute = "Absolute", Relative = "Relative", Continuous = "Continuous", + Preset = "Preset", + Home = 'Home', } export interface PanTiltZoomCommand { /** - * Specify the movement origin. If unspecified, the movement will be relative to the current position. + * Specify the movement type. If unspecified, the movement will be relative to the current position. */ movement?: PanTiltZoomMovement; /** @@ -991,6 +993,10 @@ export interface PanTiltZoomCommand { * The duration of the movement in milliseconds. */ timeout?: number; + /** + * The preset to move to. + */ + preset?: string; } export interface PanTiltZoomCapabilities {