iobroker.tapo 0.4.8 → 0.5.0

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.
Files changed (41) hide show
  1. package/README.md +273 -0
  2. package/build/lib/utils/camera/onvifCamera.js +66 -87
  3. package/build/lib/utils/camera/onvifCamera.js.map +1 -7
  4. package/build/lib/utils/camera/tapoCamera.js +998 -615
  5. package/build/lib/utils/camera/tapoCamera.js.map +1 -7
  6. package/build/lib/utils/camera/types/onvif.js +2 -16
  7. package/build/lib/utils/camera/types/onvif.js.map +1 -7
  8. package/build/lib/utils/camera/types/tapo.js +2 -16
  9. package/build/lib/utils/camera/types/tapo.js.map +1 -7
  10. package/build/lib/utils/energyUsage.js +5 -27
  11. package/build/lib/utils/energyUsage.js.map +1 -7
  12. package/build/lib/utils/l510e.js +47 -57
  13. package/build/lib/utils/l510e.js.map +1 -7
  14. package/build/lib/utils/l520e.js +62 -72
  15. package/build/lib/utils/l520e.js.map +1 -7
  16. package/build/lib/utils/l530.js +123 -127
  17. package/build/lib/utils/l530.js.map +1 -7
  18. package/build/lib/utils/newTpLinkCipher.js +78 -90
  19. package/build/lib/utils/newTpLinkCipher.js.map +1 -7
  20. package/build/lib/utils/p100.js +1078 -672
  21. package/build/lib/utils/p100.js.map +1 -7
  22. package/build/lib/utils/p110.js +62 -75
  23. package/build/lib/utils/p110.js.map +1 -7
  24. package/build/lib/utils/powerUsage.js +7 -27
  25. package/build/lib/utils/powerUsage.js.map +1 -7
  26. package/build/lib/utils/tpLinkCipher.js +31 -53
  27. package/build/lib/utils/tpLinkCipher.js.map +1 -7
  28. package/build/lib/utils/tpapCipher.js +716 -0
  29. package/build/lib/utils/tpapCipher.js.map +1 -0
  30. package/build/lib/utils/tplinkAccessory.js +2 -16
  31. package/build/lib/utils/tplinkAccessory.js.map +1 -7
  32. package/build/lib/utils/types.js +2 -16
  33. package/build/lib/utils/types.js.map +1 -7
  34. package/build/lib/utils/usage.js +7 -27
  35. package/build/lib/utils/usage.js.map +1 -7
  36. package/build/main.js +1005 -728
  37. package/build/main.js.map +1 -7
  38. package/img/tpcamera01.jpeg +0 -0
  39. package/img/tpcamera02.jpeg +0 -0
  40. package/io-package.json +14 -1
  41. package/package.json +29 -35
package/README.md CHANGED
@@ -23,10 +23,270 @@ https://github.com/apatsufas/homebridge-tapo-p100
23
23
  Die Tapo Mail und Passwort eingeben. Es werden die Geräte via Cloud abgerufen, aber lokal gesteuert.
24
24
  Wenn die IP nicht gefunden wird muss sie manuell unter tapo.0.id.ip gesetzt werden.
25
25
 
26
+ ## Status-Werte (eingehend)
27
+
28
+ Alle Geraete werden regelmaessig gepollt. Die Werte werden automatisch unter `tapo.0.id.*` angelegt.
29
+
30
+ ### Alle Geraete
31
+
32
+ | Wert | Typ | Beschreibung |
33
+ | --- | --- | --- |
34
+ | nickname | string | Geraetename |
35
+ | device_id | string | Geraete-ID |
36
+ | model | string | Modellbezeichnung |
37
+ | fw_ver | string | Firmware-Version |
38
+ | hw_ver | string | Hardware-Version |
39
+ | mac | string | MAC-Adresse |
40
+ | device_on | boolean | Geraet ein/aus |
41
+ | on_time | number | Einschaltdauer in Sekunden |
42
+ | rssi | number | WLAN-Signalstaerke |
43
+ | signal_level | number | Signalstaerke (1-3) |
44
+ | ssid | string | WLAN-Name |
45
+ | ip | string | IP-Adresse |
46
+ | overheated | boolean | Ueberhitzungsstatus |
47
+
48
+ ### Lampen (zusaetzlich)
49
+
50
+ | Wert | Typ | Beschreibung |
51
+ | --- | --- | --- |
52
+ | brightness | number | Helligkeit (0-100) |
53
+ | color_temp | number | Farbtemperatur in Kelvin |
54
+ | hue | number | Farbton (0-360, nur L530/L630) |
55
+ | saturation | number | Saettigung (0-100, nur L530/L630) |
56
+
57
+ ### P110/P115 Energiedaten (zusaetzlich)
58
+
59
+ | Wert | Typ | Beschreibung |
60
+ | --- | --- | --- |
61
+ | current_power | number | Aktuelle Leistung (mW) |
62
+ | today_energy | number | Energieverbrauch heute (Wh) |
63
+ | month_energy | number | Energieverbrauch Monat (Wh) |
64
+ | voltage_mv | number | Spannung (mV) |
65
+ | current_ma | number | Strom (mA) |
66
+ | power_mw | number | Leistung (mW) |
67
+ | current (consumption) | number | Aktuelle Leistung (W, berechnet) |
68
+ | total (consumption) | number | Energie heute (kWh, berechnet) |
69
+
70
+ ### Hub-Sensoren (Child Devices)
71
+
72
+ | Sensor | Werte | Beschreibung |
73
+ | --- | --- | --- |
74
+ | T100 (Bewegung) | detected | Bewegung erkannt |
75
+ | T110 (Kontakt) | open | Tuer/Fenster offen |
76
+ | T300 (Wasserleck) | water_leak_status, in_alarm | Wasserleck-Status |
77
+ | T310/T315 (Temp/Feuchte) | current_temp, current_humidity, temp_unit | Temperatur und Luftfeuchtigkeit |
78
+ | KE100 (Thermostat) | target_temp, current_temp, frost_protection_on, trv_states | Thermostat-Status |
79
+
80
+ Alle Sensoren liefern zusaetzlich `battery_percentage`, `at_low_battery` und `signal_level`.
81
+
82
+ ### Kamera-Status
83
+
84
+ | Wert | Typ | Beschreibung |
85
+ | --- | --- | --- |
86
+ | alarm | boolean | Alarm aktiv |
87
+ | eyes | boolean | Privacy-Modus (invertiert: true = Kamera sieht) |
88
+ | notifications | boolean | Push-Benachrichtigungen aktiv |
89
+ | motionDetection | boolean | Bewegungserkennung aktiv |
90
+ | led | boolean | LED aktiv |
91
+ | autoTrack | boolean | Auto-Tracking aktiv |
92
+ | personDetection | boolean | Personenerkennung aktiv |
93
+ | vehicleDetection | boolean | Fahrzeugerkennung aktiv |
94
+ | petDetection | boolean | Tiererkennung aktiv |
95
+ | babyCryDetection | boolean | Baby-Schrei-Erkennung aktiv |
96
+ | barkDetection | boolean | Bellen-Erkennung aktiv |
97
+ | meowDetection | boolean | Miauen-Erkennung aktiv |
98
+ | glassBreakDetection | boolean | Glasbruch-Erkennung aktiv |
99
+ | tamperDetection | boolean | Manipulations-Erkennung aktiv |
100
+ | imageFlip | boolean | Bild vertikal gespiegelt |
101
+ | ldc | boolean | Linsenverzerrungskorrektur aktiv |
102
+ | recordAudio | boolean | Audio-Aufnahme aktiv |
103
+ | autoUpgrade | boolean | Firmware Auto-Update aktiv |
104
+
105
+ Nicht jedes Geraet liefert alle Werte. Felder die das Geraet nicht unterstuetzt werden nicht angelegt.
106
+
107
+ ### Kamera-Erkennungsereignisse
108
+
109
+ Die Kamera wird lokal gepollt und liefert Erkennungs-Events (Bewegung, Personen, etc.). Die letzten 10 Events werden abgerufen (`searchDetectionList`), neuestes Event zuerst.
110
+
111
+ | Wert | Typ | Beschreibung |
112
+ | --- | --- | --- |
113
+ | detection.active | boolean | true wenn Erkennung in den letzten 30 Sekunden |
114
+ | detection.eventCount | number | Anzahl Ereignisse in den letzten 10 Minuten |
115
+ | detection.events.0.start_time | number | Unix-Timestamp Start des neuesten Events |
116
+ | detection.events.0.end_time | number | Unix-Timestamp Ende des neuesten Events |
117
+ | detection.events.0.alarm_type | number | Erkennungstyp (siehe Tabelle unten) |
118
+ | detection.events.1.start_time | number | Zweitneuestes Event (usw. bis 9) |
119
+ | motionEvent | boolean | ONVIF Echtzeit-Bewegungserkennung |
120
+
121
+ #### alarm_type Werte
122
+
123
+ | ID | Beschreibung |
124
+ | --- | --- |
125
+ | 2 | Bewegung (motion) |
126
+ | 3 | Manipulation (tamper) |
127
+ | 4 | Linienueberquerung (line crossing) |
128
+ | 5 | Bereichsintrusion (area intrusion) |
129
+ | 6 | Person (human) |
130
+ | 7 | Baby-Schrei (baby cry) |
131
+ | 8 | Fahrzeug (vehicle) |
132
+ | 9 | Tier (pet) |
133
+ | 11 | Bellen (bark) |
134
+ | 12 | Miauen (meow) |
135
+ | 13 | Glasbruch (glass break) |
136
+ | 14 | Rauch (smoke) |
137
+ | 15 | Paket abgelegt (package delivery) |
138
+ | 16 | Paket abgeholt (package pick-up) |
139
+ | 20 | Gesichtserkennung (face detection) |
140
+ | 32 | Herumlungern (loitering) |
141
+
142
+ Nicht jede Kamera liefert alle Typen. Die verfuegbaren Werte haengen von Modell und Firmware ab.
143
+
144
+ ### Alarm-Konfiguration
145
+
146
+ | Wert | Typ | Beschreibung |
147
+ | --- | --- | --- |
148
+ | alarmInfo.enabled | string | Alarm aktiv (on/off) |
149
+ | alarmInfo.alarm_mode | mixed | Alarm-Modus (z.B. sound, light) |
150
+ | alarmInfo.alarm_volume | string | Lautstaerke |
151
+ | alarmInfo.alarm_duration | string | Dauer in Sekunden |
152
+ | alarmInfo.alarm_type | string | Sirenen-Typ |
153
+ | alarmInfo.light_type | string | Licht-Typ |
154
+ | alarmInfo.light_alarm_enabled | string | Licht-Alarm aktiv (on/off) |
155
+ | alarmInfo.sound_alarm_enabled | string | Sound-Alarm aktiv (on/off) |
156
+
157
+ ### Alarm-Event-Typen (welche Erkennungen loesen Alarm aus)
158
+
159
+ | Wert | Typ | Beschreibung |
160
+ | --- | --- | --- |
161
+ | alertEventTypes.motion | boolean | Alarm bei Bewegung |
162
+ | alertEventTypes.person | boolean | Alarm bei Person |
163
+ | alertEventTypes.vehicle | boolean | Alarm bei Fahrzeug |
164
+ | alertEventTypes.pet | boolean | Alarm bei Tier |
165
+
166
+ ### Benachrichtigungen einrichten
167
+
168
+ Fuer Benachrichtigungen bei Erkennung ein ioBroker-Skript auf `detection.events.0.start_time` triggern:
169
+
170
+ ```javascript
171
+ on({ id: 'tapo.0.DEVICE_ID.detection.events.0.start_time', change: 'ne' }, (obj) => {
172
+ sendTo('telegram.0', {
173
+ text: 'Erkennung um ' + new Date(obj.state.val * 1000).toLocaleString()
174
+ });
175
+ });
176
+ ```
177
+
178
+ Das Polling-Intervall ist in den Adaptereinstellungen konfigurierbar (Standard: 10 Sekunden). Alles lokal, kein Cloud-Zugriff noetig.
179
+
26
180
  ## Steuern
27
181
 
28
182
  tapo.0.id.remote auf true/false setzen steuert den jeweiligen Befehl. Der Befehl wird lokal an das Gerät gesendet.
29
183
 
184
+ ### Plugs / Switches (P100, P110, P115, ...)
185
+
186
+ | Remote | Typ | Beschreibung |
187
+ | --- | --- | --- |
188
+ | refresh | boolean | Manueller Status-Refresh |
189
+ | setPowerState | boolean | Ein/Aus |
190
+ | setPowerStateChild | string | Child-Device steuern: `childId,true` oder `childId,false` |
191
+ | setLedEnabled | boolean | LED Indikator ein/aus |
192
+ | setAutoOff | boolean | Auto-Off Timer ein/aus |
193
+ | setAutoOffDelay | number | Auto-Off Verzoegerung in Minuten |
194
+ | setChildProtection | boolean | Tastensperre (Button Lock) ein/aus |
195
+ | setPowerProtection | boolean | Ueberlastschutz ein/aus |
196
+ | setPowerProtectionThreshold | number | Ueberlast-Schwellwert in Watt |
197
+ | setAutoUpdate | boolean | Firmware Auto-Update ein/aus |
198
+
199
+ P110/P115 liefern zusaetzlich Energiedaten (Leistung, Spannung, Strom).
200
+
201
+ ### Lampen (L510E, L520E, L530, L630, L900, L920, ...)
202
+
203
+ Alle Plug-Remotes plus:
204
+
205
+ | Remote | Typ | Beschreibung |
206
+ | --- | --- | --- |
207
+ | setBrightness | number | Helligkeit setzen |
208
+ | setColorTemp | number | Farbtemperatur (2500-6500K) |
209
+ | setColor | string | Farbe setzen: `hue, saturation` |
210
+ | setLightEffect | string | Lichteffekt ID oder `off` |
211
+ | setGradualOnOff | boolean | Sanftes Ein-/Ausschalten |
212
+
213
+ ### Fans (F1xx)
214
+
215
+ | Remote | Typ | Beschreibung |
216
+ | --- | --- | --- |
217
+ | setFanSpeedLevel | number | Geschwindigkeit 0-4 (0 = aus) |
218
+ | setFanSleepMode | boolean | Schlafmodus ein/aus |
219
+
220
+ ### Hub (H100, H200)
221
+
222
+ | Remote | Typ | Beschreibung |
223
+ | --- | --- | --- |
224
+ | playAlarm | boolean | Alarm abspielen |
225
+ | stopAlarm | boolean | Alarm stoppen |
226
+ | setAlarmVolume | string | Alarm Lautstaerke: mute/low/normal/high |
227
+ | setAlarmDuration | number | Alarm Dauer in Sekunden |
228
+
229
+ ### Thermostat / TRV (KE100)
230
+
231
+ | Remote | Typ | Beschreibung |
232
+ | --- | --- | --- |
233
+ | setTargetTemperature | number | Zieltemperatur setzen |
234
+ | setTemperatureOffset | number | Temperatur-Offset (-10 bis 10) |
235
+ | setFrostProtection | boolean | Frostschutz ein/aus |
236
+
237
+ ### Hub-Sensoren (T100, T110, T300, T310, T315)
238
+
239
+ Sensordaten (Temperatur, Luftfeuchtigkeit, Bewegung, Kontakt, Wasserleck) werden automatisch via `getChildDeviceList` abgerufen und als Status angezeigt.
240
+
241
+ ### Kameras (C200, C310, C520, TC70, ...)
242
+
243
+ | Remote | Typ | Beschreibung |
244
+ | --- | --- | --- |
245
+ | refresh | boolean | Manueller Status-Refresh |
246
+ | setAlertConfig | boolean | Alarm ein/aus |
247
+ | setLensMaskConfig | boolean | Privacy (Eyes) ein/aus |
248
+ | setForceWhitelampState | boolean | Weisslicht ein/aus |
249
+ | setLedStatus | boolean | LED ein/aus |
250
+ | setMsgPushConfig | boolean | Benachrichtigungen ein/aus |
251
+ | setDetectionConfig | boolean | Bewegungserkennung ein/aus |
252
+ | setAutoTrackTarget | boolean | Auto-Tracking ein/aus |
253
+ | setPersonDetection | boolean | Personenerkennung ein/aus |
254
+ | setVehicleDetection | boolean | Fahrzeugerkennung ein/aus |
255
+ | setPetDetection | boolean | Tiererkennung ein/aus |
256
+ | setBabyCryDetection | boolean | Baby-Schrei-Erkennung ein/aus |
257
+ | setBarkDetection | boolean | Bellen-Erkennung ein/aus |
258
+ | setMeowDetection | boolean | Miauen-Erkennung ein/aus |
259
+ | setGlassBreakDetection | boolean | Glasbruch-Erkennung ein/aus |
260
+ | setTamperDetection | boolean | Manipulations-Erkennung ein/aus |
261
+ | setImageFlipVertical | boolean | Bild vertikal spiegeln |
262
+ | setLensDistortionCorrection | boolean | Linsenverzerrungskorrektur ein/aus |
263
+ | setRecordAudio | boolean | Audio aufnehmen ein/aus |
264
+ | setAutoUpgrade | boolean | Firmware Auto-Update ein/aus |
265
+ | setHDR | boolean | HDR ein/aus |
266
+ | setCoverConfig | boolean | Privacy Zones ein/aus |
267
+ | setRecordPlan | boolean | SD-Karten Aufnahme ein/aus |
268
+ | moveMotor | string | Kamera bewegen: `x, y` (-360..360, -45..45) |
269
+ | moveMotorStep | string | Schrittwinkel (0-360) |
270
+ | moveToPreset | string | Zu Preset fahren (ID) |
271
+ | calibrateMotor | boolean | Motor kalibrieren |
272
+ | savePreset | string | Preset speichern (Name) |
273
+ | deletePreset | string | Preset loeschen (ID) |
274
+ | setCruise | string | Patrol: x/y/off |
275
+ | startManualAlarm | boolean | Manuellen Alarm starten |
276
+ | stopManualAlarm | boolean | Manuellen Alarm stoppen |
277
+ | setAlarmMode | string | Alarm-Modus: both/light/sound/off |
278
+ | setDayNightMode | string | Tag/Nacht-Modus: auto/on/off |
279
+ | setLightFrequencyMode | string | Lichtfrequenz: auto/50/60 |
280
+ | setSpeakerVolume | number | Lautsprecher-Lautstaerke (0-100) |
281
+ | setMicrophoneVolume | number | Mikrofon-Lautstaerke (0-100) |
282
+ | setMotionDetectionSensitivity | string | Bewegungs-Sensitivitaet: high/normal/low |
283
+ | setPersonDetectionSensitivity | string | Personen-Sensitivitaet: high/normal/low |
284
+ | setOsd | string | OSD Beschriftungstext |
285
+ | reboot | boolean | Kamera neustarten |
286
+ | formatSdCard | boolean | SD-Karte formatieren |
287
+
288
+ Nicht jede Kamera unterstuetzt alle Funktionen. Nicht unterstuetzte Befehle werden mit einer Fehlermeldung im Log quittiert.
289
+
30
290
  ## Kamerasteuerung aktivieren
31
291
 
32
292
  ![alt text](./img/tpcamera01.jpeg "TP Labor")
@@ -37,6 +297,19 @@ tapo.0.id.remote auf true/false setzen steuert den jeweiligen Befehl. Der Befehl
37
297
  <https://forum.iobroker.net/topic/57336/test-adapter-tp-link-tapo/>
38
298
 
39
299
  ## Changelog
300
+ ### 0.5.0 (2026-04-02)
301
+
302
+ - Support for TPAP/SPAKE2+ protocol (P100 FW 1.4.3+ and newer devices)
303
+ - Support for KLAP v1 (md5) handshake
304
+ - Fix camera connection for firmware 1.9.1+ (C310 etc.)
305
+ - 30+ new camera remotes (detection, motor, alarm, cruise, presets, image/audio, OSD)
306
+ - New data points for camera status and detection events
307
+ - New remotes for plugs, lamps, fans, hubs and thermostats
308
+ - Device-specific remotes (only relevant controls per device type)
309
+ - Energy data (voltage, current) for P110/P115
310
+ - Automatic reconnect for devices that go offline and come back
311
+ - Less log spam for unreachable devices
312
+
40
313
  ### 0.4.8 (2025-02-04)
41
314
 
42
315
  - disable sentry to prevent crashes
@@ -1,92 +1,71 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var onvifCamera_exports = {};
20
- __export(onvifCamera_exports, {
21
- OnvifCamera: () => OnvifCamera
22
- });
23
- module.exports = __toCommonJS(onvifCamera_exports);
24
- var import_onvif2 = require("onvif");
25
- var import_stream = require("stream");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OnvifCamera = void 0;
4
+ // @ts-ignore
5
+ const onvif_1 = require("onvif");
6
+ const stream_1 = require("stream");
26
7
  class OnvifCamera {
27
- constructor(config) {
28
- this.config = config;
29
- this.kOnvifPort = 2020;
30
- }
31
- async getDevice() {
32
- return new Promise((resolve, reject) => {
33
- if (this.device) {
34
- return resolve(this.device);
35
- }
36
- const device = new import_onvif2.Cam(
37
- {
38
- hostname: this.config.ipAddress,
39
- username: this.config.streamUser,
40
- password: this.config.streamPassword,
41
- port: this.kOnvifPort
42
- },
43
- (err) => {
44
- if (err) {
45
- return reject(err);
46
- }
47
- this.device = device;
48
- return resolve(this.device);
49
- }
50
- );
51
- });
52
- }
53
- async getEventEmitter() {
54
- if (this.events) {
55
- return this.events;
8
+ log;
9
+ config;
10
+ events;
11
+ device;
12
+ kOnvifPort = 2020;
13
+ constructor(log, config) {
14
+ this.log = log;
15
+ this.config = config;
16
+ }
17
+ async getDevice() {
18
+ return new Promise((resolve, reject) => {
19
+ if (this.device) {
20
+ return resolve(this.device);
21
+ }
22
+ const device = new onvif_1.Cam({
23
+ hostname: this.config.ipAddress,
24
+ username: this.config.streamUser,
25
+ password: this.config.streamPassword,
26
+ port: this.kOnvifPort,
27
+ }, (err) => {
28
+ if (err) {
29
+ return reject(err);
30
+ }
31
+ this.device = device;
32
+ return resolve(this.device);
33
+ });
34
+ });
56
35
  }
57
- const onvifDevice = await this.getDevice();
58
- let lastMotionValue = false;
59
- this.events = new import_stream.EventEmitter();
60
- onvifDevice.on("event", (event) => {
61
- var _a, _b;
62
- if ((_b = (_a = event == null ? void 0 : event.topic) == null ? void 0 : _a._) == null ? void 0 : _b.match(/RuleEngine\/CellMotionDetector\/Motion$/)) {
63
- const motion = event.message.message.data.simpleItem.$.Value;
64
- if (motion !== lastMotionValue) {
65
- lastMotionValue = Boolean(motion);
66
- this.events = this.events || new import_stream.EventEmitter();
67
- this.events.emit("motion", motion);
36
+ async getEventEmitter() {
37
+ if (this.events) {
38
+ return this.events;
68
39
  }
69
- }
70
- });
71
- return this.events;
72
- }
73
- async getVideoSource() {
74
- const onvifDevice = await this.getDevice();
75
- return onvifDevice.videoSources[0];
76
- }
77
- async getDeviceInfo() {
78
- const onvifDevice = await this.getDevice();
79
- return new Promise((resolve, reject) => {
80
- onvifDevice.getDeviceInformation((err, deviceInformation) => {
81
- if (err)
82
- return reject(err);
83
- resolve(deviceInformation);
84
- });
85
- });
86
- }
40
+ const onvifDevice = await this.getDevice();
41
+ let lastMotionValue = false;
42
+ this.events = new stream_1.EventEmitter();
43
+ onvifDevice.on('event', (event) => {
44
+ if (event?.topic?._?.match(/RuleEngine\/CellMotionDetector\/Motion$/)) {
45
+ const motion = event.message.message.data.simpleItem.$.Value;
46
+ if (motion !== lastMotionValue) {
47
+ lastMotionValue = Boolean(motion);
48
+ this.events = this.events || new stream_1.EventEmitter();
49
+ this.events.emit('motion', motion);
50
+ }
51
+ }
52
+ });
53
+ return this.events;
54
+ }
55
+ async getVideoSource() {
56
+ const onvifDevice = await this.getDevice();
57
+ return onvifDevice.videoSources[0];
58
+ }
59
+ async getDeviceInfo() {
60
+ const onvifDevice = await this.getDevice();
61
+ return new Promise((resolve, reject) => {
62
+ onvifDevice.getDeviceInformation((err, deviceInformation) => {
63
+ if (err)
64
+ return reject(err);
65
+ resolve(deviceInformation);
66
+ });
67
+ });
68
+ }
87
69
  }
88
- // Annotate the CommonJS export names for ESM import in node:
89
- 0 && (module.exports = {
90
- OnvifCamera
91
- });
92
- //# sourceMappingURL=onvifCamera.js.map
70
+ exports.OnvifCamera = OnvifCamera;
71
+ //# sourceMappingURL=onvifCamera.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/lib/utils/camera/onvifCamera.ts"],
4
- "sourcesContent": ["import { DeviceInformation, VideoSource, NotificationMessage, Cam as ICam } from \"./types/onvif\";\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { Cam } from \"onvif\";\nimport { EventEmitter } from \"stream\";\ntype CameraConfig = {\n name: string;\n ipAddress: string;\n username: string;\n password: string;\n streamUser: string;\n streamPassword: string;\n\n pullInterval?: number;\n disableStreaming?: boolean;\n disablePrivacyAccessory?: boolean;\n disableAlarmAccessory?: boolean;\n disableMotionAccessory?: boolean;\n lowQuality?: boolean;\n\n videoConfig?: VideoConfig;\n\n privacyAccessoryName?: string;\n alarmAccessoryName?: string;\n};\nexport class OnvifCamera {\n private events: EventEmitter | undefined;\n private device: Cam | undefined;\n\n private readonly kOnvifPort = 2020;\n\n constructor(protected readonly config: CameraConfig) {}\n\n private async getDevice(): Promise<ICam> {\n return new Promise((resolve, reject) => {\n if (this.device) {\n return resolve(this.device);\n }\n\n const device: ICam = new Cam(\n {\n hostname: this.config.ipAddress,\n username: this.config.streamUser,\n password: this.config.streamPassword,\n port: this.kOnvifPort,\n },\n (err: Error) => {\n if (err) {\n return reject(err);\n }\n this.device = device;\n return resolve(this.device);\n },\n );\n });\n }\n\n async getEventEmitter() {\n if (this.events) {\n return this.events;\n }\n\n const onvifDevice = await this.getDevice();\n\n let lastMotionValue = false;\n\n this.events = new EventEmitter();\n\n onvifDevice.on(\"event\", (event: NotificationMessage) => {\n if (event?.topic?._?.match(/RuleEngine\\/CellMotionDetector\\/Motion$/)) {\n const motion = event.message.message.data.simpleItem.$.Value;\n if (motion !== lastMotionValue) {\n lastMotionValue = Boolean(motion);\n this.events = this.events || new EventEmitter();\n this.events.emit(\"motion\", motion);\n }\n }\n });\n\n return this.events;\n }\n\n async getVideoSource(): Promise<VideoSource> {\n const onvifDevice = await this.getDevice();\n return onvifDevice.videoSources[0];\n }\n\n async getDeviceInfo(): Promise<DeviceInformation> {\n const onvifDevice = await this.getDevice();\n return new Promise((resolve, reject) => {\n onvifDevice.getDeviceInformation((err, deviceInformation) => {\n if (err) return reject(err);\n resolve(deviceInformation);\n });\n });\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,IAAAA,gBAAoB;AACpB,oBAA6B;AAqBtB,MAAM,YAAY;AAAA,EAMvB,YAA+B,QAAsB;AAAtB;AAF/B,SAAiB,aAAa;AAAA,EAEwB;AAAA,EAEtD,MAAc,YAA2B;AACvC,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAI,KAAK,QAAQ;AACf,eAAO,QAAQ,KAAK,MAAM;AAAA,MAC5B;AAEA,YAAM,SAAe,IAAI;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