@apocaliss92/scrypted-reolink-native 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.nodejs.js +1 -1
- package/dist/plugin.zip +0 -0
- package/package.json +1 -1
- package/src/accessories/autotracking.ts +150 -0
- package/src/accessories/floodlight.ts +92 -0
- package/src/accessories/index.ts +7 -0
- package/src/accessories/motion-floodlight.ts +171 -0
- package/src/accessories/motion-siren.ts +165 -0
- package/src/accessories/pir-sensor.ts +138 -0
- package/src/accessories/siren.ts +63 -0
- package/src/camera.ts +166 -450
- package/src/multiFocal.ts +1 -3
- package/src/utils.ts +1 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OnOff,
|
|
3
|
+
ScryptedDeviceBase,
|
|
4
|
+
Setting,
|
|
5
|
+
Settings,
|
|
6
|
+
SettingValue,
|
|
7
|
+
} from "@scrypted/sdk";
|
|
8
|
+
import { StorageSettings } from "@scrypted/sdk/storage-settings";
|
|
9
|
+
import type { ReolinkCamera } from "../camera";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* PIR Sensor: controls PIR (Passive Infrared) motion detection sensor
|
|
13
|
+
* This accessory controls the PIR sensor on battery-powered cameras.
|
|
14
|
+
*/
|
|
15
|
+
export class ReolinkCameraPirSensor
|
|
16
|
+
extends ScryptedDeviceBase
|
|
17
|
+
implements OnOff, Settings
|
|
18
|
+
{
|
|
19
|
+
private get logger(): Console {
|
|
20
|
+
return this.camera.getBaichuanLogger();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
storageSettings = new StorageSettings(this, {
|
|
24
|
+
sensitive: {
|
|
25
|
+
title: "PIR Sensitivity",
|
|
26
|
+
description: "Detection sensitivity/threshold (higher = more sensitive)",
|
|
27
|
+
type: "number",
|
|
28
|
+
defaultValue: 50,
|
|
29
|
+
range: [0, 100],
|
|
30
|
+
},
|
|
31
|
+
reduceAlarm: {
|
|
32
|
+
title: "Reduce False Alarms",
|
|
33
|
+
description: "Enable reduction of false alarm rate",
|
|
34
|
+
type: "boolean",
|
|
35
|
+
defaultValue: false,
|
|
36
|
+
},
|
|
37
|
+
interval: {
|
|
38
|
+
title: "PIR Detection Interval",
|
|
39
|
+
description: "Detection interval in seconds",
|
|
40
|
+
type: "number",
|
|
41
|
+
defaultValue: 5,
|
|
42
|
+
range: [1, 60],
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
constructor(
|
|
47
|
+
public camera: ReolinkCamera,
|
|
48
|
+
nativeId: string,
|
|
49
|
+
) {
|
|
50
|
+
super(nativeId);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async getSettings(): Promise<Setting[]> {
|
|
54
|
+
const settings = await this.storageSettings.getSettings();
|
|
55
|
+
return settings;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async putSetting(key: string, value: SettingValue): Promise<void> {
|
|
59
|
+
await this.storageSettings.putSetting(key, value);
|
|
60
|
+
|
|
61
|
+
// Always apply settings to camera when changed
|
|
62
|
+
await this.applySettings();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async applySettings(): Promise<void> {
|
|
66
|
+
const channel = this.camera.storageSettings.values.rtspChannel;
|
|
67
|
+
const enabled = this.on ? 1 : 0;
|
|
68
|
+
const sensitive = this.storageSettings.values.sensitive;
|
|
69
|
+
const reduceAlarm = this.storageSettings.values.reduceAlarm ? 1 : 0;
|
|
70
|
+
const interval = this.storageSettings.values.interval;
|
|
71
|
+
|
|
72
|
+
this.logger.log(
|
|
73
|
+
`PIR sensor applySettings: sensitive=${sensitive}, reduceAlarm=${reduceAlarm}, interval=${interval}`,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await this.camera.withBaichuanRetry(async () => {
|
|
78
|
+
const api = await this.camera.ensureClient();
|
|
79
|
+
await api.setPirInfo(channel, {
|
|
80
|
+
enable: enabled,
|
|
81
|
+
sensitive: sensitive,
|
|
82
|
+
reduceAlarm: reduceAlarm,
|
|
83
|
+
interval: interval,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
this.logger.log(`PIR sensor applySettings: success`);
|
|
87
|
+
} catch (e: any) {
|
|
88
|
+
this.logger.error(
|
|
89
|
+
`PIR sensor applySettings: failed`,
|
|
90
|
+
e?.message || String(e),
|
|
91
|
+
);
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async turnOff(): Promise<void> {
|
|
97
|
+
this.logger.log(`PIR sensor toggle: turnOff (device=${this.nativeId})`);
|
|
98
|
+
this.on = false;
|
|
99
|
+
this.camera.auxDeviceCooldowns.pir = Date.now();
|
|
100
|
+
await this.updatePirSettings();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async turnOn(): Promise<void> {
|
|
104
|
+
this.logger.log(`PIR sensor toggle: turnOn (device=${this.nativeId})`);
|
|
105
|
+
this.on = true;
|
|
106
|
+
this.camera.auxDeviceCooldowns.pir = Date.now();
|
|
107
|
+
await this.updatePirSettings();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private async updatePirSettings(): Promise<void> {
|
|
111
|
+
const channel = this.camera.storageSettings.values.rtspChannel;
|
|
112
|
+
const enabled = this.on ? 1 : 0;
|
|
113
|
+
const sensitive = this.storageSettings.values.sensitive;
|
|
114
|
+
const reduceAlarm = this.storageSettings.values.reduceAlarm ? 1 : 0;
|
|
115
|
+
const interval = this.storageSettings.values.interval;
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
await this.camera.withBaichuanRetry(async () => {
|
|
119
|
+
const api = await this.camera.ensureClient();
|
|
120
|
+
await api.setPirInfo(channel, {
|
|
121
|
+
enable: enabled,
|
|
122
|
+
sensitive: sensitive,
|
|
123
|
+
reduceAlarm: reduceAlarm,
|
|
124
|
+
interval: interval,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
this.logger.log(
|
|
128
|
+
`PIR sensor toggle: ${enabled ? "turnOn" : "turnOff"} ok (device=${this.nativeId})`,
|
|
129
|
+
);
|
|
130
|
+
} catch (e: any) {
|
|
131
|
+
this.logger.error(
|
|
132
|
+
`PIR sensor toggle: failed (device=${this.nativeId})`,
|
|
133
|
+
e?.message || String(e),
|
|
134
|
+
);
|
|
135
|
+
throw e;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { OnOff, ScryptedDeviceBase } from "@scrypted/sdk";
|
|
2
|
+
import type { ReolinkCamera } from "../camera";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Siren: direct control (not motion-based)
|
|
6
|
+
* This accessory directly controls the siren on/off state.
|
|
7
|
+
*/
|
|
8
|
+
export class ReolinkCameraSiren extends ScryptedDeviceBase implements OnOff {
|
|
9
|
+
private get logger(): Console {
|
|
10
|
+
return this.camera.getBaichuanLogger();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
public camera: ReolinkCamera,
|
|
15
|
+
nativeId: string,
|
|
16
|
+
) {
|
|
17
|
+
super(nativeId);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async turnOff(): Promise<void> {
|
|
21
|
+
this.logger.log(`Siren toggle: turnOff (device=${this.nativeId})`);
|
|
22
|
+
this.on = false;
|
|
23
|
+
this.camera.auxDeviceCooldowns.siren = Date.now();
|
|
24
|
+
try {
|
|
25
|
+
const channel = this.camera.storageSettings.values.rtspChannel;
|
|
26
|
+
await this.camera.withBaichuanRetry(async () => {
|
|
27
|
+
const api = await this.camera.ensureClient();
|
|
28
|
+
await api.setSiren(channel, false);
|
|
29
|
+
const sirenState = await api.getSiren(channel);
|
|
30
|
+
this.on = sirenState.enabled;
|
|
31
|
+
});
|
|
32
|
+
this.logger.log(`Siren toggle: turnOff ok (device=${this.nativeId})`);
|
|
33
|
+
} catch (e: any) {
|
|
34
|
+
this.logger.error(
|
|
35
|
+
`Siren toggle: turnOff failed (device=${this.nativeId})`,
|
|
36
|
+
e?.message || String(e),
|
|
37
|
+
);
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async turnOn(): Promise<void> {
|
|
43
|
+
this.logger.log(`Siren toggle: turnOn (device=${this.nativeId})`);
|
|
44
|
+
this.on = true;
|
|
45
|
+
this.camera.auxDeviceCooldowns.siren = Date.now();
|
|
46
|
+
try {
|
|
47
|
+
const channel = this.camera.storageSettings.values.rtspChannel;
|
|
48
|
+
await this.camera.withBaichuanRetry(async () => {
|
|
49
|
+
const api = await this.camera.ensureClient();
|
|
50
|
+
await api.setSiren(channel, true);
|
|
51
|
+
const sirenState = await api.getSiren(channel);
|
|
52
|
+
this.on = sirenState.enabled;
|
|
53
|
+
});
|
|
54
|
+
this.logger.log(`Siren toggle: turnOn ok (device=${this.nativeId})`);
|
|
55
|
+
} catch (e: any) {
|
|
56
|
+
this.logger.error(
|
|
57
|
+
`Siren toggle: turnOn failed (device=${this.nativeId})`,
|
|
58
|
+
e?.message || String(e),
|
|
59
|
+
);
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|