hoffmation-base 3.2.3-alpha.5 → 3.2.3-alpha.7

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.
@@ -1,5 +1,5 @@
1
1
  import { BaseAction } from './baseAction';
2
- import { CommandType } from '../enums';
2
+ import { CommandSource, CommandType } from '../enums';
3
3
  import { iMotionSensor } from '../interfaces';
4
4
  export declare class MotionSensorAction extends BaseAction {
5
5
  /** @inheritDoc */
@@ -12,5 +12,5 @@ export declare class MotionSensorAction extends BaseAction {
12
12
  * The motion sensor that triggered the action
13
13
  */
14
14
  readonly sensor: iMotionSensor;
15
- constructor(sensor: iMotionSensor);
15
+ constructor(sensor: iMotionSensor, source?: CommandSource);
16
16
  }
@@ -4,8 +4,8 @@ exports.MotionSensorAction = void 0;
4
4
  const baseAction_1 = require("./baseAction");
5
5
  const enums_1 = require("../enums");
6
6
  class MotionSensorAction extends baseAction_1.BaseAction {
7
- constructor(sensor) {
8
- super(enums_1.CommandSource.Automatic, `${sensor.customName} ${sensor.movementDetected ? 'detected' : 'cleared'} motion`);
7
+ constructor(sensor, source = enums_1.CommandSource.Automatic) {
8
+ super(source, `${sensor.customName} ${sensor.movementDetected ? 'detected' : 'cleared'} motion`);
9
9
  /** @inheritDoc */
10
10
  this.type = enums_1.CommandType.MotionSensorAction;
11
11
  this.motionDetected = sensor.movementDetected;
@@ -156,6 +156,7 @@ export declare class API {
156
156
  * @returns In case it failed the Error containing the reason
157
157
  */
158
158
  static setRoomSettings(roomName: string, settings: Partial<DeviceSettings>): Error | null;
159
+ static cameraInformPersonDetected(deviceId: string): Error | void;
159
160
  static getLastCameraImage(deviceId: string): Error | string;
160
161
  static persistAllDeviceSettings(): void;
161
162
  static loadAllDeviceSettingsFromDb(): void;
@@ -370,6 +370,16 @@ class API {
370
370
  r.settings.settingsContainer.persist(r);
371
371
  return null;
372
372
  }
373
+ static cameraInformPersonDetected(deviceId) {
374
+ const d = this.getDevice(deviceId);
375
+ if (d === undefined) {
376
+ return new Error(`Device with ID ${deviceId} not found`);
377
+ }
378
+ if (!d.deviceCapabilities.includes(enums_1.DeviceCapability.camera)) {
379
+ return new Error(`Device with ID ${deviceId} is no camera`);
380
+ }
381
+ d.setPersonDetected();
382
+ }
373
383
  // TODO: Missing Comment
374
384
  static getLastCameraImage(deviceId) {
375
385
  const d = this.getDevice(deviceId);
@@ -23,12 +23,13 @@ class BaseCommand {
23
23
  }
24
24
  get isAutomaticAction() {
25
25
  if (this.overrideCommandSource !== undefined) {
26
- return this.overrideCommandSource === enums_1.CommandSource.Automatic;
26
+ return (this.overrideCommandSource === enums_1.CommandSource.Automatic ||
27
+ this.overrideCommandSource === enums_1.CommandSource.ApiAutomatic);
27
28
  }
28
29
  if (typeof this.source === 'object') {
29
30
  return this.source.isAutomaticAction;
30
31
  }
31
- return this.source === enums_1.CommandSource.Automatic;
32
+ return this.source === enums_1.CommandSource.Automatic || this.source === enums_1.CommandSource.ApiAutomatic;
32
33
  }
33
34
  get isForceAction() {
34
35
  if (this.overrideCommandSource !== undefined) {
@@ -1,5 +1,5 @@
1
1
  import { iBaseDevice, iCameraDevice, iCameraSettings } from '../interfaces';
2
- import { LogDebugType, LogLevel } from '../enums';
2
+ import { CommandSource, LogDebugType, LogLevel } from '../enums';
3
3
  import { MotionSensorAction } from '../action';
4
4
  import { DeviceInfo } from './DeviceInfo';
5
5
  import { RoomBaseDevice } from './RoomBaseDevice';
@@ -55,11 +55,13 @@ export declare abstract class CameraDevice extends RoomBaseDevice implements iCa
55
55
  /** @inheritDoc */
56
56
  blockForDevice(device: iBaseDevice, block: boolean): void;
57
57
  /** @inheritDoc */
58
+ setPersonDetected(): void;
59
+ /** @inheritDoc */
58
60
  persistMotionSensor(): void;
59
61
  log(level: LogLevel, message: string, debugType?: LogDebugType): void;
60
62
  private initializeMovementCounter;
61
63
  protected onNewMotionDetectedValue(newValue: boolean): void;
62
- protected onNewPersonDetectedValue(newValue: boolean): void;
64
+ protected onNewPersonDetectedValue(newValue: boolean, source?: CommandSource): void;
63
65
  protected onNewImageSnapshot(image: string): void;
64
66
  protected onNewDogDetectionValue(newDogDetectionVal: boolean): void;
65
67
  protected abstract resetPersonDetectedState(): void;
@@ -94,6 +94,10 @@ class CameraDevice extends RoomBaseDevice_1.RoomBaseDevice {
94
94
  this.log(enums_1.LogLevel.Debug, `Handle device ${block ? 'block' : 'unblock'}, new blocking amount: ${this._devicesBlockingAlarmMap.size}`);
95
95
  }
96
96
  /** @inheritDoc */
97
+ setPersonDetected() {
98
+ this.onNewPersonDetectedValue(true, enums_1.CommandSource.ApiAutomatic);
99
+ }
100
+ /** @inheritDoc */
97
101
  persistMotionSensor() {
98
102
  var _a;
99
103
  (_a = services_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.persistMotionSensor(this);
@@ -133,7 +137,7 @@ class CameraDevice extends RoomBaseDevice_1.RoomBaseDevice {
133
137
  this.resetMovementFallbackTimer();
134
138
  }
135
139
  }
136
- onNewPersonDetectedValue(newValue) {
140
+ onNewPersonDetectedValue(newValue, source = enums_1.CommandSource.Automatic) {
137
141
  this.log(enums_1.LogLevel.Debug, `Update for PersonDetected to value: ${newValue}`);
138
142
  if (newValue) {
139
143
  this.log(enums_1.LogLevel.Info, 'Person Detected');
@@ -141,7 +145,7 @@ class CameraDevice extends RoomBaseDevice_1.RoomBaseDevice {
141
145
  }
142
146
  this._personDetected = newValue;
143
147
  if (this.settings.movementDetectionOnPersonOnly) {
144
- this.updateMovement(newValue);
148
+ this.updateMovement(newValue, source);
145
149
  }
146
150
  }
147
151
  onNewImageSnapshot(image) {
@@ -163,11 +167,11 @@ class CameraDevice extends RoomBaseDevice_1.RoomBaseDevice {
163
167
  this.updateMovement(newDogDetectionVal);
164
168
  }
165
169
  }
166
- updateMovement(newState) {
170
+ updateMovement(newState, source = enums_1.CommandSource.Automatic) {
167
171
  if (!this._initialized && newState) {
168
172
  this.log(enums_1.LogLevel.Trace, 'Movement recognized, but database initialization has not finished yet --> delay.');
169
173
  utils_1.Utils.guardedTimeout(() => {
170
- this.updateMovement(newState);
174
+ this.updateMovement(newState, source);
171
175
  }, 1000, this);
172
176
  return;
173
177
  }
@@ -184,7 +188,7 @@ class CameraDevice extends RoomBaseDevice_1.RoomBaseDevice {
184
188
  this.log(enums_1.LogLevel.Trace, `This is movement no. ${this.detectionsToday}`);
185
189
  }
186
190
  for (const c of this._movementDetectedCallback) {
187
- c(new action_1.MotionSensorAction(this));
191
+ c(new action_1.MotionSensorAction(this, source));
188
192
  }
189
193
  }
190
194
  resetPersonDetectFallbackTimer() {
@@ -11,17 +11,22 @@ export declare enum CommandSource {
11
11
  * This should mark all commands that are executed as an automatic response to a certain action/change.
12
12
  */
13
13
  Automatic = 2,
14
+ /**
15
+ * This should mark all commands/sources which resulted of an automatic api call, e.g an external service webhook.
16
+ * @type {CommandSource.ApiAutomatic}
17
+ */
18
+ ApiAutomatic = 3,
14
19
  /**
15
20
  * This should mark all commands that are executed by a user thus having a higher priority than other automatic commands.
16
21
  */
17
- Manual = 3,
22
+ Manual = 4,
18
23
  /**
19
24
  * This should mark all commands that are executed by an API call.
20
25
  * !WARNING! API could be an automatic call, but also a manual call e.g. using hoffmation-ios or homebridge-hoffmation --> So this is a higher priority than Automatic but still lower than manual/force.
21
26
  */
22
- API = 4,
27
+ API = 5,
23
28
  /**
24
29
  * This should mark all commands that have highest priority, thus overruling/ignoring certain controls/safety mechanisms.
25
30
  */
26
- Force = 5
31
+ Force = 6
27
32
  }
@@ -16,17 +16,22 @@ var CommandSource;
16
16
  * This should mark all commands that are executed as an automatic response to a certain action/change.
17
17
  */
18
18
  CommandSource[CommandSource["Automatic"] = 2] = "Automatic";
19
+ /**
20
+ * This should mark all commands/sources which resulted of an automatic api call, e.g an external service webhook.
21
+ * @type {CommandSource.ApiAutomatic}
22
+ */
23
+ CommandSource[CommandSource["ApiAutomatic"] = 3] = "ApiAutomatic";
19
24
  /**
20
25
  * This should mark all commands that are executed by a user thus having a higher priority than other automatic commands.
21
26
  */
22
- CommandSource[CommandSource["Manual"] = 3] = "Manual";
27
+ CommandSource[CommandSource["Manual"] = 4] = "Manual";
23
28
  /**
24
29
  * This should mark all commands that are executed by an API call.
25
30
  * !WARNING! API could be an automatic call, but also a manual call e.g. using hoffmation-ios or homebridge-hoffmation --> So this is a higher priority than Automatic but still lower than manual/force.
26
31
  */
27
- CommandSource[CommandSource["API"] = 4] = "API";
32
+ CommandSource[CommandSource["API"] = 5] = "API";
28
33
  /**
29
34
  * This should mark all commands that have highest priority, thus overruling/ignoring certain controls/safety mechanisms.
30
35
  */
31
- CommandSource[CommandSource["Force"] = 5] = "Force";
36
+ CommandSource[CommandSource["Force"] = 6] = "Force";
32
37
  })(CommandSource || (exports.CommandSource = CommandSource = {}));
@@ -47,4 +47,8 @@ export interface iCameraDevice extends iMotionSensor {
47
47
  * @param block - Whether to block the alarm for the device or lift the block
48
48
  */
49
49
  blockForDevice(device: iBaseDevice, block: boolean): void;
50
+ /**
51
+ * Externally trigger/set Person detected
52
+ */
53
+ setPersonDetected(): void;
50
54
  }