Skip to content

Commit

Permalink
onvif: initial ptz preset support
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Oct 5, 2024
1 parent f26b6c3 commit 511f348
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/client/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 packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"typescript": "^5.6.2"
},
"dependencies": {
"@scrypted/types": "^0.3.59",
"@scrypted/types": "^0.3.60",
"engine.io-client": "^6.6.1",
"follow-redirects": "^1.15.9",
"rimraf": "^6.0.1"
Expand Down
4 changes: 2 additions & 2 deletions plugins/onvif/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/onvif/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/onvif",
"version": "0.1.27",
"version": "0.1.28",
"description": "ONVIF Camera Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",
Expand Down
55 changes: 54 additions & 1 deletion plugins/onvif/src/onvif-ptz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class OnvifPtzMixin extends SettingsMixinDeviceBase<Settings> implements
],
onPut: (ov, ptz: string[]) => {
this.ptzCapabilities = {
...this.ptzCapabilities,
pan: ptz.includes('Pan'),
tilt: ptz.includes('Tilt'),
zoom: ptz.includes('Zoom'),
Expand All @@ -38,13 +39,65 @@ export class OnvifPtzMixin extends SettingsMixinDeviceBase<Settings> implements
],
defaultValue: 'Default',
},
presets: {
title: 'Presets',
description: 'PTZ Presets in the format "key=name". Where key is the PTZ Preset identifier and name is a friendly name.',
multiple: true,
defaultValue: [],
combobox: true,
onPut: async (ov, presets: string[]) => {
const caps = {
...this.ptzCapabilities,
presets: {},
};
for (const preset of presets) {
const [key, name] = preset.split('=');
caps.presets[key] = name;
}
this.ptzCapabilities = caps;
},
mapGet: () => {
const presets = this.ptzCapabilities?.presets || {};
return Object.entries(presets).map(([key, name]) => key + '=' + name);
},
},
cachedPresets: {
multiple: true,
hide: true,
json: true,
defaultValue: {},
},
});

constructor(options: SettingsMixinDeviceOptions<Settings>) {
super(options);

// force a read to set the state.
this.storageSettings.values.ptz;

this.refreshPresets();

this.storageSettings.settings.presets.onGet = async () => {
// getPresets is where the key is the name of the preset, and the value is the id.
// kind of weird and backwards.
const choices = Object.entries(this.storageSettings.values.cachedPresets).map(([name, key]) => key + '=' + name);
return {
choices,
};
};
}

async refreshPresets() {
const client = await this.getClient();
client.cam.getPresets({}, (e, result, xml) => {
if (e) {
this.console.error('failed to get presets', e);
}
else {
this.console.log('presets', result);
this.storageSettings.values.cachedPresets = result;
}
});
}

getMixinSettings(): Promise<Setting[]> {
Expand Down Expand Up @@ -83,7 +136,7 @@ export class OnvifPtzMixin extends SettingsMixinDeviceBase<Settings> implements
})
}
else if (movement === PanTiltZoomMovement.Continuous) {
let x= command.pan;
let x = command.pan;
let y = command.tilt;
let zoom = command.zoom;
if (command.speed?.pan)
Expand Down
4 changes: 2 additions & 2 deletions sdk/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 sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/sdk",
"version": "0.3.63",
"version": "0.3.65",
"description": "",
"main": "dist/src/index.js",
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions sdk/types/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 sdk/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/types",
"version": "0.3.59",
"version": "0.3.60",
"description": "",
"main": "dist/index.js",
"author": "",
Expand Down
1 change: 1 addition & 0 deletions sdk/types/scrypted_python/scrypted_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ class ObjectsDetected(TypedDict):
class PanTiltZoomCapabilities(TypedDict):

pan: bool
presets: Any # Preset id mapped to friendly name.
tilt: bool
zoom: bool

Expand Down
6 changes: 6 additions & 0 deletions sdk/types/src/types.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,12 @@ export interface PanTiltZoomCapabilities {
pan?: boolean;
tilt?: boolean;
zoom?: boolean;
/**
* Preset id mapped to friendly name.
*/
presets?: {
[key: string]: string;
};
}
export interface PanTiltZoom {
ptzCapabilities?: PanTiltZoomCapabilities;
Expand Down

0 comments on commit 511f348

Please sign in to comment.