hoffmation-base 3.0.0-beta.9 → 3.0.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.
- package/README.md +34 -8
- package/lib/models/deviceSettings/cameraSettings.d.ts +4 -0
- package/lib/models/deviceSettings/cameraSettings.js +6 -1
- package/lib/models/deviceSettings/deviceSettings.d.ts +5 -0
- package/lib/models/deviceSettings/deviceSettings.js +7 -0
- package/lib/server/devices/{blueIris/cameraDevice.d.ts → CameraDevice.d.ts} +28 -30
- package/lib/server/devices/{blueIris/cameraDevice.js → CameraDevice.js} +69 -112
- package/lib/server/devices/baseDeviceInterfaces/iCameraDevice.d.ts +0 -7
- package/lib/server/devices/baseDeviceInterfaces/index.d.ts +1 -0
- package/lib/server/devices/baseDeviceInterfaces/index.js +1 -0
- package/lib/server/devices/blueIris/blueIrisCameraDevice.d.ts +28 -0
- package/lib/server/devices/blueIris/blueIrisCameraDevice.js +80 -0
- package/lib/server/devices/blueIris/index.d.ts +1 -1
- package/lib/server/devices/blueIris/index.js +1 -1
- package/lib/server/devices/dachs/lib/dachsHttpClient.js +4 -0
- package/lib/server/devices/index.d.ts +1 -0
- package/lib/server/devices/index.js +1 -0
- package/lib/server/services/dbo/postgreSqlPersist.js +82 -64
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -50,3 +50,4 @@ __exportStar(require("./IoBrokerDeviceInfo"), exports);
|
|
|
50
50
|
var nameAmountValuePair_1 = require("./nameAmountValuePair");
|
|
51
51
|
Object.defineProperty(exports, "NameAmountValuePair", { enumerable: true, get: function () { return nameAmountValuePair_1.NameAmountValuePair; } });
|
|
52
52
|
__exportStar(require("./wledDevice"), exports);
|
|
53
|
+
__exportStar(require("./CameraDevice"), exports);
|
|
@@ -5,7 +5,6 @@ const models_1 = require("../../../models");
|
|
|
5
5
|
const devices_1 = require("../../devices");
|
|
6
6
|
const pg_1 = require("pg");
|
|
7
7
|
const log_service_1 = require("../log-service");
|
|
8
|
-
const DeviceCapability_1 = require("../../devices/DeviceCapability");
|
|
9
8
|
const utils_1 = require("../utils");
|
|
10
9
|
class PostgreSqlPersist {
|
|
11
10
|
constructor(conf) {
|
|
@@ -17,36 +16,39 @@ class PostgreSqlPersist {
|
|
|
17
16
|
/** @inheritDoc */
|
|
18
17
|
addRoom(room) {
|
|
19
18
|
this.query(`
|
|
20
|
-
insert into hoffmation_schema."BasicRooms" (name, etage)
|
|
21
|
-
values ('${room.roomName}'
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
;
|
|
19
|
+
insert into hoffmation_schema."BasicRooms" (name, etage)
|
|
20
|
+
values ('${room.roomName}', ${room.etage}) ON CONFLICT (name)
|
|
21
|
+
DO
|
|
22
|
+
UPDATE SET
|
|
23
|
+
etage = ${room.etage}
|
|
24
|
+
;
|
|
26
25
|
`);
|
|
27
26
|
}
|
|
28
27
|
/** @inheritDoc */
|
|
29
28
|
addDevice(device) {
|
|
30
29
|
this.query(`
|
|
31
|
-
insert into hoffmation_schema."DeviceInfo" ("deviceid", "roomname", "alldeviceskey", "customname", "devtype")
|
|
32
|
-
values ('${device.id}','${device.info.room}','${device.info.allDevicesKey}','${device.info.customName}',
|
|
33
|
-
|
|
34
|
-
DO
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
insert into hoffmation_schema."DeviceInfo" ("deviceid", "roomname", "alldeviceskey", "customname", "devtype")
|
|
31
|
+
values ('${device.id}', '${device.info.room}', '${device.info.allDevicesKey}', '${device.info.customName}',
|
|
32
|
+
${device.deviceType}) ON CONFLICT ("deviceid")
|
|
33
|
+
DO
|
|
34
|
+
UPDATE SET
|
|
35
|
+
"roomname" = '${device.info.room}',
|
|
36
|
+
"alldeviceskey" = '${device.info.allDevicesKey}',
|
|
37
|
+
"customname" = '${device.info.customName}',
|
|
38
|
+
"devtype" = ${device.deviceType}
|
|
39
|
+
;
|
|
40
40
|
`);
|
|
41
41
|
}
|
|
42
42
|
/** @inheritDoc */
|
|
43
43
|
async getLastDesiredPosition(device) {
|
|
44
44
|
const dbResult = await this.query(`SELECT position
|
|
45
|
-
from hoffmation_schema."ShutterDeviceData"
|
|
46
|
-
WHERE "deviceID" = '${device.id}'
|
|
47
|
-
and date >= CURRENT_DATE
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
from hoffmation_schema."ShutterDeviceData"
|
|
46
|
+
WHERE "deviceID" = '${device.id}'
|
|
47
|
+
and date >= CURRENT_DATE
|
|
48
|
+
AND date
|
|
49
|
+
< CURRENT_DATE + INTERVAL '1 DAY'
|
|
50
|
+
ORDER BY date desc
|
|
51
|
+
Limit 1`);
|
|
50
52
|
if (dbResult !== null && dbResult.length > 0) {
|
|
51
53
|
return dbResult[0];
|
|
52
54
|
}
|
|
@@ -55,9 +57,13 @@ Limit 1`);
|
|
|
55
57
|
}
|
|
56
58
|
/** @inheritDoc */
|
|
57
59
|
async motionSensorTodayCount(device) {
|
|
58
|
-
const dbResult = await this.query(`SELECT Count(*)
|
|
59
|
-
from hoffmation_schema."MotionSensorDeviceData"
|
|
60
|
-
WHERE "deviceID" = '${device.id}'
|
|
60
|
+
const dbResult = await this.query(`SELECT Count(*)
|
|
61
|
+
from hoffmation_schema."MotionSensorDeviceData"
|
|
62
|
+
WHERE "deviceID" = '${device.id}'
|
|
63
|
+
and "movementDetected"
|
|
64
|
+
and date >= CURRENT_DATE
|
|
65
|
+
AND date
|
|
66
|
+
< CURRENT_DATE + INTERVAL '1 DAY'`);
|
|
61
67
|
if (dbResult !== null && dbResult.length > 0) {
|
|
62
68
|
const result = dbResult[0];
|
|
63
69
|
result.count = Number(result.count);
|
|
@@ -335,6 +341,15 @@ BEGIN
|
|
|
335
341
|
add "batteryStoredKwH" double precision;
|
|
336
342
|
END IF;
|
|
337
343
|
|
|
344
|
+
IF (SELECT COUNT(column_name) = 0
|
|
345
|
+
FROM information_schema.columns
|
|
346
|
+
WHERE table_name = 'HeaterDeviceData'
|
|
347
|
+
and column_name = 'windowOpen') Then
|
|
348
|
+
alter table hoffmation_schema."HeaterDeviceData"
|
|
349
|
+
add "windowOpen" boolean;
|
|
350
|
+
END IF;
|
|
351
|
+
|
|
352
|
+
|
|
338
353
|
IF (SELECT COUNT(column_name) = 0
|
|
339
354
|
FROM information_schema.columns
|
|
340
355
|
WHERE table_name = 'EnergyCalculation'
|
|
@@ -356,19 +371,19 @@ $$;`);
|
|
|
356
371
|
/** @inheritDoc */
|
|
357
372
|
persistAC(device) {
|
|
358
373
|
this.query(`
|
|
359
|
-
insert into hoffmation_schema."AcDeviceData" ("deviceID", "on", "date", "roomTemperature")
|
|
360
|
-
values ('${device.id}', ${device.on}, '${new Date().toISOString()}', ${device.temperature});
|
|
374
|
+
insert into hoffmation_schema."AcDeviceData" ("deviceID", "on", "date", "roomTemperature")
|
|
375
|
+
values ('${device.id}', ${device.on}, '${new Date().toISOString()}', ${device.temperature});
|
|
361
376
|
`);
|
|
362
377
|
}
|
|
363
378
|
/** @inheritDoc */
|
|
364
379
|
persistActuator(device) {
|
|
365
380
|
let percentage = undefined;
|
|
366
|
-
if (device.deviceCapabilities.includes(
|
|
381
|
+
if (device.deviceCapabilities.includes(devices_1.DeviceCapability.dimmablelamp)) {
|
|
367
382
|
percentage = device.brightness;
|
|
368
383
|
}
|
|
369
384
|
this.query(`
|
|
370
|
-
insert into hoffmation_schema."ActuatorDeviceData" ("deviceID", "on", "date", "percentage")
|
|
371
|
-
values ('${device.id}', ${device.actuatorOn}, '${new Date().toISOString()}', ${percentage !== null && percentage !== void 0 ? percentage : 'null'});
|
|
385
|
+
insert into hoffmation_schema."ActuatorDeviceData" ("deviceID", "on", "date", "percentage")
|
|
386
|
+
values ('${device.id}', ${device.actuatorOn}, '${new Date().toISOString()}', ${percentage !== null && percentage !== void 0 ? percentage : 'null'});
|
|
372
387
|
`);
|
|
373
388
|
}
|
|
374
389
|
/** @inheritDoc */
|
|
@@ -382,30 +397,31 @@ values ('${device.id}', ${device.actuatorOn}, '${new Date().toISOString()}', ${p
|
|
|
382
397
|
desiredTemperature = null;
|
|
383
398
|
}
|
|
384
399
|
void this.query(`
|
|
385
|
-
insert into hoffmation_schema."HeaterDeviceData"
|
|
386
|
-
|
|
400
|
+
insert into hoffmation_schema."HeaterDeviceData"
|
|
401
|
+
("deviceID", "level", "date", "roomTemperature", "desiredTemperature", "seasonTurnOff", "windowOpen")
|
|
402
|
+
values ('${device.id}', ${device.iLevel}, '${new Date().toISOString()}', ${roomTemp !== null && roomTemp !== void 0 ? roomTemp : 'null'}, ${desiredTemperature !== null && desiredTemperature !== void 0 ? desiredTemperature : 'null'}, ${device.seasonTurnOff}, ${device.windowOpen});
|
|
387
403
|
`);
|
|
388
404
|
}
|
|
389
405
|
/** @inheritDoc */
|
|
390
406
|
persistHandleSensor(device) {
|
|
391
407
|
const currentPos = device.position;
|
|
392
408
|
this.query(`
|
|
393
|
-
insert into hoffmation_schema."HandleDeviceData" ("deviceID", "position", "date")
|
|
394
|
-
values ('${device.id}', ${currentPos}, '${new Date().toISOString()}');
|
|
409
|
+
insert into hoffmation_schema."HandleDeviceData" ("deviceID", "position", "date")
|
|
410
|
+
values ('${device.id}', ${currentPos}, '${new Date().toISOString()}');
|
|
395
411
|
`);
|
|
396
412
|
}
|
|
397
413
|
/** @inheritDoc */
|
|
398
414
|
persistSwitchInput(device, pressType, buttonName) {
|
|
399
415
|
this.query(`
|
|
400
|
-
insert into hoffmation_schema."ButtonSwitchPresses" ("deviceID", "pressType", "buttonName", "date")
|
|
401
|
-
values ('${device.id}', ${pressType}, '${buttonName}', '${new Date().toISOString()}');
|
|
416
|
+
insert into hoffmation_schema."ButtonSwitchPresses" ("deviceID", "pressType", "buttonName", "date")
|
|
417
|
+
values ('${device.id}', ${pressType}, '${buttonName}', '${new Date().toISOString()}');
|
|
402
418
|
`);
|
|
403
419
|
}
|
|
404
420
|
/** @inheritDoc */
|
|
405
421
|
persistMotionSensor(device) {
|
|
406
422
|
this.query(`
|
|
407
|
-
insert into hoffmation_schema."MotionSensorDeviceData" ("deviceID", "movementDetected", "date")
|
|
408
|
-
values ('${device.id}', ${device.movementDetected}, '${new Date().toISOString()}');
|
|
423
|
+
insert into hoffmation_schema."MotionSensorDeviceData" ("deviceID", "movementDetected", "date")
|
|
424
|
+
values ('${device.id}', ${device.movementDetected}, '${new Date().toISOString()}');
|
|
409
425
|
`);
|
|
410
426
|
}
|
|
411
427
|
/** @inheritDoc */
|
|
@@ -413,8 +429,8 @@ values ('${device.id}', ${device.movementDetected}, '${new Date().toISOString()}
|
|
|
413
429
|
const currentLevel = device.currentLevel >= 0 ? device.currentLevel : null;
|
|
414
430
|
const desiredLevel = device.desiredWindowShutterLevel >= 0 ? device.desiredWindowShutterLevel : null;
|
|
415
431
|
this.query(`
|
|
416
|
-
insert into hoffmation_schema."ShutterDeviceData" ("deviceID", "position", "date", "desiredPosition")
|
|
417
|
-
values ('${device.id}', ${currentLevel}, '${new Date().toISOString()}', ${desiredLevel});
|
|
432
|
+
insert into hoffmation_schema."ShutterDeviceData" ("deviceID", "position", "date", "desiredPosition")
|
|
433
|
+
values ('${device.id}', ${currentLevel}, '${new Date().toISOString()}', ${desiredLevel});
|
|
418
434
|
`);
|
|
419
435
|
}
|
|
420
436
|
/** @inheritDoc */
|
|
@@ -424,37 +440,38 @@ values ('${device.id}', ${currentLevel}, '${new Date().toISOString()}', ${desire
|
|
|
424
440
|
roomTemp = null;
|
|
425
441
|
}
|
|
426
442
|
this.query(`
|
|
427
|
-
insert into hoffmation_schema."TemperatureSensorDeviceData" ("deviceID", "temperature", "date", "roomTemperature")
|
|
428
|
-
values ('${device.id}', ${device.iTemperature}, '${new Date().toISOString()}', ${roomTemp !== null && roomTemp !== void 0 ? roomTemp : 'null'});
|
|
443
|
+
insert into hoffmation_schema."TemperatureSensorDeviceData" ("deviceID", "temperature", "date", "roomTemperature")
|
|
444
|
+
values ('${device.id}', ${device.iTemperature}, '${new Date().toISOString()}', ${roomTemp !== null && roomTemp !== void 0 ? roomTemp : 'null'});
|
|
429
445
|
`);
|
|
430
446
|
}
|
|
431
447
|
/** @inheritDoc */
|
|
432
448
|
persistHumiditySensor(device) {
|
|
433
449
|
this.query(`
|
|
434
|
-
insert into hoffmation_schema."HumiditySensorDeviceData" ("deviceID", "humidity", "date")
|
|
435
|
-
values ('${device.id}', ${device.humidity}, '${new Date().toISOString()}');
|
|
450
|
+
insert into hoffmation_schema."HumiditySensorDeviceData" ("deviceID", "humidity", "date")
|
|
451
|
+
values ('${device.id}', ${device.humidity}, '${new Date().toISOString()}');
|
|
436
452
|
`);
|
|
437
453
|
}
|
|
438
454
|
/** @inheritDoc */
|
|
439
455
|
persistBatteryDevice(device) {
|
|
440
456
|
this.query(`
|
|
441
|
-
insert into hoffmation_schema."BatteryDeviceData" ("deviceID", "battery", "date")
|
|
442
|
-
values ('${device.id}', ${utils_1.Utils.round(device.batteryLevel, 1)}, '${new Date().toISOString()}');
|
|
457
|
+
insert into hoffmation_schema."BatteryDeviceData" ("deviceID", "battery", "date")
|
|
458
|
+
values ('${device.id}', ${utils_1.Utils.round(device.batteryLevel, 1)}, '${new Date().toISOString()}');
|
|
443
459
|
`);
|
|
444
460
|
}
|
|
445
461
|
/** @inheritDoc */
|
|
446
462
|
persistZigbeeDevice(device) {
|
|
447
463
|
const dateValue = device.lastUpdate.getTime() > 0 ? `'${device.lastUpdate.toISOString()}'` : 'null';
|
|
448
464
|
this.query(`
|
|
449
|
-
insert into hoffmation_schema."ZigbeeDeviceData" ("deviceID", "date", "available", "linkQuality", "lastUpdate")
|
|
450
|
-
values ('${device.id}', '${new Date().toISOString()}', ${device.available}, ${device.linkQuality},
|
|
465
|
+
insert into hoffmation_schema."ZigbeeDeviceData" ("deviceID", "date", "available", "linkQuality", "lastUpdate")
|
|
466
|
+
values ('${device.id}', '${new Date().toISOString()}', ${device.available}, ${device.linkQuality},
|
|
467
|
+
${dateValue});
|
|
451
468
|
`);
|
|
452
469
|
}
|
|
453
470
|
/** @inheritDoc */
|
|
454
471
|
persistIlluminationSensor(device) {
|
|
455
472
|
this.query(`
|
|
456
|
-
insert into hoffmation_schema."IlluminationSensorDeviceData" ("deviceID", "illumination", "date")
|
|
457
|
-
values ('${device.id}', ${device.currentIllumination}, '${new Date().toISOString()}');`);
|
|
473
|
+
insert into hoffmation_schema."IlluminationSensorDeviceData" ("deviceID", "illumination", "date")
|
|
474
|
+
values ('${device.id}', ${device.currentIllumination}, '${new Date().toISOString()}');`);
|
|
458
475
|
}
|
|
459
476
|
/** @inheritDoc */
|
|
460
477
|
persistShutterCalibration(_data) {
|
|
@@ -463,31 +480,32 @@ values ('${device.id}', ${device.currentIllumination}, '${new Date().toISOString
|
|
|
463
480
|
/** @inheritDoc */
|
|
464
481
|
persistEnergyManager(calc) {
|
|
465
482
|
this.query(`
|
|
466
|
-
insert into hoffmation_schema."EnergyCalculation" ("startDate", "endDate", "selfConsumedKwH", "injectedKwH",
|
|
467
|
-
|
|
468
|
-
values ('${new Date(calc.startMs).toISOString()}','${new Date(calc.endMs).toISOString()}',
|
|
469
|
-
|
|
483
|
+
insert into hoffmation_schema."EnergyCalculation" ("startDate", "endDate", "selfConsumedKwH", "injectedKwH",
|
|
484
|
+
"drawnKwH", "batteryStoredKwH", "batteryLevel")
|
|
485
|
+
values ('${new Date(calc.startMs).toISOString()}', '${new Date(calc.endMs).toISOString()}',
|
|
486
|
+
${calc.selfConsumedKwH}, ${calc.injectedKwH}, ${calc.drawnKwH}, ${calc.batteryStoredKwH},
|
|
487
|
+
${calc.batteryLevel});
|
|
470
488
|
`);
|
|
471
489
|
}
|
|
472
490
|
/** @inheritDoc */
|
|
473
491
|
persistSettings(id, settings, customName) {
|
|
474
492
|
this.query(`
|
|
475
|
-
insert into hoffmation_schema."Settings" (id, settings, customname, date)
|
|
476
|
-
values ('${id}','${settings}','${customName}', '${new Date().toISOString()}')
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
;
|
|
493
|
+
insert into hoffmation_schema."Settings" (id, settings, customname, date)
|
|
494
|
+
values ('${id}', '${settings}', '${customName}', '${new Date().toISOString()}') ON CONFLICT (id, date)
|
|
495
|
+
DO
|
|
496
|
+
UPDATE SET
|
|
497
|
+
settings = '${settings}',
|
|
498
|
+
customname = '${customName}'
|
|
499
|
+
;
|
|
482
500
|
`);
|
|
483
501
|
}
|
|
484
502
|
/** @inheritDoc */
|
|
485
503
|
async loadSettings(id) {
|
|
486
504
|
const dbResult = await this.query(`SELECT settings::text, id, date
|
|
487
|
-
from hoffmation_schema."Settings"
|
|
488
|
-
WHERE "id" = '${id}'
|
|
489
|
-
ORDER BY "date" DESC
|
|
490
|
-
LIMIT 1`);
|
|
505
|
+
from hoffmation_schema."Settings"
|
|
506
|
+
WHERE "id" = '${id}'
|
|
507
|
+
ORDER BY "date" DESC
|
|
508
|
+
LIMIT 1`);
|
|
491
509
|
if (dbResult !== null && dbResult.length > 0) {
|
|
492
510
|
return dbResult[0].settings;
|
|
493
511
|
}
|