hoffmation-base 3.6.0 → 3.7.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/lib/action/airQualitySensorChangeAction.d.ts +16 -0
  2. package/lib/action/airQualitySensorChangeAction.js +15 -0
  3. package/lib/action/index.d.ts +1 -0
  4. package/lib/action/index.js +3 -1
  5. package/lib/devices/sharedFunctions/airQualitySensor.d.ts +27 -0
  6. package/lib/devices/sharedFunctions/airQualitySensor.js +87 -0
  7. package/lib/devices/sharedFunctions/index.d.ts +1 -0
  8. package/lib/devices/sharedFunctions/index.js +1 -0
  9. package/lib/devices/unifi/index.d.ts +1 -0
  10. package/lib/devices/unifi/index.js +1 -0
  11. package/lib/devices/unifi/own-unifi-air-quality-sensor.d.ts +81 -0
  12. package/lib/devices/unifi/own-unifi-air-quality-sensor.js +164 -0
  13. package/lib/devices/unifi/own-unifi-camera.d.ts +6 -5
  14. package/lib/devices/unifi/own-unifi-camera.js +14 -24
  15. package/lib/devices/unifi/protect-module.d.ts +11 -0
  16. package/lib/devices/unifi/protect-module.js +16 -0
  17. package/lib/devices/unifi/unifi-logger.d.ts +5 -5
  18. package/lib/devices/unifi/unifi-logger.js +9 -8
  19. package/lib/devices/unifi/unifi-protect.d.ts +38 -7
  20. package/lib/devices/unifi/unifi-protect.js +199 -66
  21. package/lib/enums/DeviceCapability.d.ts +1 -0
  22. package/lib/enums/DeviceCapability.js +1 -0
  23. package/lib/enums/commandType.d.ts +1 -0
  24. package/lib/enums/commandType.js +1 -0
  25. package/lib/enums/deviceType.d.ts +1 -0
  26. package/lib/enums/deviceType.js +1 -0
  27. package/lib/interfaces/baseDevices/iAirQualityCollector.d.ts +23 -0
  28. package/lib/interfaces/baseDevices/iAirQualityCollector.js +2 -0
  29. package/lib/interfaces/baseDevices/iAirQualitySensor.d.ts +97 -0
  30. package/lib/interfaces/baseDevices/iAirQualitySensor.js +7 -0
  31. package/lib/interfaces/baseDevices/index.d.ts +2 -0
  32. package/lib/interfaces/baseDevices/index.js +2 -0
  33. package/lib/interfaces/iBlockAutomaticHandler.d.ts +4 -0
  34. package/lib/interfaces/iPersist.d.ts +6 -1
  35. package/lib/services/ac/ac-device.js +11 -0
  36. package/lib/services/blockAutomaticHandler.d.ts +11 -0
  37. package/lib/services/blockAutomaticHandler.js +17 -0
  38. package/lib/services/dbo/postgreSqlPersist.d.ts +3 -1
  39. package/lib/services/dbo/postgreSqlPersist.js +34 -1
  40. package/lib/tsconfig.tsbuildinfo +1 -1
  41. package/package.json +4 -3
@@ -9,11 +9,22 @@ export declare class BlockAutomaticHandler implements iBlockAutomaticHandler {
9
9
  private readonly _logger;
10
10
  private readonly _restoreAutomatic;
11
11
  private _automaticBlockedUntil;
12
+ private _blockSetByUser;
12
13
  private _restoreAutomaticStateTimeout;
13
14
  constructor(restoreAutomaticCb: (c: RestoreTargetAutomaticValueCommand) => void, _logger: (level: LogLevel, message: string, logDebugType?: LogDebugType) => void);
14
15
  get automaticBlockedUntil(): Date;
15
16
  private set automaticBlockedUntil(value);
16
17
  get automaticBlockActive(): boolean;
18
+ /**
19
+ * Whether the active block was set by a person rather than by another rule.
20
+ *
21
+ * The expiry date alone cannot answer that, and a rule that has to decide whether it may overrule
22
+ * the current state needs to: at the end of the day the user's choice outranks a configured
23
+ * automatism. Manual, API and Force all count - they are the same decision reaching the house
24
+ * through different doors.
25
+ * @returns True while a block set by a person is still running.
26
+ */
27
+ get automaticBlockedByUser(): boolean;
17
28
  disableAutomatic(c: BlockAutomaticCommand): void;
18
29
  disableAutomaticUntil(c: BlockAutomaticUntilCommand): void;
19
30
  liftAutomaticBlock(c: BlockAutomaticLiftBlockCommand): void;
@@ -16,6 +16,7 @@ class BlockAutomaticHandler {
16
16
  constructor(restoreAutomaticCb, _logger) {
17
17
  this._logger = _logger;
18
18
  this._automaticBlockedUntil = new Date(0);
19
+ this._blockSetByUser = false;
19
20
  this._restoreAutomaticStateTimeout = null;
20
21
  this._restoreAutomatic = restoreAutomaticCb;
21
22
  }
@@ -28,6 +29,18 @@ class BlockAutomaticHandler {
28
29
  get automaticBlockActive() {
29
30
  return this._automaticBlockedUntil > new Date();
30
31
  }
32
+ /**
33
+ * Whether the active block was set by a person rather than by another rule.
34
+ *
35
+ * The expiry date alone cannot answer that, and a rule that has to decide whether it may overrule
36
+ * the current state needs to: at the end of the day the user's choice outranks a configured
37
+ * automatism. Manual, API and Force all count - they are the same decision reaching the house
38
+ * through different doors.
39
+ * @returns True while a block set by a person is still running.
40
+ */
41
+ get automaticBlockedByUser() {
42
+ return this.automaticBlockActive && this._blockSetByUser;
43
+ }
31
44
  disableAutomatic(c) {
32
45
  this.disableAutomaticUntil(new command_1.BlockAutomaticUntilCommand(c, new Date(utils_1.Utils.nowMS() + c.durationMS), '', c.onCollideAction, c.revertToAutomaticAtBlockLift));
33
46
  }
@@ -41,6 +54,9 @@ class BlockAutomaticHandler {
41
54
  }
42
55
  this._logger(enums_1.LogLevel.Info, c.logMessage);
43
56
  this.automaticBlockedUntil = c.targetDate;
57
+ // Recorded here rather than derived later: the command is gone once this returns, and the level
58
+ // that pinned the device is exactly what a rule needs to know before overruling it.
59
+ this._blockSetByUser = c.isForceAction;
44
60
  if (c.revertToAutomaticAtBlockLift) {
45
61
  const revertCommand = new command_1.RestoreTargetAutomaticValueCommand(c, 'Restore to automatic state after block.');
46
62
  revertCommand.overrideCommandSource = enums_1.CommandSource.Automatic;
@@ -53,6 +69,7 @@ class BlockAutomaticHandler {
53
69
  liftAutomaticBlock(c) {
54
70
  this.removeRestoreTimeout();
55
71
  this.automaticBlockedUntil = new Date(0);
72
+ this._blockSetByUser = false;
56
73
  if (c.revertToAutomatic) {
57
74
  this._restoreAutomatic(new command_1.RestoreTargetAutomaticValueCommand(c));
58
75
  }
@@ -1,5 +1,5 @@
1
1
  import { PoolConfig } from 'pg';
2
- import { iAcDevice, iActuator, iBaseDevice, iBatteryDevice, iButtonSwitch, iDesiredShutterPosition, iHandle, iHeater, iHumidityCollector, iIlluminationSensor, iMotionSensor, iPersist, iRoomBase, iShutter, iShutterCalibration, iTemperatureCollector, iTemperatureMeasurement, iZigbeeDevice } from '../../interfaces';
2
+ import { iAcDevice, iActuator, iBaseDevice, iBatteryDevice, iButtonSwitch, iDesiredShutterPosition, iHandle, iHeater, iAirQualityCollector, iHumidityCollector, iIlluminationSensor, iMotionSensor, iPersist, iRoomBase, iShutter, iShutterCalibration, iTemperatureCollector, iTemperatureMeasurement, iZigbeeDevice } from '../../interfaces';
3
3
  import { CountToday, EnergyCalculation } from '../../models';
4
4
  import { ButtonPressType } from '../../enums';
5
5
  export declare class PostgreSqlPersist implements iPersist {
@@ -42,6 +42,8 @@ export declare class PostgreSqlPersist implements iPersist {
42
42
  /** @inheritDoc */
43
43
  persistHumiditySensor(device: iHumidityCollector): void;
44
44
  /** @inheritDoc */
45
+ persistAirQualitySensor(device: iAirQualityCollector): void;
46
+ /** @inheritDoc */
45
47
  persistBatteryDevice(device: iBatteryDevice): void;
46
48
  /** @inheritDoc */
47
49
  persistZigbeeDevice(device: iZigbeeDevice): void;
@@ -292,7 +292,31 @@ BEGIN
292
292
  constraint humiditysensordevicedata_pk
293
293
  primary key ("deviceID", date)
294
294
  );
295
-
295
+
296
+ END IF;
297
+
298
+ IF (SELECT to_regclass('hoffmation_schema."AirQualitySensorDeviceData"') IS NULL) Then
299
+ create table if not exists hoffmation_schema."AirQualitySensorDeviceData"
300
+ (
301
+ "deviceID" varchar(60) not null
302
+ constraint "AirQualitySensorDeviceData_DeviceInfo_null_fk"
303
+ references hoffmation_schema."DeviceInfo"
304
+ on delete set null,
305
+ aqi double precision,
306
+ co2 double precision,
307
+ nox double precision,
308
+ "pm1p0" double precision,
309
+ "pm2p5" double precision,
310
+ "pm4p0" double precision,
311
+ "pm10p0" double precision,
312
+ tvoc double precision,
313
+ vape double precision,
314
+ voc double precision,
315
+ date timestamp not null,
316
+ constraint airqualitysensordevicedata_pk
317
+ primary key ("deviceID", date)
318
+ );
319
+
296
320
  END IF;
297
321
 
298
322
  IF (SELECT to_regclass('hoffmation_schema."BatteryDeviceData"') IS NULL) Then
@@ -478,6 +502,15 @@ $$;`);
478
502
  `);
479
503
  }
480
504
  /** @inheritDoc */
505
+ persistAirQualitySensor(device) {
506
+ const readings = device.airQuality;
507
+ const value = (metric) => (metric === interfaces_1.UNDEFINED_AIR_QUALITY_VALUE ? 'null' : `${metric}`);
508
+ this.query(`
509
+ insert into hoffmation_schema."AirQualitySensorDeviceData" ("deviceID", "aqi", "co2", "nox", "pm1p0", "pm2p5", "pm4p0", "pm10p0", "tvoc", "vape", "voc", "date")
510
+ values ('${device.id}', ${value(readings.aqi)}, ${value(readings.co2)}, ${value(readings.nox)}, ${value(readings.pm1p0)}, ${value(readings.pm2p5)}, ${value(readings.pm4p0)}, ${value(readings.pm10p0)}, ${value(readings.tvoc)}, ${value(readings.vape)}, ${value(readings.voc)}, '${new Date().toISOString()}');
511
+ `);
512
+ }
513
+ /** @inheritDoc */
481
514
  persistBatteryDevice(device) {
482
515
  this.query(`
483
516
  insert into hoffmation_schema."BatteryDeviceData" ("deviceID", "battery", "date")