hoffmation-base 3.2.1-alpha.11 → 3.2.1-alpha.13
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.
|
|
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, {
|
package/lib/index.js
CHANGED
|
@@ -48,7 +48,7 @@ class HoffmationInitializationObject {
|
|
|
48
48
|
exports.HoffmationInitializationObject = HoffmationInitializationObject;
|
|
49
49
|
class HoffmationBase {
|
|
50
50
|
static async initializeBeforeIoBroker(initObject) {
|
|
51
|
-
var _a
|
|
51
|
+
var _a;
|
|
52
52
|
settings_service_1.SettingsService.initialize(initObject.config);
|
|
53
53
|
i18n_1.Res.initialize(initObject.config.translationSettings);
|
|
54
54
|
if (initObject.config.logSettings) {
|
|
@@ -57,9 +57,12 @@ class HoffmationBase {
|
|
|
57
57
|
logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Hoffmation-Base Startup');
|
|
58
58
|
if (initObject.config.persistence) {
|
|
59
59
|
if (initObject.config.persistence.postgreSql) {
|
|
60
|
-
|
|
60
|
+
logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Creating PostgresSQL Client');
|
|
61
|
+
const dbo = new services_1.PostgreSqlPersist(initObject.config.persistence.postgreSql);
|
|
62
|
+
await dbo.initialize();
|
|
63
|
+
services_1.Persistence.dbo = dbo;
|
|
64
|
+
logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Persistence initialized');
|
|
61
65
|
}
|
|
62
|
-
await ((_a = services_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.initialize());
|
|
63
66
|
}
|
|
64
67
|
if (settings_service_1.SettingsService.settings.mp3Server) {
|
|
65
68
|
logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Mp3Server settings detected --> initializing');
|
|
@@ -81,7 +84,7 @@ class HoffmationBase {
|
|
|
81
84
|
logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Asus Router settings detected --> initializing');
|
|
82
85
|
new services_1.AsusRouter(settings_service_1.SettingsService.settings.asusConfig);
|
|
83
86
|
}
|
|
84
|
-
else if ((
|
|
87
|
+
else if ((_a = settings_service_1.SettingsService.settings.unifiSettings) === null || _a === void 0 ? void 0 : _a.loginOptions) {
|
|
85
88
|
logging_1.ServerLogService.writeLog(enums_1.LogLevel.Info, 'Unifi Router settings detected --> initializing');
|
|
86
89
|
new services_1.UnifiRouter(settings_service_1.SettingsService.settings.unifiSettings.loginOptions);
|
|
87
90
|
}
|
|
@@ -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) {
|
|
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;
|