@iobroker/js-controller-adapter 6.0.6 → 6.0.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.
- package/build/cjs/lib/adapter/adapter.d.ts +8 -1
- package/build/cjs/lib/adapter/adapter.js +205 -200
- package/build/cjs/lib/adapter/adapter.js.map +2 -2
- package/build/esm/lib/adapter/adapter.d.ts +8 -1
- package/build/esm/lib/adapter/adapter.d.ts.map +1 -1
- package/build/esm/lib/adapter/adapter.js +264 -256
- package/build/esm/lib/adapter/adapter.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +11 -12
|
@@ -8,7 +8,7 @@ import deepClone from 'deep-clone';
|
|
|
8
8
|
import { PluginHandler } from '@iobroker/plugin-base';
|
|
9
9
|
import semver from 'semver';
|
|
10
10
|
import path from 'node:path';
|
|
11
|
-
import { getObjectsConstructor, getStatesConstructor, tools, EXIT_CODES, password, logger } from '@iobroker/js-controller-common';
|
|
11
|
+
import { getObjectsConstructor, getStatesConstructor, tools, EXIT_CODES, password, logger, isInstalledFromNpm } from '@iobroker/js-controller-common';
|
|
12
12
|
import { decryptArray, encryptArray, getSupportedFeatures, isMessageboxSupported, getAdapterScopedPackageIdentifier, listInstalledNodeModules, requestModuleNameByUrl } from '../../lib/adapter/utils.js';
|
|
13
13
|
// @ts-expect-error no ts file
|
|
14
14
|
import extend from 'node.extend';
|
|
@@ -113,7 +113,7 @@ export class AdapterClass extends EventEmitter {
|
|
|
113
113
|
/** contents of package.json */
|
|
114
114
|
pack;
|
|
115
115
|
/** contents of io-package.json */
|
|
116
|
-
ioPack;
|
|
116
|
+
ioPack;
|
|
117
117
|
_initializeTimeout;
|
|
118
118
|
inited;
|
|
119
119
|
/** contents of iobroker.json if required via AdapterOptions */
|
|
@@ -8288,8 +8288,8 @@ export class AdapterClass extends EventEmitter {
|
|
|
8288
8288
|
}
|
|
8289
8289
|
if (this.pluginHandler.isPluginActive(pluginName) !== state.val) {
|
|
8290
8290
|
if (state.val) {
|
|
8291
|
-
if (!this.pluginHandler.
|
|
8292
|
-
this.pluginHandler.
|
|
8291
|
+
if (!this.pluginHandler.isPluginInstantiated(pluginName)) {
|
|
8292
|
+
this.pluginHandler.instantiatePlugin(pluginName, this.pluginHandler.getPluginConfig(pluginName) || {}, thisDir);
|
|
8293
8293
|
this.pluginHandler.setDatabaseForPlugin(pluginName, this.#objects, this.#states);
|
|
8294
8294
|
this.pluginHandler.initPlugin(pluginName, this.adapterConfig || {});
|
|
8295
8295
|
}
|
|
@@ -8677,265 +8677,264 @@ export class AdapterClass extends EventEmitter {
|
|
|
8677
8677
|
return;
|
|
8678
8678
|
}
|
|
8679
8679
|
this.pluginHandler.setDatabaseForPlugins(this.#objects, this.#states);
|
|
8680
|
-
this.pluginHandler.initPlugins(adapterConfig || {}
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
|
|
8689
|
-
|
|
8690
|
-
}
|
|
8691
|
-
else {
|
|
8692
|
-
!this._config.isInstall &&
|
|
8693
|
-
this._logger.error(`${this.namespaceLog} no config found for adapter`);
|
|
8694
|
-
}
|
|
8695
|
-
if (!this._config.isInstall && (!process.argv || !this._config.forceIfDisabled)) {
|
|
8696
|
-
const id = `system.adapter.${this.namespace}`;
|
|
8697
|
-
this.outputCount += 2;
|
|
8698
|
-
this.#states.setState(`${id}.alive`, { val: true, ack: true, expire: 30, from: id });
|
|
8699
|
-
let done = false;
|
|
8700
|
-
this.#states.setState(`${id}.connected`, {
|
|
8701
|
-
val: true,
|
|
8702
|
-
ack: true,
|
|
8703
|
-
expire: 30,
|
|
8704
|
-
from: id
|
|
8705
|
-
}, () => {
|
|
8706
|
-
if (!done) {
|
|
8707
|
-
done = true;
|
|
8708
|
-
this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND);
|
|
8709
|
-
}
|
|
8710
|
-
});
|
|
8711
|
-
setTimeout(() => {
|
|
8712
|
-
if (!done) {
|
|
8713
|
-
done = true;
|
|
8714
|
-
this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND);
|
|
8715
|
-
}
|
|
8716
|
-
}, 1_000);
|
|
8717
|
-
return;
|
|
8718
|
-
}
|
|
8719
|
-
}
|
|
8720
|
-
if (!this._config.isInstall && (!adapterConfig || !('_id' in adapterConfig))) {
|
|
8721
|
-
this._logger.error(`${this.namespaceLog} invalid config: no _id found`);
|
|
8722
|
-
this.terminate(EXIT_CODES.INVALID_ADAPTER_ID);
|
|
8723
|
-
return;
|
|
8724
|
-
}
|
|
8725
|
-
let name;
|
|
8726
|
-
let instance;
|
|
8727
|
-
if (!this._config.isInstall) {
|
|
8728
|
-
// @ts-expect-error
|
|
8729
|
-
const tmp = adapterConfig._id.match(/^system\.adapter\.([a-zA-Z0-9-_]+)\.([0-9]+)$/);
|
|
8730
|
-
if (!tmp) {
|
|
8731
|
-
this._logger.error(`${this.namespaceLog} invalid config`);
|
|
8732
|
-
this.terminate(EXIT_CODES.INVALID_ADAPTER_ID);
|
|
8733
|
-
return;
|
|
8734
|
-
}
|
|
8735
|
-
name = tmp[1];
|
|
8736
|
-
instance = parseInt(tmp[2]) || 0;
|
|
8680
|
+
await this.pluginHandler.initPlugins(adapterConfig || {});
|
|
8681
|
+
if (!this.#states || !this.#objects || this.terminated) {
|
|
8682
|
+
// if adapterState was destroyed,we should not continue
|
|
8683
|
+
return;
|
|
8684
|
+
}
|
|
8685
|
+
this.#states.subscribe(`system.adapter.${this.namespace}.plugins.*`);
|
|
8686
|
+
if (this._options.instance === undefined) {
|
|
8687
|
+
if (!adapterConfig || !('common' in adapterConfig) || !adapterConfig.common.enabled) {
|
|
8688
|
+
if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.enabled !== undefined) {
|
|
8689
|
+
!this._config.isInstall && this._logger.error(`${this.namespaceLog} adapter disabled`);
|
|
8737
8690
|
}
|
|
8738
8691
|
else {
|
|
8739
|
-
|
|
8740
|
-
instance = 0;
|
|
8741
|
-
adapterConfig = adapterConfig || {
|
|
8742
|
-
// @ts-expect-error protectedNative exists on instance objects
|
|
8743
|
-
common: { mode: 'once', name: name, protectedNative: [] },
|
|
8744
|
-
native: {}
|
|
8745
|
-
};
|
|
8692
|
+
!this._config.isInstall && this._logger.error(`${this.namespaceLog} no config found for adapter`);
|
|
8746
8693
|
}
|
|
8747
|
-
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
|
|
8753
|
-
|
|
8754
|
-
|
|
8755
|
-
|
|
8694
|
+
if (!this._config.isInstall && (!process.argv || !this._config.forceIfDisabled)) {
|
|
8695
|
+
const id = `system.adapter.${this.namespace}`;
|
|
8696
|
+
this.outputCount += 2;
|
|
8697
|
+
this.#states.setState(`${id}.alive`, { val: true, ack: true, expire: 30, from: id });
|
|
8698
|
+
let done = false;
|
|
8699
|
+
this.#states.setState(`${id}.connected`, {
|
|
8700
|
+
val: true,
|
|
8701
|
+
ack: true,
|
|
8702
|
+
expire: 30,
|
|
8703
|
+
from: id
|
|
8704
|
+
}, () => {
|
|
8705
|
+
if (!done) {
|
|
8706
|
+
done = true;
|
|
8707
|
+
this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND);
|
|
8756
8708
|
}
|
|
8757
|
-
}
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
this.namespaceLog = this.namespace + (this.startedInCompactMode ? ' (COMPACT)' : ` (${process.pid})`);
|
|
8766
|
-
if (!this.startedInCompactMode) {
|
|
8767
|
-
process.title = `io.${this.namespace}`;
|
|
8709
|
+
});
|
|
8710
|
+
setTimeout(() => {
|
|
8711
|
+
if (!done) {
|
|
8712
|
+
done = true;
|
|
8713
|
+
this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND);
|
|
8714
|
+
}
|
|
8715
|
+
}, 1_000);
|
|
8716
|
+
return;
|
|
8768
8717
|
}
|
|
8718
|
+
}
|
|
8719
|
+
if (!this._config.isInstall && (!adapterConfig || !('_id' in adapterConfig))) {
|
|
8720
|
+
this._logger.error(`${this.namespaceLog} invalid config: no _id found`);
|
|
8721
|
+
this.terminate(EXIT_CODES.INVALID_ADAPTER_ID);
|
|
8722
|
+
return;
|
|
8723
|
+
}
|
|
8724
|
+
let name;
|
|
8725
|
+
let instance;
|
|
8726
|
+
if (!this._config.isInstall) {
|
|
8769
8727
|
// @ts-expect-error
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
if (
|
|
8776
|
-
// @ts-expect-error
|
|
8777
|
-
adapterConfig.common.mode === 'schedule' ||
|
|
8778
|
-
// @ts-expect-error
|
|
8779
|
-
adapterConfig.common.mode === 'once') {
|
|
8780
|
-
this.stop = params => this._stop({ ...params, isPause: true });
|
|
8781
|
-
}
|
|
8782
|
-
else if (this.startedInCompactMode) {
|
|
8783
|
-
this.stop = params => this._stop({ ...params, isPause: false });
|
|
8784
|
-
this.kill = this.stop;
|
|
8785
|
-
}
|
|
8786
|
-
else {
|
|
8787
|
-
this.stop = params => this._stop({ ...params, isPause: false });
|
|
8788
|
-
}
|
|
8789
|
-
// Monitor logging state
|
|
8790
|
-
this.#states.subscribe(`${SYSTEM_ADAPTER_PREFIX}*.logging`);
|
|
8791
|
-
if (typeof this._options.message === 'function' &&
|
|
8792
|
-
// @ts-expect-error, we should infer correctly that this is an InstanceObject in this case
|
|
8793
|
-
!isMessageboxSupported(adapterConfig.common)) {
|
|
8794
|
-
this._logger.error(`${this.namespaceLog} : message handler implemented, but messagebox not enabled. Define common.messagebox in io-package.json for adapter or delete message handler.`);
|
|
8795
|
-
// @ts-expect-error we should infer adapterConfig correctly
|
|
8796
|
-
}
|
|
8797
|
-
else if (isMessageboxSupported(adapterConfig.common)) {
|
|
8798
|
-
this.mboxSubscribed = true;
|
|
8799
|
-
this.#states.subscribeMessage(`system.adapter.${this.namespace}`);
|
|
8728
|
+
const tmp = adapterConfig._id.match(/^system\.adapter\.([a-zA-Z0-9-_]+)\.([0-9]+)$/);
|
|
8729
|
+
if (!tmp) {
|
|
8730
|
+
this._logger.error(`${this.namespaceLog} invalid config`);
|
|
8731
|
+
this.terminate(EXIT_CODES.INVALID_ADAPTER_ID);
|
|
8732
|
+
return;
|
|
8800
8733
|
}
|
|
8734
|
+
name = tmp[1];
|
|
8735
|
+
instance = parseInt(tmp[2]) || 0;
|
|
8801
8736
|
}
|
|
8802
8737
|
else {
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
// @ts-expect-error
|
|
8812
|
-
this.common = adapterConfig.common || {};
|
|
8813
|
-
this.host = this.common?.host || tools.getHostName() || os.hostname();
|
|
8814
|
-
}
|
|
8815
|
-
this.adapterConfig = adapterConfig;
|
|
8816
|
-
this._utils = new Validator(this.#objects, this.#states, this.namespaceLog, this._logger, this.namespace, this._namespaceRegExp);
|
|
8817
|
-
this.log = new Log(this.namespaceLog, this._config.log.level, this._logger);
|
|
8818
|
-
await this._createInstancesObjects(adapterConfig);
|
|
8819
|
-
// auto oObjects
|
|
8820
|
-
if (this._options.objects) {
|
|
8821
|
-
this.oObjects = await this.getAdapterObjectsAsync();
|
|
8822
|
-
await this.subscribeObjectsAsync('*');
|
|
8823
|
-
}
|
|
8824
|
-
// initialize the system secret
|
|
8825
|
-
await this.getSystemSecret();
|
|
8826
|
-
// Decrypt all attributes of encryptedNative
|
|
8827
|
-
const promises = [];
|
|
8738
|
+
name = this.name;
|
|
8739
|
+
instance = 0;
|
|
8740
|
+
adapterConfig = adapterConfig || {
|
|
8741
|
+
// @ts-expect-error protectedNative exists on instance objects
|
|
8742
|
+
common: { mode: 'once', name: name, protectedNative: [] },
|
|
8743
|
+
native: {}
|
|
8744
|
+
};
|
|
8745
|
+
}
|
|
8828
8746
|
// @ts-expect-error
|
|
8829
|
-
if (
|
|
8830
|
-
//
|
|
8831
|
-
for (const
|
|
8832
|
-
//
|
|
8833
|
-
// @ts-expect-error
|
|
8834
|
-
if (
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
.then(decryptedValue => (this.config[attr] = decryptedValue))
|
|
8838
|
-
.catch(e => this._logger.error(`${this.namespaceLog} Can not decrypt attribute ${attr}: ${e.message}`)));
|
|
8747
|
+
if (adapterConfig.common.loglevel && !this.overwriteLogLevel) {
|
|
8748
|
+
// set configured in DB log level
|
|
8749
|
+
for (const trans of Object.values(this._logger.transports)) {
|
|
8750
|
+
// set the loglevel on transport only if no loglevel was pinned in log config
|
|
8751
|
+
// @ts-expect-error it is our own modification
|
|
8752
|
+
if (!trans._defaultConfigLoglevel) {
|
|
8753
|
+
// @ts-expect-error
|
|
8754
|
+
trans.level = adapterConfig.common.loglevel;
|
|
8839
8755
|
}
|
|
8840
8756
|
}
|
|
8757
|
+
// @ts-expect-error
|
|
8758
|
+
this._config.log.level = adapterConfig.common.loglevel;
|
|
8759
|
+
}
|
|
8760
|
+
// @ts-expect-error
|
|
8761
|
+
this.name = adapterConfig.common.name;
|
|
8762
|
+
this.instance = instance;
|
|
8763
|
+
this.namespace = `${name}.${instance}`;
|
|
8764
|
+
this.namespaceLog = this.namespace + (this.startedInCompactMode ? ' (COMPACT)' : ` (${process.pid})`);
|
|
8765
|
+
if (!this.startedInCompactMode) {
|
|
8766
|
+
process.title = `io.${this.namespace}`;
|
|
8767
|
+
}
|
|
8768
|
+
// @ts-expect-error
|
|
8769
|
+
this.config = adapterConfig.native;
|
|
8770
|
+
// @ts-expect-error
|
|
8771
|
+
this.host = adapterConfig.common.host;
|
|
8772
|
+
// @ts-expect-error
|
|
8773
|
+
this.common = adapterConfig.common;
|
|
8774
|
+
if (
|
|
8775
|
+
// @ts-expect-error
|
|
8776
|
+
adapterConfig.common.mode === 'schedule' ||
|
|
8777
|
+
// @ts-expect-error
|
|
8778
|
+
adapterConfig.common.mode === 'once') {
|
|
8779
|
+
this.stop = params => this._stop({ ...params, isPause: true });
|
|
8780
|
+
}
|
|
8781
|
+
else if (this.startedInCompactMode) {
|
|
8782
|
+
this.stop = params => this._stop({ ...params, isPause: false });
|
|
8783
|
+
this.kill = this.stop;
|
|
8841
8784
|
}
|
|
8842
8785
|
else {
|
|
8843
|
-
|
|
8844
|
-
const idx = this.SUPPORTED_FEATURES.indexOf('ADAPTER_AUTO_DECRYPT_NATIVE');
|
|
8845
|
-
if (idx !== -1) {
|
|
8846
|
-
this.SUPPORTED_FEATURES.splice(idx, 1);
|
|
8847
|
-
}
|
|
8786
|
+
this.stop = params => this._stop({ ...params, isPause: false });
|
|
8848
8787
|
}
|
|
8849
|
-
//
|
|
8850
|
-
|
|
8851
|
-
if (
|
|
8852
|
-
//
|
|
8853
|
-
|
|
8788
|
+
// Monitor logging state
|
|
8789
|
+
this.#states.subscribe(`${SYSTEM_ADAPTER_PREFIX}*.logging`);
|
|
8790
|
+
if (typeof this._options.message === 'function' &&
|
|
8791
|
+
// @ts-expect-error, we should infer correctly that this is an InstanceObject in this case
|
|
8792
|
+
!isMessageboxSupported(adapterConfig.common)) {
|
|
8793
|
+
this._logger.error(`${this.namespaceLog} : message handler implemented, but messagebox not enabled. Define common.messagebox in io-package.json for adapter or delete message handler.`);
|
|
8794
|
+
// @ts-expect-error we should infer adapterConfig correctly
|
|
8854
8795
|
}
|
|
8855
|
-
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
val: this._config.log.level,
|
|
8859
|
-
ack: true,
|
|
8860
|
-
from: `system.adapter.${this.namespace}`
|
|
8861
|
-
});
|
|
8862
|
-
if (this._options.instance === undefined) {
|
|
8863
|
-
this.version = this.pack?.version
|
|
8864
|
-
? this.pack.version
|
|
8865
|
-
: this.ioPack?.common
|
|
8866
|
-
? this.ioPack.common.version
|
|
8867
|
-
: 'unknown';
|
|
8868
|
-
// display if it's a non-official version - only if installedFrom is explicitly given and differs it's not npm
|
|
8869
|
-
const isNpmVersion = !this.ioPack ||
|
|
8870
|
-
!this.ioPack.common ||
|
|
8871
|
-
typeof this.ioPack.common.installedFrom !== 'string' ||
|
|
8872
|
-
this.ioPack.common.installedFrom.startsWith(`${tools.appName.toLowerCase()}.${this.name}`);
|
|
8873
|
-
this._logger.info(`${this.namespaceLog} starting. Version ${this.version} ${!isNpmVersion ? `(non-npm: ${this.ioPack.common.installedFrom}) ` : ''}in ${this.adapterDir}, node: ${process.version}, js-controller: ${controllerVersion}`);
|
|
8874
|
-
this._config.system = this._config.system || {};
|
|
8875
|
-
this._config.system.statisticsInterval = parseInt(this._config.system.statisticsInterval, 10) || 15_000;
|
|
8876
|
-
if (!this._config.isInstall) {
|
|
8877
|
-
this._reportInterval = setInterval(() => this._reportStatus(), this._config.system.statisticsInterval);
|
|
8878
|
-
this._reportStatus();
|
|
8879
|
-
const id = `system.adapter.${this.namespace}`;
|
|
8880
|
-
this.#states.setState(`${id}.compactMode`, {
|
|
8881
|
-
ack: true,
|
|
8882
|
-
from: id,
|
|
8883
|
-
val: !!this.startedInCompactMode
|
|
8884
|
-
});
|
|
8885
|
-
this.outputCount++;
|
|
8886
|
-
if (this.startedInCompactMode) {
|
|
8887
|
-
this.#states.setState(`${id}.cpu`, { ack: true, from: id, val: 0 });
|
|
8888
|
-
this.#states.setState(`${id}.cputime`, { ack: true, from: id, val: 0 });
|
|
8889
|
-
this.#states.setState(`${id}.memRss`, { val: 0, ack: true, from: id });
|
|
8890
|
-
this.#states.setState(`${id}.memHeapTotal`, { val: 0, ack: true, from: id });
|
|
8891
|
-
this.#states.setState(`${id}.memHeapUsed`, { val: 0, ack: true, from: id });
|
|
8892
|
-
this.#states.setState(`${id}.eventLoopLag`, { val: 0, ack: true, from: id });
|
|
8893
|
-
this.outputCount += 6;
|
|
8894
|
-
}
|
|
8895
|
-
else {
|
|
8896
|
-
tools.measureEventLoopLag(1_000, lag => {
|
|
8897
|
-
if (lag) {
|
|
8898
|
-
this.eventLoopLags.push(lag);
|
|
8899
|
-
}
|
|
8900
|
-
});
|
|
8901
|
-
}
|
|
8902
|
-
}
|
|
8796
|
+
else if (isMessageboxSupported(adapterConfig.common)) {
|
|
8797
|
+
this.mboxSubscribed = true;
|
|
8798
|
+
this.#states.subscribeMessage(`system.adapter.${this.namespace}`);
|
|
8903
8799
|
}
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8800
|
+
}
|
|
8801
|
+
else {
|
|
8802
|
+
// @ts-expect-error
|
|
8803
|
+
this.name = adapterConfig.name || this.name;
|
|
8804
|
+
// @ts-expect-error
|
|
8805
|
+
this.instance = adapterConfig.instance || 0;
|
|
8806
|
+
this.namespace = `${this.name}.${this.instance}`;
|
|
8807
|
+
this.namespaceLog = this.namespace + (this.startedInCompactMode ? ' (COMPACT)' : ` (${process.pid})`);
|
|
8808
|
+
// @ts-expect-error
|
|
8809
|
+
this.config = adapterConfig.native || {};
|
|
8810
|
+
// @ts-expect-error
|
|
8811
|
+
this.common = adapterConfig.common || {};
|
|
8812
|
+
this.host = this.common?.host || tools.getHostName() || os.hostname();
|
|
8813
|
+
}
|
|
8814
|
+
this.adapterConfig = adapterConfig;
|
|
8815
|
+
this._utils = new Validator(this.#objects, this.#states, this.namespaceLog, this._logger, this.namespace, this._namespaceRegExp);
|
|
8816
|
+
this.log = new Log(this.namespaceLog, this._config.log.level, this._logger);
|
|
8817
|
+
await this._createInstancesObjects(adapterConfig);
|
|
8818
|
+
// auto oObjects
|
|
8819
|
+
if (this._options.objects) {
|
|
8820
|
+
this.oObjects = await this.getAdapterObjectsAsync();
|
|
8821
|
+
await this.subscribeObjectsAsync('*');
|
|
8822
|
+
}
|
|
8823
|
+
// initialize the system secret
|
|
8824
|
+
await this.getSystemSecret();
|
|
8825
|
+
// Decrypt all attributes of encryptedNative
|
|
8826
|
+
const promises = [];
|
|
8827
|
+
// @ts-expect-error
|
|
8828
|
+
if (Array.isArray(adapterConfig.encryptedNative)) {
|
|
8829
|
+
// @ts-expect-error
|
|
8830
|
+
for (const attr of adapterConfig.encryptedNative) {
|
|
8831
|
+
// we can only decrypt strings
|
|
8832
|
+
// @ts-expect-error
|
|
8833
|
+
if (typeof this.config[attr] === 'string') {
|
|
8834
|
+
promises.push(this.getEncryptedConfig(attr)
|
|
8835
|
+
// @ts-expect-error
|
|
8836
|
+
.then(decryptedValue => (this.config[attr] = decryptedValue))
|
|
8837
|
+
.catch(e => this._logger.error(`${this.namespaceLog} Can not decrypt attribute ${attr}: ${e.message}`)));
|
|
8907
8838
|
}
|
|
8908
|
-
|
|
8909
|
-
|
|
8839
|
+
}
|
|
8840
|
+
}
|
|
8841
|
+
else {
|
|
8842
|
+
// remove encrypted native from supported features, otherwise this can cause issues, if no adapter upload done with js-c v3+ yet
|
|
8843
|
+
const idx = this.SUPPORTED_FEATURES.indexOf('ADAPTER_AUTO_DECRYPT_NATIVE');
|
|
8844
|
+
if (idx !== -1) {
|
|
8845
|
+
this.SUPPORTED_FEATURES.splice(idx, 1);
|
|
8846
|
+
}
|
|
8847
|
+
}
|
|
8848
|
+
// Wait till all attributes decrypted
|
|
8849
|
+
await Promise.all(promises);
|
|
8850
|
+
if (!this.#states) {
|
|
8851
|
+
// if this.adapterStates was destroyed, we should not continue
|
|
8852
|
+
return;
|
|
8853
|
+
}
|
|
8854
|
+
this.outputCount++;
|
|
8855
|
+
// set current loglevel
|
|
8856
|
+
this.#states.setState(`system.adapter.${this.namespace}.logLevel`, {
|
|
8857
|
+
val: this._config.log.level,
|
|
8858
|
+
ack: true,
|
|
8859
|
+
from: `system.adapter.${this.namespace}`
|
|
8860
|
+
});
|
|
8861
|
+
if (this._options.instance === undefined) {
|
|
8862
|
+
this.version = this.pack?.version
|
|
8863
|
+
? this.pack.version
|
|
8864
|
+
: this.ioPack?.common
|
|
8865
|
+
? this.ioPack.common.version
|
|
8866
|
+
: 'unknown';
|
|
8867
|
+
// display if it's a non-official version - only if installedFrom is explicitly given and differs it's not npm
|
|
8868
|
+
// display if it's a non-official version - only if installedFrom is explicitly given and differs it's not npm
|
|
8869
|
+
const isNpmVersion = isInstalledFromNpm({
|
|
8870
|
+
adapterName: this.name,
|
|
8871
|
+
installedFrom: this.ioPack.common.installedFrom
|
|
8872
|
+
});
|
|
8873
|
+
this._logger.info(`${this.namespaceLog} starting. Version ${this.version} ${!isNpmVersion ? `(non-npm: ${this.ioPack.common.installedFrom}) ` : ''}in ${this.adapterDir}, node: ${process.version}, js-controller: ${controllerVersion}`);
|
|
8874
|
+
this._config.system = this._config.system || {};
|
|
8875
|
+
this._config.system.statisticsInterval = parseInt(this._config.system.statisticsInterval, 10) || 15_000;
|
|
8876
|
+
if (!this._config.isInstall) {
|
|
8877
|
+
this._reportInterval = setInterval(() => this._reportStatus(), this._config.system.statisticsInterval);
|
|
8878
|
+
this._reportStatus();
|
|
8879
|
+
const id = `system.adapter.${this.namespace}`;
|
|
8880
|
+
this.#states.setState(`${id}.compactMode`, {
|
|
8881
|
+
ack: true,
|
|
8882
|
+
from: id,
|
|
8883
|
+
val: !!this.startedInCompactMode
|
|
8884
|
+
});
|
|
8885
|
+
this.outputCount++;
|
|
8886
|
+
if (this.startedInCompactMode) {
|
|
8887
|
+
this.#states.setState(`${id}.cpu`, { ack: true, from: id, val: 0 });
|
|
8888
|
+
this.#states.setState(`${id}.cputime`, { ack: true, from: id, val: 0 });
|
|
8889
|
+
this.#states.setState(`${id}.memRss`, { val: 0, ack: true, from: id });
|
|
8890
|
+
this.#states.setState(`${id}.memHeapTotal`, { val: 0, ack: true, from: id });
|
|
8891
|
+
this.#states.setState(`${id}.memHeapUsed`, { val: 0, ack: true, from: id });
|
|
8892
|
+
this.#states.setState(`${id}.eventLoopLag`, { val: 0, ack: true, from: id });
|
|
8893
|
+
this.outputCount += 6;
|
|
8910
8894
|
}
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8895
|
+
else {
|
|
8896
|
+
tools.measureEventLoopLag(1_000, lag => {
|
|
8897
|
+
if (lag) {
|
|
8898
|
+
this.eventLoopLags.push(lag);
|
|
8899
|
+
}
|
|
8916
8900
|
});
|
|
8917
8901
|
}
|
|
8918
8902
|
}
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
}
|
|
8931
|
-
this.
|
|
8903
|
+
}
|
|
8904
|
+
if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.restartSchedule) {
|
|
8905
|
+
try {
|
|
8906
|
+
this._schedule = await import('node-schedule');
|
|
8907
|
+
}
|
|
8908
|
+
catch {
|
|
8909
|
+
this._logger.error(`${this.namespaceLog} Cannot load node-schedule. Scheduled restart is disabled`);
|
|
8910
|
+
}
|
|
8911
|
+
if (this._schedule) {
|
|
8912
|
+
this._logger.debug(`${this.namespaceLog} Schedule restart: ${adapterConfig.common.restartSchedule}`);
|
|
8913
|
+
this._restartScheduleJob = this._schedule.scheduleJob(adapterConfig.common.restartSchedule, () => {
|
|
8914
|
+
this._logger.info(`${this.namespaceLog} Scheduled restart.`);
|
|
8915
|
+
this._stop({ isPause: false, isScheduled: true });
|
|
8932
8916
|
});
|
|
8933
8917
|
}
|
|
8934
|
-
|
|
8935
|
-
|
|
8918
|
+
}
|
|
8919
|
+
// auto oStates
|
|
8920
|
+
if (this._options.states) {
|
|
8921
|
+
this.getStates('*', null, (err, _states) => {
|
|
8922
|
+
if (this._stopInProgress) {
|
|
8923
|
+
return;
|
|
8924
|
+
}
|
|
8925
|
+
this.oStates = _states;
|
|
8926
|
+
this.subscribeStates('*');
|
|
8927
|
+
if (this._firstConnection) {
|
|
8928
|
+
this._firstConnection = false;
|
|
8929
|
+
this._callReadyHandler();
|
|
8930
|
+
}
|
|
8936
8931
|
this.adapterReady = true;
|
|
8937
|
-
}
|
|
8938
|
-
}
|
|
8932
|
+
});
|
|
8933
|
+
}
|
|
8934
|
+
else if (!this._stopInProgress) {
|
|
8935
|
+
this._callReadyHandler();
|
|
8936
|
+
this.adapterReady = true;
|
|
8937
|
+
}
|
|
8939
8938
|
}
|
|
8940
8939
|
/**
|
|
8941
8940
|
* Calls the ready handler, if it is an install run it calls the install handler instead
|
|
@@ -9181,6 +9180,32 @@ export class AdapterClass extends EventEmitter {
|
|
|
9181
9180
|
};
|
|
9182
9181
|
await this.#states.pushMessage(`system.host.${this.host}`, obj);
|
|
9183
9182
|
}
|
|
9183
|
+
/**
|
|
9184
|
+
* Initialize the plugin handler for this adapter
|
|
9185
|
+
*/
|
|
9186
|
+
_initPluginHandler() {
|
|
9187
|
+
const pluginSettings = {
|
|
9188
|
+
scope: 'adapter',
|
|
9189
|
+
namespace: `system.adapter.${this.namespace}`,
|
|
9190
|
+
logNamespace: this.namespaceLog,
|
|
9191
|
+
// @ts-expect-error
|
|
9192
|
+
log: this._logger,
|
|
9193
|
+
iobrokerConfig: this._config,
|
|
9194
|
+
// @ts-expect-error
|
|
9195
|
+
parentPackage: this.pack,
|
|
9196
|
+
controllerVersion
|
|
9197
|
+
};
|
|
9198
|
+
this.pluginHandler = new PluginHandler(pluginSettings);
|
|
9199
|
+
try {
|
|
9200
|
+
this.pluginHandler.addPlugins(this.ioPack.common.plugins || {}, [this.adapterDir, thisDir]); // first resolve from adapter directory, else from js-controller
|
|
9201
|
+
}
|
|
9202
|
+
catch (e) {
|
|
9203
|
+
this._logger.error(`Could not add plugins: ${e.message}`);
|
|
9204
|
+
}
|
|
9205
|
+
}
|
|
9206
|
+
/**
|
|
9207
|
+
* Initializes the adapter
|
|
9208
|
+
*/
|
|
9184
9209
|
async _init() {
|
|
9185
9210
|
/**
|
|
9186
9211
|
* Initiates the databases
|
|
@@ -9248,24 +9273,7 @@ export class AdapterClass extends EventEmitter {
|
|
|
9248
9273
|
process.once('exit', () => this._stop());
|
|
9249
9274
|
process.on('uncaughtException', err => this._exceptionHandler(err));
|
|
9250
9275
|
process.on('unhandledRejection', err => this._exceptionHandler(err, true));
|
|
9251
|
-
|
|
9252
|
-
scope: 'adapter',
|
|
9253
|
-
namespace: `system.adapter.${this.namespace}`,
|
|
9254
|
-
logNamespace: this.namespaceLog,
|
|
9255
|
-
// @ts-expect-error
|
|
9256
|
-
log: this._logger,
|
|
9257
|
-
iobrokerConfig: this._config,
|
|
9258
|
-
// @ts-expect-error
|
|
9259
|
-
parentPackage: this.pack,
|
|
9260
|
-
controllerVersion
|
|
9261
|
-
};
|
|
9262
|
-
this.pluginHandler = new PluginHandler(pluginSettings);
|
|
9263
|
-
try {
|
|
9264
|
-
this.pluginHandler.addPlugins(this.ioPack.common.plugins, [this.adapterDir, thisDir]); // first resolve from adapter directory, else from js-controller
|
|
9265
|
-
}
|
|
9266
|
-
catch (e) {
|
|
9267
|
-
this._logger.error(`Could not add plugins: ${e.message}`);
|
|
9268
|
-
}
|
|
9276
|
+
this._initPluginHandler();
|
|
9269
9277
|
// finally init
|
|
9270
9278
|
_initDBs();
|
|
9271
9279
|
}
|