hoffmation-base 3.1.3 → 3.2.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.
@@ -35,6 +35,8 @@ export declare abstract class CameraDevice implements iCameraDevice {
35
35
  private _personDetectFallbackTimeout;
36
36
  private _movementDetectFallbackTimeout;
37
37
  private _dogDetectFallbackTimeout;
38
+ protected _lastUpdate: Date;
39
+ get lastUpdate(): Date;
38
40
  protected constructor(name: string, roomName: string);
39
41
  /** @inheritDoc */
40
42
  get lastImage(): string;
@@ -16,6 +16,9 @@ const utils_1 = require("../utils");
16
16
  const api_1 = require("../api");
17
17
  const logging_1 = require("../logging");
18
18
  class CameraDevice {
19
+ get lastUpdate() {
20
+ return this._lastUpdate;
21
+ }
19
22
  constructor(name, roomName) {
20
23
  var _a;
21
24
  /** @inheritDoc */
@@ -37,6 +40,7 @@ class CameraDevice {
37
40
  this._personDetectFallbackTimeout = null;
38
41
  this._movementDetectFallbackTimeout = null;
39
42
  this._dogDetectFallbackTimeout = null;
43
+ this._lastUpdate = new Date(0);
40
44
  this.name = name;
41
45
  this._info = new DeviceInfo_1.DeviceInfo();
42
46
  this._info.fullName = `Camera ${roomName} ${name}`;
@@ -45,7 +49,7 @@ class CameraDevice {
45
49
  this._info.allDevicesKey = `camera-${roomName}-${name}`;
46
50
  devices_1.Devices.alLDevices[this._info.allDevicesKey] = this;
47
51
  this.persistDeviceInfo();
48
- this.loadDeviceSettings();
52
+ utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 4500, this);
49
53
  if (!services_1.Persistence.anyDboActive) {
50
54
  this._initialized = true;
51
55
  }
@@ -57,6 +57,7 @@ class BlueIrisCameraDevice extends CameraDevice_1.CameraDevice {
57
57
  this.onNewImageSnapshot(state.val);
58
58
  break;
59
59
  }
60
+ this._lastUpdate = new Date();
60
61
  }
61
62
  resetPersonDetectedState() {
62
63
  var _a;
@@ -55,7 +55,7 @@ class Dachs {
55
55
  this._influxClient = new lib_1.DachsInfluxClient(options.influxDb);
56
56
  }
57
57
  this.persistDeviceInfo();
58
- this.loadDeviceSettings();
58
+ utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 4500, this);
59
59
  const modifiedOptions = lodash_1.default.cloneDeep(options);
60
60
  modifiedOptions.connectionOptions.resultConfig = {
61
61
  flatten: true,
@@ -32,7 +32,7 @@ class DachsTemperatureSensor {
32
32
  devices_1.Devices.alLDevices[this._info.allDevicesKey] = this;
33
33
  devices_1.Devices.temperatureWarmWater = this;
34
34
  this.persistDeviceInfo();
35
- utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 200, this);
35
+ utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 4500, this);
36
36
  }
37
37
  /** @inheritDoc */
38
38
  get customName() {
@@ -47,7 +47,7 @@ class OwnGoveeDevice {
47
47
  index_1.Devices.alLDevices[`govee-${roomName}-${deviceId}`] = this;
48
48
  this.persistDeviceInfo();
49
49
  this.blockAutomationHandler = new blockAutomaticHandler_1.BlockAutomaticHandler(this.restoreTargetAutomaticValue.bind(this), this.log.bind(this));
50
- utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 300, this);
50
+ utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 4800, this);
51
51
  }
52
52
  get color() {
53
53
  return this._color;
@@ -23,6 +23,7 @@ class OwnUnifiCamera extends index_1.CameraDevice {
23
23
  */
24
24
  update(packet) {
25
25
  this.checkForMotionUpdate(packet);
26
+ this._lastUpdate = new Date();
26
27
  }
27
28
  checkForMotionUpdate(packet) {
28
29
  var _a;
@@ -9,7 +9,9 @@ export declare class UnifiProtect implements iDisposable {
9
9
  static readonly ownCameras: Map<string, OwnUnifiCamera>;
10
10
  private _deviceStates;
11
11
  private _idMap;
12
+ private _lastUpdate;
12
13
  constructor(settings: iUnifiProtectOptions);
14
+ private reconnect;
13
15
  dispose(): void;
14
16
  static addDevice(camera: OwnUnifiCamera): void;
15
17
  private initialize;
@@ -4,12 +4,24 @@ exports.UnifiProtect = void 0;
4
4
  const unifi_protect_1 = require("unifi-protect");
5
5
  const enums_1 = require("../../enums");
6
6
  const logging_1 = require("../../logging");
7
+ const utils_1 = require("../../utils");
7
8
  class UnifiProtect {
8
9
  constructor(settings) {
9
10
  this.unifiLogger = new UnifiLogger();
10
11
  this._deviceStates = new Map();
11
12
  this._idMap = new Map();
13
+ this._lastUpdate = new Date(0);
12
14
  this._api = new unifi_protect_1.ProtectApi(this.unifiLogger);
15
+ this.reconnect(settings);
16
+ utils_1.Utils.guardedInterval(() => {
17
+ if (new Date().getTime() - this._lastUpdate.getTime() < 180 * 1000) {
18
+ // We had an update within the last 3 minutes --> no need to reconnect
19
+ return;
20
+ }
21
+ this.reconnect(settings);
22
+ }, 5 * 60 * 1000);
23
+ }
24
+ reconnect(settings) {
13
25
  this._api
14
26
  .login(settings.nvrAddress, settings.username, settings.password)
15
27
  .then((_loggedIn) => {
@@ -41,6 +53,7 @@ class UnifiProtect {
41
53
  onMessage(packet) {
42
54
  var _a, _b;
43
55
  const payload = packet.payload;
56
+ this._lastUpdate = new Date();
44
57
  switch (packet.header.modelKey) {
45
58
  case 'nvr':
46
59
  break;
@@ -67,12 +80,13 @@ class UnifiProtect {
67
80
  }
68
81
  }
69
82
  initializeCamera(data) {
70
- logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, `Unifi-Protect: Camera ${data.name} initialized`);
71
83
  if (!UnifiProtect.ownCameras.has(data.name)) {
84
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, `Unifi-Protect: Ignoring camera ${data.name}`);
72
85
  return;
73
86
  }
74
87
  const camera = UnifiProtect.ownCameras.get(data.name);
75
88
  camera.initialize(data);
89
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, `Unifi-Protect: Camera ${data.name} (re)initialized`);
76
90
  this._idMap.set(data.id, data.name);
77
91
  }
78
92
  }
@@ -39,7 +39,7 @@ class VictronDevice {
39
39
  devices_1.Devices.alLDevices['victron'] = this;
40
40
  devices_1.Devices.energymanager = this;
41
41
  this.persistDeviceInfo();
42
- this.loadDeviceSettings();
42
+ utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 4500, this);
43
43
  this._victronConsumer = new victron_mqtt_consumer_1.VictronMqttConsumer(opts);
44
44
  this._iCalculationInterval = utils_1.Utils.guardedInterval(() => {
45
45
  if (this.data.battery.soc) {
package/lib/index.js CHANGED
@@ -23,7 +23,6 @@ const services_1 = require("./services");
23
23
  const ioBroker_1 = require("./ioBroker");
24
24
  const devices_1 = require("./devices");
25
25
  const utils_1 = require("./utils");
26
- const weather_1 = require("./services/weather");
27
26
  const i18n_1 = require("./i18n");
28
27
  __exportStar(require("./enums"), exports);
29
28
  __exportStar(require("./action"), exports);
@@ -131,7 +130,7 @@ class HoffmationBase {
131
130
  utils_1.Utils.guardedNewThread(() => {
132
131
  if (settings_service_1.SettingsService.settings.weather) {
133
132
  logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Weather settings detected --> initializing');
134
- weather_1.WeatherService.initialize(settings_service_1.SettingsService.settings.weather);
133
+ services_1.WeatherService.initialize(settings_service_1.SettingsService.settings.weather);
135
134
  }
136
135
  });
137
136
  utils_1.Utils.guardedNewThread(() => {
@@ -37,6 +37,10 @@ export interface iCameraDevice extends iMotionSensor {
37
37
  * Whether the camera has currently detected a human
38
38
  */
39
39
  readonly personDetected: boolean;
40
+ /**
41
+ *
42
+ */
43
+ readonly lastUpdate: Date;
40
44
  /**
41
45
  * Inform this camera of a device, which blocks the alarm (or should unlift its block)
42
46
  * @param device - The device to block/unblock the alarm for
@@ -34,7 +34,7 @@ class OwnSonosDevice {
34
34
  this._info.allDevicesKey = `sonos-${roomName}-${discoveryName}`;
35
35
  devices_1.Devices.alLDevices[`sonos-${roomName}-${discoveryName}`] = this;
36
36
  this.persistDeviceInfo();
37
- this.loadDeviceSettings();
37
+ utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 4500, this);
38
38
  }
39
39
  get info() {
40
40
  return this._info;
@@ -88,7 +88,7 @@ class AcDevice {
88
88
  utils_1.Utils.guardedInterval(this.automaticCheck, 5 * 60 * 1000, this, false);
89
89
  utils_1.Utils.guardedInterval(this.persist, 15 * 60 * 1000, this, true);
90
90
  this.persistDeviceInfo();
91
- this.loadDeviceSettings();
91
+ utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 4500, this);
92
92
  this.blockAutomationHandler = new blockAutomaticHandler_1.BlockAutomaticHandler(this.restoreTargetAutomaticValue.bind(this), this.log.bind(this));
93
93
  }
94
94
  /** @inheritDoc */