hoffmation-base 3.2.1-alpha.10 → 3.2.1-alpha.12

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.
@@ -59,12 +59,14 @@ class BaseDevice {
59
59
  loadDeviceSettings() {
60
60
  utils_1.Utils.retryAction(() => {
61
61
  var _a;
62
- if (this.settings === undefined || services_1.Persistence.dbo === undefined) {
62
+ if (this.settings === undefined || !services_1.Persistence.dboReady) {
63
63
  return false;
64
64
  }
65
65
  (_a = this.settings) === null || _a === void 0 ? void 0 : _a.initializeFromDb(this);
66
66
  return true;
67
- }, this);
67
+ }, this, 5, 2000, undefined, () => {
68
+ this.log(enums_1.LogLevel.Error, 'Could not load device settings within 5 retries.');
69
+ });
68
70
  }
69
71
  log(level, message, logDebugType = enums_1.LogDebugType.None) {
70
72
  logging_1.ServerLogService.writeLog(level, message, {
@@ -14,7 +14,7 @@ const DeviceInfo_1 = require("../DeviceInfo");
14
14
  const devices_1 = require("../devices");
15
15
  const utils_1 = require("../../utils");
16
16
  const sharedFunctions_1 = require("../sharedFunctions");
17
- const sun_time_offsets_1 = require("../../models/sun-time-offsets");
17
+ const models_1 = require("../../models");
18
18
  const command_1 = require("../../command");
19
19
  const services_1 = require("../../services");
20
20
  const settings_service_1 = require("../../settings-service");
@@ -61,6 +61,7 @@ class Dachs extends RoomBaseDevice_1.RoomBaseDevice {
61
61
  ]);
62
62
  devices_1.Devices.alLDevices[allDevicesKey] = this;
63
63
  this.deviceCapabilities.push(enums_1.DeviceCapability.actuator);
64
+ this.deviceCapabilities.push(enums_1.DeviceCapability.blockAutomatic);
64
65
  if (options.influxDb) {
65
66
  this._influxClient = new lib_1.DachsInfluxClient(options.influxDb);
66
67
  }
@@ -189,6 +190,9 @@ class Dachs extends RoomBaseDevice_1.RoomBaseDevice {
189
190
  this.checkAllDesiredStates(action, action.newLevel);
190
191
  }
191
192
  checkAllDesiredStates(action, batteryLevel) {
193
+ if (this.blockAutomationHandler.automaticBlockActive) {
194
+ return;
195
+ }
192
196
  const shouldDachsBeStarted = this.shouldDachsBeStarted(action, batteryLevel);
193
197
  this.checkHeatingRod(action, batteryLevel);
194
198
  this.checkAlternativeActuator(shouldDachsBeStarted, action);
@@ -301,7 +305,7 @@ class Dachs extends RoomBaseDevice_1.RoomBaseDevice {
301
305
  // It is winter and heat storage is kinda cold --> Start
302
306
  return true;
303
307
  }
304
- const dayType = services_1.TimeCallbackService.dayType(new sun_time_offsets_1.SunTimeOffsets());
308
+ const dayType = services_1.TimeCallbackService.dayType(new models_1.SunTimeOffsets());
305
309
  if ((dayType === enums_1.TimeOfDay.Daylight || dayType === enums_1.TimeOfDay.BeforeSunrise) &&
306
310
  batteryLevel > this.settings.batteryLevelTurnOnThreshold) {
307
311
  // It is daytime (maybe solar power) and it is no critical battery level
@@ -1,8 +1,13 @@
1
1
  import { iPersist } from '../../interfaces';
2
2
  export declare class Persistence {
3
+ private static _dbo;
3
4
  /**
4
5
  * The persitence layer object
6
+ * @returns The persistence layer
5
7
  */
6
- static dbo: iPersist | undefined;
8
+ static get dbo(): iPersist | undefined;
9
+ static set dbo(value: iPersist | undefined);
10
+ static get dboReady(): boolean;
11
+ static lazyDbo(retries?: number): Promise<iPersist | undefined>;
7
12
  static get anyDboActive(): boolean;
8
13
  }
@@ -1,9 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Persistence = void 0;
4
+ const logging_1 = require("../../logging");
5
+ const enums_1 = require("../../enums");
6
+ const utils_1 = require("../../utils");
4
7
  class Persistence {
8
+ /**
9
+ * The persitence layer object
10
+ * @returns The persistence layer
11
+ */
12
+ static get dbo() {
13
+ if (this._dbo === undefined) {
14
+ return undefined;
15
+ }
16
+ if (this._dbo.initialized === false) {
17
+ const err = new Error('Db is not yet initialized');
18
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Warn, 'Db is not yet initialized, Stack: ' + err.stack);
19
+ return undefined;
20
+ }
21
+ return this._dbo;
22
+ }
23
+ static set dbo(value) {
24
+ this._dbo = value;
25
+ }
26
+ static get dboReady() {
27
+ return this._dbo !== undefined && this._dbo.initialized;
28
+ }
29
+ static async lazyDbo(retries = 5) {
30
+ if (this.dbo === undefined) {
31
+ return undefined;
32
+ }
33
+ if (this.dbo.initialized) {
34
+ return this.dbo;
35
+ }
36
+ if (retries == 0) {
37
+ return undefined;
38
+ }
39
+ return new Promise((resolve) => {
40
+ utils_1.Utils.guardedTimeout(() => {
41
+ resolve(Persistence.lazyDbo(retries - 1));
42
+ }, 2000, this);
43
+ });
44
+ }
5
45
  static get anyDboActive() {
6
46
  return this.dbo !== undefined;
7
47
  }
8
48
  }
9
49
  exports.Persistence = Persistence;
50
+ Persistence._dbo = undefined;