hoffmation-base 3.2.3-alpha.0 → 3.2.3-alpha.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.
Files changed (39) hide show
  1. package/lib/action/dingSensorAction.d.ts +16 -0
  2. package/lib/action/dingSensorAction.js +15 -0
  3. package/lib/action/index.d.ts +1 -0
  4. package/lib/action/index.js +3 -1
  5. package/lib/devices/DoorDevice.d.ts +38 -0
  6. package/lib/devices/DoorDevice.js +104 -0
  7. package/lib/devices/dachs/dachs.js +6 -4
  8. package/lib/devices/devices.d.ts +6 -3
  9. package/lib/devices/index.d.ts +1 -0
  10. package/lib/devices/index.js +1 -0
  11. package/lib/devices/unifi/index.d.ts +2 -0
  12. package/lib/devices/unifi/index.js +2 -0
  13. package/lib/devices/unifi/own-unifi-door.d.ts +15 -0
  14. package/lib/devices/unifi/own-unifi-door.js +48 -0
  15. package/lib/devices/unifi/unifi-access.d.ts +19 -0
  16. package/lib/devices/unifi/unifi-access.js +98 -0
  17. package/lib/devices/unifi/unifi-logger.d.ts +10 -0
  18. package/lib/devices/unifi/unifi-logger.js +31 -0
  19. package/lib/devices/unifi/unifi-protect.js +2 -23
  20. package/lib/enums/DeviceCapability.d.ts +2 -1
  21. package/lib/enums/DeviceCapability.js +1 -0
  22. package/lib/enums/commandType.d.ts +2 -1
  23. package/lib/enums/commandType.js +1 -0
  24. package/lib/enums/deviceType.d.ts +1 -0
  25. package/lib/enums/deviceType.js +1 -0
  26. package/lib/enums/logSource.d.ts +2 -1
  27. package/lib/enums/logSource.js +1 -0
  28. package/lib/index.js +5 -1
  29. package/lib/interfaces/baseDevices/iDoorDevice.d.ts +33 -0
  30. package/lib/interfaces/baseDevices/iDoorDevice.js +2 -0
  31. package/lib/interfaces/baseDevices/index.d.ts +1 -0
  32. package/lib/interfaces/deviceSettings/iDoorSettings.d.ts +18 -0
  33. package/lib/interfaces/deviceSettings/iDoorSettings.js +2 -0
  34. package/lib/interfaces/deviceSettings/index.d.ts +1 -0
  35. package/lib/interfaces/iUnifiProtectOptions.d.ts +4 -0
  36. package/lib/settingsObjects/deviceSettings/doorSettings.d.ts +8 -0
  37. package/lib/settingsObjects/deviceSettings/doorSettings.js +21 -0
  38. package/lib/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +4 -2
@@ -0,0 +1,16 @@
1
+ import { BaseAction } from './baseAction';
2
+ import { CommandType } from '../enums';
3
+ import { iDoorDevice } from '../interfaces';
4
+ export declare class DingSensorAction extends BaseAction {
5
+ /** @inheritDoc */
6
+ type: CommandType;
7
+ /**
8
+ * Whether ding was detected or cleared. (True = detected, False = cleared)
9
+ */
10
+ readonly dingOccured: boolean;
11
+ /**
12
+ * The door that triggered the action
13
+ */
14
+ readonly sensor: iDoorDevice;
15
+ constructor(sensor: iDoorDevice);
16
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DingSensorAction = void 0;
4
+ const baseAction_1 = require("./baseAction");
5
+ const enums_1 = require("../enums");
6
+ class DingSensorAction extends baseAction_1.BaseAction {
7
+ constructor(sensor) {
8
+ super(enums_1.CommandSource.Automatic, `${sensor.customName} ${sensor.dingActive ? 'detected' : 'cleared'} ding`);
9
+ /** @inheritDoc */
10
+ this.type = enums_1.CommandType.DingSensorAction;
11
+ this.dingOccured = sensor.dingActive;
12
+ this.sensor = sensor;
13
+ }
14
+ }
15
+ exports.DingSensorAction = DingSensorAction;
@@ -9,3 +9,4 @@ export { ActuatorChangeAction } from './actuatorChangeAction';
9
9
  export { BatteryLevelChangeAction } from './batteryLevelChangeAction';
10
10
  export { PresenceGroupAnyMovementAction } from './presenceGroupAnyMovementAction';
11
11
  export { HandleChangeAction } from './handleChangeAction';
12
+ export { DingSensorAction } from './dingSensorAction';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HandleChangeAction = exports.PresenceGroupAnyMovementAction = exports.BatteryLevelChangeAction = exports.ActuatorChangeAction = exports.TemperatureSensorChangeAction = exports.ShutterPositionChangedAction = exports.PresenceGroupFirstEnterAction = exports.PresenceGroupLastLeftAction = exports.MotionSensorAction = exports.HumiditySensorChangeAction = exports.BaseAction = void 0;
3
+ exports.DingSensorAction = exports.HandleChangeAction = exports.PresenceGroupAnyMovementAction = exports.BatteryLevelChangeAction = exports.ActuatorChangeAction = exports.TemperatureSensorChangeAction = exports.ShutterPositionChangedAction = exports.PresenceGroupFirstEnterAction = exports.PresenceGroupLastLeftAction = exports.MotionSensorAction = exports.HumiditySensorChangeAction = exports.BaseAction = void 0;
4
4
  var baseAction_1 = require("./baseAction");
5
5
  Object.defineProperty(exports, "BaseAction", { enumerable: true, get: function () { return baseAction_1.BaseAction; } });
6
6
  var humiditySensorChangeAction_1 = require("./humiditySensorChangeAction");
@@ -23,3 +23,5 @@ var presenceGroupAnyMovementAction_1 = require("./presenceGroupAnyMovementAction
23
23
  Object.defineProperty(exports, "PresenceGroupAnyMovementAction", { enumerable: true, get: function () { return presenceGroupAnyMovementAction_1.PresenceGroupAnyMovementAction; } });
24
24
  var handleChangeAction_1 = require("./handleChangeAction");
25
25
  Object.defineProperty(exports, "HandleChangeAction", { enumerable: true, get: function () { return handleChangeAction_1.HandleChangeAction; } });
26
+ var dingSensorAction_1 = require("./dingSensorAction");
27
+ Object.defineProperty(exports, "DingSensorAction", { enumerable: true, get: function () { return dingSensorAction_1.DingSensorAction; } });
@@ -0,0 +1,38 @@
1
+ import { LogDebugType, LogLevel } from '../enums';
2
+ import { DeviceInfo } from './DeviceInfo';
3
+ import { RoomBaseDevice } from './RoomBaseDevice';
4
+ import { iDoorDevice, iDoorSettings } from '../interfaces';
5
+ import { DingSensorAction } from '../action';
6
+ export declare abstract class DoorDevice extends RoomBaseDevice implements iDoorDevice {
7
+ /** @inheritDoc */
8
+ settings: iDoorSettings;
9
+ /**
10
+ * The human readable name of this device
11
+ */
12
+ readonly name: string;
13
+ /** @inheritDoc */
14
+ dingsToday: number;
15
+ protected _lastDing: number;
16
+ protected _dingCallback: Array<(action: DingSensorAction) => void>;
17
+ protected _dingActive: boolean;
18
+ protected _lastUpdate: Date;
19
+ private _dingActiveFallbackTimeout;
20
+ protected constructor(name: string, roomName: string);
21
+ get lastUpdate(): Date;
22
+ /** @inheritDoc */
23
+ get dingActive(): boolean;
24
+ /** @inheritDoc */
25
+ get personDetected(): boolean;
26
+ /** @inheritDoc */
27
+ get info(): DeviceInfo;
28
+ /** @inheritDoc */
29
+ get timeSinceDing(): number;
30
+ /** @inheritDoc */
31
+ get id(): string;
32
+ /** @inheritDoc */
33
+ addDingCallback(pCallback: (action: DingSensorAction) => void): void;
34
+ log(level: LogLevel, message: string, debugType?: LogDebugType): void;
35
+ protected onNewDingActiveValue(newValue: boolean): void;
36
+ protected abstract resetDingActiveState(): void;
37
+ private resetDingActiveFallbackTimeout;
38
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DoorDevice = void 0;
4
+ const enums_1 = require("../enums");
5
+ const DeviceInfo_1 = require("./DeviceInfo");
6
+ const devices_1 = require("./devices");
7
+ const utils_1 = require("../utils");
8
+ const logging_1 = require("../logging");
9
+ const RoomBaseDevice_1 = require("./RoomBaseDevice");
10
+ const doorSettings_1 = require("../settingsObjects/deviceSettings/doorSettings");
11
+ const services_1 = require("../services");
12
+ const action_1 = require("../action");
13
+ class DoorDevice extends RoomBaseDevice_1.RoomBaseDevice {
14
+ constructor(name, roomName) {
15
+ const info = new DeviceInfo_1.DeviceInfo();
16
+ info.fullName = `Door ${roomName} ${name}`;
17
+ info.customName = `Door ${name}`;
18
+ info.room = roomName;
19
+ const allDevicesKey = `door-${roomName}-${name}`;
20
+ info.allDevicesKey = allDevicesKey;
21
+ super(info, enums_1.DeviceType.Door);
22
+ /** @inheritDoc */
23
+ this.settings = new doorSettings_1.DoorSettings();
24
+ /** @inheritDoc */
25
+ this.dingsToday = 0;
26
+ this._lastDing = 0;
27
+ this._dingCallback = [];
28
+ this._dingActive = false;
29
+ this._lastUpdate = new Date(0);
30
+ this._dingActiveFallbackTimeout = null;
31
+ // this.jsonOmitKeys.push('_lastImage');
32
+ this.deviceCapabilities.push(enums_1.DeviceCapability.doorbell);
33
+ this.name = name;
34
+ devices_1.Devices.alLDevices[allDevicesKey] = this;
35
+ }
36
+ get lastUpdate() {
37
+ return this._lastUpdate;
38
+ }
39
+ /** @inheritDoc */
40
+ get dingActive() {
41
+ return this._dingActive;
42
+ }
43
+ /** @inheritDoc */
44
+ get personDetected() {
45
+ return this._dingActive;
46
+ }
47
+ /** @inheritDoc */
48
+ get info() {
49
+ return this._info;
50
+ }
51
+ /** @inheritDoc */
52
+ get timeSinceDing() {
53
+ return Math.round((utils_1.Utils.nowMS() - this._lastDing) / 1000);
54
+ }
55
+ /** @inheritDoc */
56
+ get id() {
57
+ var _a;
58
+ return (_a = this.info.allDevicesKey) !== null && _a !== void 0 ? _a : `door-${this.info.room}-${this.info.customName}`;
59
+ }
60
+ /** @inheritDoc */
61
+ addDingCallback(pCallback) {
62
+ this._dingCallback.push(pCallback);
63
+ }
64
+ log(level, message, debugType = enums_1.LogDebugType.None) {
65
+ var _a, _b;
66
+ logging_1.ServerLogService.writeLog(level, `${this.name}: ${message}`, {
67
+ debugType: debugType,
68
+ room: (_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.roomName) !== null && _b !== void 0 ? _b : '',
69
+ deviceId: this.name,
70
+ deviceName: this.name,
71
+ });
72
+ }
73
+ onNewDingActiveValue(newValue) {
74
+ this.log(enums_1.LogLevel.Debug, `Update for DingActive to value: ${newValue}`);
75
+ this._dingActive = newValue;
76
+ if (newValue) {
77
+ this.resetDingActiveFallbackTimeout();
78
+ }
79
+ else {
80
+ return;
81
+ }
82
+ this._lastDing = utils_1.Utils.nowMS();
83
+ this.dingsToday++;
84
+ this.log(enums_1.LogLevel.Trace, `This is ding no. ${this.dingsToday}`);
85
+ if (this.settings.alertDingOnTelegram && this._dingActive) {
86
+ services_1.TelegramService.sendMessageToSubscriber(`${this.name} detected ding`);
87
+ }
88
+ for (const c of this._dingCallback) {
89
+ c(new action_1.DingSensorAction(this));
90
+ }
91
+ }
92
+ resetDingActiveFallbackTimeout() {
93
+ if (this._dingActiveFallbackTimeout !== null) {
94
+ clearTimeout(this._dingActiveFallbackTimeout);
95
+ this._dingActiveFallbackTimeout = null;
96
+ }
97
+ this._dingActiveFallbackTimeout = utils_1.Utils.guardedTimeout(() => {
98
+ this._dingActiveFallbackTimeout = null;
99
+ this._dingActive = false;
100
+ this.resetDingActiveState();
101
+ }, 10000, this);
102
+ }
103
+ }
104
+ exports.DoorDevice = DoorDevice;
@@ -280,7 +280,7 @@ class Dachs extends RoomBaseDevice_1.RoomBaseDevice {
280
280
  this.heatingRod.setActuator(setAction);
281
281
  }
282
282
  shouldDachsBeStarted(action, batteryLevel) {
283
- var _a, _b;
283
+ var _a, _b, _c;
284
284
  const dayType = services_1.TimeCallbackService.dayType(new models_1.SunTimeOffsets());
285
285
  if (this.blockDachsStart !== undefined) {
286
286
  if ((dayType === enums_1.TimeOfDay.Daylight || dayType === enums_1.TimeOfDay.BeforeSunrise) &&
@@ -302,11 +302,13 @@ class Dachs extends RoomBaseDevice_1.RoomBaseDevice {
302
302
  const liftAction = new command_1.ActuatorSetStateCommand(action, false, `Battery reached ${batteryLevel}%, Dachs is now allowed to run if needed`, null);
303
303
  this.blockDachsStart.setActuator(liftAction);
304
304
  }
305
- else if (utils_1.Utils.nowMS() - this._blockStarted > 180 * 60 * 60) {
305
+ else if (utils_1.Utils.nowMS() - this._blockStarted > 180 * 60 * 60 &&
306
+ (((_a = settings_service_1.SettingsService.settings.heaterSettings) === null || _a === void 0 ? void 0 : _a.mode) === enums_1.HeatingMode.Winter ||
307
+ this.warmWaterDachsAlternativeActuator === undefined)) {
306
308
  const liftAction = new command_1.ActuatorSetStateCommand(action, false, `Battery is at ${batteryLevel}%, but Dachs wasn't allowed to run for 3 hours, Dachs is now allowed to run if needed`, null);
307
309
  this.blockDachsStart.setActuator(liftAction);
308
310
  }
309
- else if (((_a = settings_service_1.SettingsService.settings.heaterSettings) === null || _a === void 0 ? void 0 : _a.mode) === enums_1.HeatingMode.Winter &&
311
+ else if (((_b = settings_service_1.SettingsService.settings.heaterSettings) === null || _b === void 0 ? void 0 : _b.mode) === enums_1.HeatingMode.Winter &&
310
312
  this.heatStorageTempSensor.temperatureSensor.temperature < this.settings.winterMinimumPreNightHeatStorageTemp &&
311
313
  utils_1.Utils.dateByTimeSpan(21, 30) < new Date()) {
312
314
  const liftWinterAction = new command_1.ActuatorSetStateCommand(action, false, `Battery at ${batteryLevel}% but it is winter, we are nearing night and heat storage is kinda cold: Dachs is now allowed to run if needed`, null);
@@ -321,7 +323,7 @@ class Dachs extends RoomBaseDevice_1.RoomBaseDevice {
321
323
  // We are already running
322
324
  return false;
323
325
  }
324
- if (((_b = settings_service_1.SettingsService.settings.heaterSettings) === null || _b === void 0 ? void 0 : _b.mode) === enums_1.HeatingMode.Winter &&
326
+ if (((_c = settings_service_1.SettingsService.settings.heaterSettings) === null || _c === void 0 ? void 0 : _c.mode) === enums_1.HeatingMode.Winter &&
325
327
  this.heatStorageTempSensor.temperatureSensor.temperature < this.settings.winterMinimumHeatStorageTemp) {
326
328
  // It is winter and heat storage is kinda cold --> Start
327
329
  return true;
@@ -1,7 +1,6 @@
1
- import { iBaseDevice, iConfig, iEnergyManager, iRoomImportEnforcer, iTemperatureCollector } from '../interfaces';
1
+ import { iBaseDevice, iConfig, iDeviceConfig, iEnergyManager, iRoomImportEnforcer, iTemperatureCollector } from '../interfaces';
2
2
  import { Dachs } from './dachs';
3
- import { iDeviceConfig } from '../interfaces/iDeviceConfig';
4
- import { UnifiProtect } from './unifi';
3
+ import { UnifiAccess, UnifiProtect } from './unifi';
5
4
  export declare class Devices {
6
5
  /**
7
6
  * A constant for the identifier of HM-IP Adapter devices
@@ -64,6 +63,10 @@ export declare class Devices {
64
63
  * A reference to the Unifi Protect device
65
64
  */
66
65
  static unifiProtect?: UnifiProtect;
66
+ /**
67
+ * A reference to the Unifi Access device
68
+ */
69
+ static unifiAccess?: UnifiAccess;
67
70
  constructor(pDeviceData: {
68
71
  [id: string]: iDeviceConfig;
69
72
  }, pRoomImportEnforcer?: iRoomImportEnforcer, config?: iConfig);
@@ -20,6 +20,7 @@ export * from './device-list';
20
20
  export * from './DeviceInfo';
21
21
  export * from './devices';
22
22
  export * from './deviceUpdater';
23
+ export * from './DoorDevice';
23
24
  export * from './Griffe';
24
25
  export * from './Heizgruppen';
25
26
  export * from './mqtt';
@@ -37,6 +37,7 @@ __exportStar(require("./device-list"), exports);
37
37
  __exportStar(require("./DeviceInfo"), exports);
38
38
  __exportStar(require("./devices"), exports);
39
39
  __exportStar(require("./deviceUpdater"), exports);
40
+ __exportStar(require("./DoorDevice"), exports);
40
41
  __exportStar(require("./Griffe"), exports);
41
42
  __exportStar(require("./Heizgruppen"), exports);
42
43
  __exportStar(require("./mqtt"), exports);
@@ -1,2 +1,4 @@
1
1
  export * from './own-unifi-camera';
2
2
  export * from './unifi-protect';
3
+ export * from './unifi-access';
4
+ export * from './own-unifi-door';
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./own-unifi-camera"), exports);
18
18
  __exportStar(require("./unifi-protect"), exports);
19
+ __exportStar(require("./unifi-access"), exports);
20
+ __exportStar(require("./own-unifi-door"), exports);
@@ -0,0 +1,15 @@
1
+ import { AccessDeviceConfig, AccessEventPacket } from 'unifi-access';
2
+ import { DoorDevice } from '../DoorDevice';
3
+ export declare class OwnUnifiDoor extends DoorDevice {
4
+ /**
5
+ * The name of the unifi device as written in Unifi-Access
6
+ */
7
+ readonly unifiDeviceName: string;
8
+ private _config;
9
+ private _lastDoorbellRingRequestId;
10
+ constructor(name: string, roomName: string, unifiDeviceName: string);
11
+ update(packet: AccessEventPacket): void;
12
+ initialize(data: AccessDeviceConfig): void;
13
+ protected resetDingActiveState(): void;
14
+ private checkForDingUpdate;
15
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OwnUnifiDoor = void 0;
4
+ const DoorDevice_1 = require("../DoorDevice");
5
+ const enums_1 = require("../../enums");
6
+ class OwnUnifiDoor extends DoorDevice_1.DoorDevice {
7
+ constructor(name, roomName, unifiDeviceName) {
8
+ super(name, roomName);
9
+ // @ts-expect-error Config wird später verwendet
10
+ this._config = null;
11
+ this._lastDoorbellRingRequestId = null;
12
+ this.unifiDeviceName = unifiDeviceName;
13
+ }
14
+ update(packet) {
15
+ this.checkForDingUpdate(packet);
16
+ this._lastUpdate = new Date();
17
+ }
18
+ initialize(data) {
19
+ this._config = data;
20
+ }
21
+ resetDingActiveState() {
22
+ // Nothing
23
+ }
24
+ checkForDingUpdate(packet) {
25
+ switch (packet.event) {
26
+ case 'access.data.device.remote_unlock':
27
+ this.log(enums_1.LogLevel.Debug, `Device ${this.unifiDeviceName} was unlocked`);
28
+ return;
29
+ case 'access.remote_view':
30
+ const ringEvent = packet.data;
31
+ this._lastDoorbellRingRequestId = ringEvent.request_id;
32
+ this.onNewDingActiveValue(true);
33
+ return;
34
+ case 'access.remote_view.change':
35
+ const cancelEvent = packet.data;
36
+ if (cancelEvent.remote_call_request_id === this._lastDoorbellRingRequestId &&
37
+ this._lastDoorbellRingRequestId !== null) {
38
+ this._lastDoorbellRingRequestId = null;
39
+ this.onNewDingActiveValue(false);
40
+ }
41
+ return;
42
+ case 'access.data.device.update':
43
+ default:
44
+ return;
45
+ }
46
+ }
47
+ }
48
+ exports.OwnUnifiDoor = OwnUnifiDoor;
@@ -0,0 +1,19 @@
1
+ import { iDisposable, iUnifiProtectOptions } from '../../interfaces';
2
+ import { OwnUnifiDoor } from './own-unifi-door';
3
+ export declare class UnifiAccess implements iDisposable {
4
+ /**
5
+ * Mapping for own devices
6
+ */
7
+ static readonly ownDoors: Map<string, OwnUnifiDoor>;
8
+ private readonly unifiLogger;
9
+ private readonly _api;
10
+ private _idMap;
11
+ private _lastUpdate;
12
+ constructor(settings: iUnifiProtectOptions);
13
+ static addDevice(door: OwnUnifiDoor): void;
14
+ dispose(): void;
15
+ private reconnect;
16
+ private initialize;
17
+ private onMessage;
18
+ private initializeDevice;
19
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnifiAccess = void 0;
4
+ const unifi_access_1 = require("unifi-access");
5
+ const enums_1 = require("../../enums");
6
+ const logging_1 = require("../../logging");
7
+ const utils_1 = require("../../utils");
8
+ const unifi_logger_1 = require("./unifi-logger");
9
+ class UnifiAccess {
10
+ constructor(settings) {
11
+ this.unifiLogger = new unifi_logger_1.UnifiLogger(enums_1.LogSource.UnifiAccess);
12
+ // private _deviceStates: Map<string, unknown> = new Map<string, unknown>();
13
+ this._idMap = new Map();
14
+ this._lastUpdate = new Date(0);
15
+ this._api = new unifi_access_1.AccessApi(this.unifiLogger);
16
+ this.reconnect(settings);
17
+ utils_1.Utils.guardedInterval(() => {
18
+ if (new Date().getTime() - this._lastUpdate.getTime() < 180 * 1000) {
19
+ // We had an update within the last 3 minutes --> no need to reconnect
20
+ return;
21
+ }
22
+ this.reconnect(settings);
23
+ }, 5 * 60 * 1000);
24
+ }
25
+ static addDevice(door) {
26
+ this.ownDoors.set(door.unifiDeviceName, door);
27
+ }
28
+ dispose() {
29
+ this._api.logout();
30
+ }
31
+ reconnect(settings) {
32
+ this._api
33
+ .login(settings.nvrAddress, settings.usernameAccess, settings.password)
34
+ .then((_loggedIn) => {
35
+ this.initialize();
36
+ })
37
+ .catch((error) => {
38
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Error, `Unifi-Protect: Login failed: ${error}`);
39
+ });
40
+ }
41
+ async initialize() {
42
+ this.unifiLogger.info('Unifi-Access: Login successful');
43
+ const bootstrap = await this._api.getBootstrap();
44
+ if (!bootstrap || !this._api.bootstrap) {
45
+ this.unifiLogger.error('Unifi-Access: Bootstrap failed');
46
+ return;
47
+ }
48
+ // const info: AccessBootstrapConfigInterface = this._api.bootstrap;
49
+ if (this._api.devices === null) {
50
+ this.unifiLogger.error('Unifi-Access: No devices found');
51
+ return;
52
+ }
53
+ for (const device of this._api.devices) {
54
+ this.initializeDevice(device);
55
+ }
56
+ this._api.on('message', this.onMessage.bind(this));
57
+ }
58
+ onMessage(packet) {
59
+ const deviceConfig = packet.data;
60
+ this._lastUpdate = new Date();
61
+ switch (deviceConfig.device_type) {
62
+ case 'nvr':
63
+ break;
64
+ default:
65
+ // Lookup the device.
66
+ const id = packet.event_object_id;
67
+ const ownName = this._idMap.get(id);
68
+ if (!ownName) {
69
+ break;
70
+ }
71
+ const ownDoor = UnifiAccess.ownDoors.get(ownName);
72
+ if (ownDoor !== undefined) {
73
+ ownDoor.update(packet);
74
+ break;
75
+ }
76
+ break;
77
+ }
78
+ // Update the internal list we maintain.
79
+ // if (deviceConfig) {
80
+ // this._deviceStates.set(packet.header.id, Object.assign(this._deviceStates.get(packet.header.id) ?? {}, payload));
81
+ // }
82
+ }
83
+ initializeDevice(data) {
84
+ if (!UnifiAccess.ownDoors.has(data.alias)) {
85
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, `Unifi-Protect: Ignoring camera ${data.name}`);
86
+ return;
87
+ }
88
+ const door = UnifiAccess.ownDoors.get(data.alias);
89
+ door.initialize(data);
90
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, `Unifi-Access: ${data.name} (re)initialized`);
91
+ this._idMap.set(data.unique_id, data.alias);
92
+ }
93
+ }
94
+ exports.UnifiAccess = UnifiAccess;
95
+ /**
96
+ * Mapping for own devices
97
+ */
98
+ UnifiAccess.ownDoors = new Map();
@@ -0,0 +1,10 @@
1
+ import { ProtectLogging } from 'unifi-protect';
2
+ import { LogSource } from '../../enums';
3
+ export declare class UnifiLogger implements ProtectLogging {
4
+ private readonly source;
5
+ constructor(source: LogSource);
6
+ debug(message: string, ..._parameters: unknown[]): void;
7
+ error(message: string, ..._parameters: unknown[]): void;
8
+ info(message: string, ..._parameters: unknown[]): void;
9
+ warn(message: string, ..._parameters: unknown[]): void;
10
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnifiLogger = void 0;
4
+ const logging_1 = require("../../logging");
5
+ const enums_1 = require("../../enums");
6
+ class UnifiLogger {
7
+ constructor(source) {
8
+ this.source = source;
9
+ }
10
+ debug(message, ..._parameters) {
11
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Debug, message, {
12
+ source: this.source,
13
+ });
14
+ }
15
+ error(message, ..._parameters) {
16
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Error, message, {
17
+ source: this.source,
18
+ });
19
+ }
20
+ info(message, ..._parameters) {
21
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, message, {
22
+ source: this.source,
23
+ });
24
+ }
25
+ warn(message, ..._parameters) {
26
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Warn, message, {
27
+ source: this.source,
28
+ });
29
+ }
30
+ }
31
+ exports.UnifiLogger = UnifiLogger;
@@ -5,9 +5,10 @@ const unifi_protect_1 = require("unifi-protect");
5
5
  const enums_1 = require("../../enums");
6
6
  const logging_1 = require("../../logging");
7
7
  const utils_1 = require("../../utils");
8
+ const unifi_logger_1 = require("./unifi-logger");
8
9
  class UnifiProtect {
9
10
  constructor(settings) {
10
- this.unifiLogger = new UnifiLogger();
11
+ this.unifiLogger = new unifi_logger_1.UnifiLogger(enums_1.LogSource.UnifiProtect);
11
12
  this._deviceStates = new Map();
12
13
  this._idMap = new Map();
13
14
  this._lastUpdate = new Date(0);
@@ -95,25 +96,3 @@ exports.UnifiProtect = UnifiProtect;
95
96
  * Mapping for own devices
96
97
  */
97
98
  UnifiProtect.ownCameras = new Map();
98
- class UnifiLogger {
99
- debug(message, ..._parameters) {
100
- logging_1.ServerLogService.writeLog(enums_1.LogLevel.Debug, message, {
101
- source: enums_1.LogSource.UnifiProtect,
102
- });
103
- }
104
- error(message, ..._parameters) {
105
- logging_1.ServerLogService.writeLog(enums_1.LogLevel.Error, message, {
106
- source: enums_1.LogSource.UnifiProtect,
107
- });
108
- }
109
- info(message, ..._parameters) {
110
- logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, message, {
111
- source: enums_1.LogSource.UnifiProtect,
112
- });
113
- }
114
- warn(message, ..._parameters) {
115
- logging_1.ServerLogService.writeLog(enums_1.LogLevel.Warn, message, {
116
- source: enums_1.LogSource.UnifiProtect,
117
- });
118
- }
119
- }
@@ -26,5 +26,6 @@ export declare enum DeviceCapability {
26
26
  trackableDevice = 102,
27
27
  scene = 103,
28
28
  blockAutomatic = 104,
29
- camera = 105
29
+ camera = 105,
30
+ doorbell = 106
30
31
  }
@@ -31,4 +31,5 @@ var DeviceCapability;
31
31
  DeviceCapability[DeviceCapability["scene"] = 103] = "scene";
32
32
  DeviceCapability[DeviceCapability["blockAutomatic"] = 104] = "blockAutomatic";
33
33
  DeviceCapability[DeviceCapability["camera"] = 105] = "camera";
34
+ DeviceCapability[DeviceCapability["doorbell"] = 106] = "doorbell";
34
35
  })(DeviceCapability || (exports.DeviceCapability = DeviceCapability = {}));
@@ -32,5 +32,6 @@ export declare enum CommandType {
32
32
  WindowRestoreDesiredPositionCommand = "WindowRestoreDesiredPositionCommand",
33
33
  WindowSetDesiredPositionCommand = "WindowSetDesiredPositionCommand",
34
34
  WindowSetRolloByWeatherStatusCommand = "WindowSetRolloByWeatherStatusCommand",
35
- WledSetLightCommand = "WledSetLightCommand"
35
+ WledSetLightCommand = "WledSetLightCommand",
36
+ DingSensorAction = "DingSensorAction"
36
37
  }
@@ -37,4 +37,5 @@ var CommandType;
37
37
  CommandType["WindowSetDesiredPositionCommand"] = "WindowSetDesiredPositionCommand";
38
38
  CommandType["WindowSetRolloByWeatherStatusCommand"] = "WindowSetRolloByWeatherStatusCommand";
39
39
  CommandType["WledSetLightCommand"] = "WledSetLightCommand";
40
+ CommandType["DingSensorAction"] = "DingSensorAction";
40
41
  })(CommandType || (exports.CommandType = CommandType = {}));
@@ -56,6 +56,7 @@ export declare enum DeviceType {
56
56
  Espresense = 4001,
57
57
  TrackableDevice = 4002,
58
58
  Camera = 6001,
59
+ Door = 6002,
59
60
  Victron = 7001,
60
61
  Dachs = 7002,
61
62
  DachsWarmWaterTemperature = 7003
@@ -60,6 +60,7 @@ var DeviceType;
60
60
  DeviceType[DeviceType["Espresense"] = 4001] = "Espresense";
61
61
  DeviceType[DeviceType["TrackableDevice"] = 4002] = "TrackableDevice";
62
62
  DeviceType[DeviceType["Camera"] = 6001] = "Camera";
63
+ DeviceType[DeviceType["Door"] = 6002] = "Door";
63
64
  DeviceType[DeviceType["Victron"] = 7001] = "Victron";
64
65
  DeviceType[DeviceType["Dachs"] = 7002] = "Dachs";
65
66
  DeviceType[DeviceType["DachsWarmWaterTemperature"] = 7003] = "DachsWarmWaterTemperature";
@@ -1,5 +1,6 @@
1
1
  export declare enum LogSource {
2
2
  NotSpecified = 0,
3
3
  News = 1,
4
- UnifiProtect = 2
4
+ UnifiProtect = 2,
5
+ UnifiAccess = 3
5
6
  }
@@ -6,4 +6,5 @@ var LogSource;
6
6
  LogSource[LogSource["NotSpecified"] = 0] = "NotSpecified";
7
7
  LogSource[LogSource["News"] = 1] = "News";
8
8
  LogSource[LogSource["UnifiProtect"] = 2] = "UnifiProtect";
9
+ LogSource[LogSource["UnifiAccess"] = 3] = "UnifiAccess";
9
10
  })(LogSource || (exports.LogSource = LogSource = {}));
package/lib/index.js CHANGED
@@ -89,11 +89,15 @@ class HoffmationBase {
89
89
  new services_1.UnifiRouter(settings_service_1.SettingsService.settings.unifiSettings.loginOptions);
90
90
  }
91
91
  utils_1.Utils.guardedFunction(() => {
92
- var _a;
92
+ var _a, _b;
93
93
  if ((_a = settings_service_1.SettingsService.settings.unifiSettings) === null || _a === void 0 ? void 0 : _a.nvrOptions) {
94
94
  logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Unifi Protect settings detected --> initializing');
95
95
  devices_1.Devices.unifiProtect = new devices_1.UnifiProtect(settings_service_1.SettingsService.settings.unifiSettings.nvrOptions);
96
96
  }
97
+ if ((_b = settings_service_1.SettingsService.settings.unifiSettings) === null || _b === void 0 ? void 0 : _b.nvrOptions) {
98
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Unifi Access settings detected --> initializing');
99
+ devices_1.Devices.unifiAccess = new devices_1.UnifiAccess(settings_service_1.SettingsService.settings.unifiSettings.nvrOptions);
100
+ }
97
101
  }, this);
98
102
  services_1.TimeCallbackService.init();
99
103
  logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Hoffmation-Base First Initializations finished');