@iobroker/js-controller-adapter 6.0.7 → 6.0.9
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 +6 -0
- package/build/cjs/lib/adapter/adapter.js +190 -186
- package/build/cjs/lib/adapter/adapter.js.map +2 -2
- package/build/esm/lib/adapter/adapter.d.ts +6 -0
- package/build/esm/lib/adapter/adapter.d.ts.map +1 -1
- package/build/esm/lib/adapter/adapter.js +243 -234
- package/build/esm/lib/adapter/adapter.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +12 -11
|
@@ -575,6 +575,14 @@ export class AdapterClass extends EventEmitter {
|
|
|
575
575
|
this.setExecutableCapabilities = tools.setExecutableCapabilities;
|
|
576
576
|
this._init();
|
|
577
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* Get the adapter scoped package identifier of a node module
|
|
580
|
+
*
|
|
581
|
+
* @param moduleName name of the node module
|
|
582
|
+
*/
|
|
583
|
+
getAdapterScopedPackageIdentifier(moduleName) {
|
|
584
|
+
return getAdapterScopedPackageIdentifier({ moduleName, namespace: this.namespace });
|
|
585
|
+
}
|
|
578
586
|
/**
|
|
579
587
|
* Install specified npm module
|
|
580
588
|
*
|
|
@@ -8288,8 +8296,8 @@ export class AdapterClass extends EventEmitter {
|
|
|
8288
8296
|
}
|
|
8289
8297
|
if (this.pluginHandler.isPluginActive(pluginName) !== state.val) {
|
|
8290
8298
|
if (state.val) {
|
|
8291
|
-
if (!this.pluginHandler.
|
|
8292
|
-
this.pluginHandler.
|
|
8299
|
+
if (!this.pluginHandler.isPluginInstanciated(pluginName)) {
|
|
8300
|
+
this.pluginHandler.instanciatePlugin(pluginName, this.pluginHandler.getPluginConfig(pluginName) || {}, thisDir);
|
|
8293
8301
|
this.pluginHandler.setDatabaseForPlugin(pluginName, this.#objects, this.#states);
|
|
8294
8302
|
this.pluginHandler.initPlugin(pluginName, this.adapterConfig || {});
|
|
8295
8303
|
}
|
|
@@ -8677,264 +8685,265 @@ export class AdapterClass extends EventEmitter {
|
|
|
8677
8685
|
return;
|
|
8678
8686
|
}
|
|
8679
8687
|
this.pluginHandler.setDatabaseForPlugins(this.#objects, this.#states);
|
|
8680
|
-
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
|
|
8689
|
-
|
|
8688
|
+
this.pluginHandler.initPlugins(adapterConfig || {}, async () => {
|
|
8689
|
+
if (!this.#states || !this.#objects || this.terminated) {
|
|
8690
|
+
// if adapterState was destroyed,we should not continue
|
|
8691
|
+
return;
|
|
8692
|
+
}
|
|
8693
|
+
this.#states.subscribe(`system.adapter.${this.namespace}.plugins.*`);
|
|
8694
|
+
if (this._options.instance === undefined) {
|
|
8695
|
+
if (!adapterConfig || !('common' in adapterConfig) || !adapterConfig.common.enabled) {
|
|
8696
|
+
if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.enabled !== undefined) {
|
|
8697
|
+
!this._config.isInstall && this._logger.error(`${this.namespaceLog} adapter disabled`);
|
|
8698
|
+
}
|
|
8699
|
+
else {
|
|
8700
|
+
!this._config.isInstall &&
|
|
8701
|
+
this._logger.error(`${this.namespaceLog} no config found for adapter`);
|
|
8702
|
+
}
|
|
8703
|
+
if (!this._config.isInstall && (!process.argv || !this._config.forceIfDisabled)) {
|
|
8704
|
+
const id = `system.adapter.${this.namespace}`;
|
|
8705
|
+
this.outputCount += 2;
|
|
8706
|
+
this.#states.setState(`${id}.alive`, { val: true, ack: true, expire: 30, from: id });
|
|
8707
|
+
let done = false;
|
|
8708
|
+
this.#states.setState(`${id}.connected`, {
|
|
8709
|
+
val: true,
|
|
8710
|
+
ack: true,
|
|
8711
|
+
expire: 30,
|
|
8712
|
+
from: id
|
|
8713
|
+
}, () => {
|
|
8714
|
+
if (!done) {
|
|
8715
|
+
done = true;
|
|
8716
|
+
this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND);
|
|
8717
|
+
}
|
|
8718
|
+
});
|
|
8719
|
+
setTimeout(() => {
|
|
8720
|
+
if (!done) {
|
|
8721
|
+
done = true;
|
|
8722
|
+
this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND);
|
|
8723
|
+
}
|
|
8724
|
+
}, 1_000);
|
|
8725
|
+
return;
|
|
8726
|
+
}
|
|
8727
|
+
}
|
|
8728
|
+
if (!this._config.isInstall && (!adapterConfig || !('_id' in adapterConfig))) {
|
|
8729
|
+
this._logger.error(`${this.namespaceLog} invalid config: no _id found`);
|
|
8730
|
+
this.terminate(EXIT_CODES.INVALID_ADAPTER_ID);
|
|
8731
|
+
return;
|
|
8732
|
+
}
|
|
8733
|
+
let name;
|
|
8734
|
+
let instance;
|
|
8735
|
+
if (!this._config.isInstall) {
|
|
8736
|
+
// @ts-expect-error
|
|
8737
|
+
const tmp = adapterConfig._id.match(/^system\.adapter\.([a-zA-Z0-9-_]+)\.([0-9]+)$/);
|
|
8738
|
+
if (!tmp) {
|
|
8739
|
+
this._logger.error(`${this.namespaceLog} invalid config`);
|
|
8740
|
+
this.terminate(EXIT_CODES.INVALID_ADAPTER_ID);
|
|
8741
|
+
return;
|
|
8742
|
+
}
|
|
8743
|
+
name = tmp[1];
|
|
8744
|
+
instance = parseInt(tmp[2]) || 0;
|
|
8690
8745
|
}
|
|
8691
8746
|
else {
|
|
8692
|
-
|
|
8747
|
+
name = this.name;
|
|
8748
|
+
instance = 0;
|
|
8749
|
+
adapterConfig = adapterConfig || {
|
|
8750
|
+
// @ts-expect-error protectedNative exists on instance objects
|
|
8751
|
+
common: { mode: 'once', name: name, protectedNative: [] },
|
|
8752
|
+
native: {}
|
|
8753
|
+
};
|
|
8693
8754
|
}
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
from: id
|
|
8704
|
-
}, () => {
|
|
8705
|
-
if (!done) {
|
|
8706
|
-
done = true;
|
|
8707
|
-
this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND);
|
|
8708
|
-
}
|
|
8709
|
-
});
|
|
8710
|
-
setTimeout(() => {
|
|
8711
|
-
if (!done) {
|
|
8712
|
-
done = true;
|
|
8713
|
-
this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND);
|
|
8755
|
+
// @ts-expect-error
|
|
8756
|
+
if (adapterConfig.common.loglevel && !this.overwriteLogLevel) {
|
|
8757
|
+
// set configured in DB log level
|
|
8758
|
+
for (const trans of Object.values(this._logger.transports)) {
|
|
8759
|
+
// set the loglevel on transport only if no loglevel was pinned in log config
|
|
8760
|
+
// @ts-expect-error it is our own modification
|
|
8761
|
+
if (!trans._defaultConfigLoglevel) {
|
|
8762
|
+
// @ts-expect-error
|
|
8763
|
+
trans.level = adapterConfig.common.loglevel;
|
|
8714
8764
|
}
|
|
8715
|
-
}
|
|
8716
|
-
|
|
8765
|
+
}
|
|
8766
|
+
// @ts-expect-error
|
|
8767
|
+
this._config.log.level = adapterConfig.common.loglevel;
|
|
8717
8768
|
}
|
|
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) {
|
|
8727
8769
|
// @ts-expect-error
|
|
8728
|
-
|
|
8729
|
-
|
|
8730
|
-
|
|
8731
|
-
|
|
8732
|
-
|
|
8770
|
+
this.name = adapterConfig.common.name;
|
|
8771
|
+
this.instance = instance;
|
|
8772
|
+
this.namespace = `${name}.${instance}`;
|
|
8773
|
+
this.namespaceLog = this.namespace + (this.startedInCompactMode ? ' (COMPACT)' : ` (${process.pid})`);
|
|
8774
|
+
if (!this.startedInCompactMode) {
|
|
8775
|
+
process.title = `io.${this.namespace}`;
|
|
8776
|
+
}
|
|
8777
|
+
// @ts-expect-error
|
|
8778
|
+
this.config = adapterConfig.native;
|
|
8779
|
+
// @ts-expect-error
|
|
8780
|
+
this.host = adapterConfig.common.host;
|
|
8781
|
+
// @ts-expect-error
|
|
8782
|
+
this.common = adapterConfig.common;
|
|
8783
|
+
if (
|
|
8784
|
+
// @ts-expect-error
|
|
8785
|
+
adapterConfig.common.mode === 'schedule' ||
|
|
8786
|
+
// @ts-expect-error
|
|
8787
|
+
adapterConfig.common.mode === 'once') {
|
|
8788
|
+
this.stop = params => this._stop({ ...params, isPause: true });
|
|
8789
|
+
}
|
|
8790
|
+
else if (this.startedInCompactMode) {
|
|
8791
|
+
this.stop = params => this._stop({ ...params, isPause: false });
|
|
8792
|
+
this.kill = this.stop;
|
|
8793
|
+
}
|
|
8794
|
+
else {
|
|
8795
|
+
this.stop = params => this._stop({ ...params, isPause: false });
|
|
8796
|
+
}
|
|
8797
|
+
// Monitor logging state
|
|
8798
|
+
this.#states.subscribe(`${SYSTEM_ADAPTER_PREFIX}*.logging`);
|
|
8799
|
+
if (typeof this._options.message === 'function' &&
|
|
8800
|
+
// @ts-expect-error, we should infer correctly that this is an InstanceObject in this case
|
|
8801
|
+
!isMessageboxSupported(adapterConfig.common)) {
|
|
8802
|
+
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.`);
|
|
8803
|
+
// @ts-expect-error we should infer adapterConfig correctly
|
|
8804
|
+
}
|
|
8805
|
+
else if (isMessageboxSupported(adapterConfig.common)) {
|
|
8806
|
+
this.mboxSubscribed = true;
|
|
8807
|
+
this.#states.subscribeMessage(`system.adapter.${this.namespace}`);
|
|
8733
8808
|
}
|
|
8734
|
-
name = tmp[1];
|
|
8735
|
-
instance = parseInt(tmp[2]) || 0;
|
|
8736
8809
|
}
|
|
8737
8810
|
else {
|
|
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
|
-
}
|
|
8746
|
-
// @ts-expect-error
|
|
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;
|
|
8755
|
-
}
|
|
8756
|
-
}
|
|
8757
8811
|
// @ts-expect-error
|
|
8758
|
-
this.
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
this.
|
|
8770
|
-
|
|
8771
|
-
this.
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
if (
|
|
8812
|
+
this.name = adapterConfig.name || this.name;
|
|
8813
|
+
// @ts-expect-error
|
|
8814
|
+
this.instance = adapterConfig.instance || 0;
|
|
8815
|
+
this.namespace = `${this.name}.${this.instance}`;
|
|
8816
|
+
this.namespaceLog = this.namespace + (this.startedInCompactMode ? ' (COMPACT)' : ` (${process.pid})`);
|
|
8817
|
+
// @ts-expect-error
|
|
8818
|
+
this.config = adapterConfig.native || {};
|
|
8819
|
+
// @ts-expect-error
|
|
8820
|
+
this.common = adapterConfig.common || {};
|
|
8821
|
+
this.host = this.common?.host || tools.getHostName() || os.hostname();
|
|
8822
|
+
}
|
|
8823
|
+
this.adapterConfig = adapterConfig;
|
|
8824
|
+
this._utils = new Validator(this.#objects, this.#states, this.namespaceLog, this._logger, this.namespace, this._namespaceRegExp);
|
|
8825
|
+
this.log = new Log(this.namespaceLog, this._config.log.level, this._logger);
|
|
8826
|
+
await this._createInstancesObjects(adapterConfig);
|
|
8827
|
+
// auto oObjects
|
|
8828
|
+
if (this._options.objects) {
|
|
8829
|
+
this.oObjects = await this.getAdapterObjectsAsync();
|
|
8830
|
+
await this.subscribeObjectsAsync('*');
|
|
8831
|
+
}
|
|
8832
|
+
// initialize the system secret
|
|
8833
|
+
await this.getSystemSecret();
|
|
8834
|
+
// Decrypt all attributes of encryptedNative
|
|
8835
|
+
const promises = [];
|
|
8775
8836
|
// @ts-expect-error
|
|
8776
|
-
adapterConfig.
|
|
8837
|
+
if (Array.isArray(adapterConfig.encryptedNative)) {
|
|
8777
8838
|
// @ts-expect-error
|
|
8778
|
-
adapterConfig.
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8839
|
+
for (const attr of adapterConfig.encryptedNative) {
|
|
8840
|
+
// we can only decrypt strings
|
|
8841
|
+
// @ts-expect-error
|
|
8842
|
+
if (typeof this.config[attr] === 'string') {
|
|
8843
|
+
promises.push(this.getEncryptedConfig(attr)
|
|
8844
|
+
// @ts-expect-error
|
|
8845
|
+
.then(decryptedValue => (this.config[attr] = decryptedValue))
|
|
8846
|
+
.catch(e => this._logger.error(`${this.namespaceLog} Can not decrypt attribute ${attr}: ${e.message}`)));
|
|
8847
|
+
}
|
|
8848
|
+
}
|
|
8784
8849
|
}
|
|
8785
8850
|
else {
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
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
|
|
8795
|
-
}
|
|
8796
|
-
else if (isMessageboxSupported(adapterConfig.common)) {
|
|
8797
|
-
this.mboxSubscribed = true;
|
|
8798
|
-
this.#states.subscribeMessage(`system.adapter.${this.namespace}`);
|
|
8799
|
-
}
|
|
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}`)));
|
|
8851
|
+
// remove encrypted native from supported features, otherwise this can cause issues, if no adapter upload done with js-c v3+ yet
|
|
8852
|
+
const idx = this.SUPPORTED_FEATURES.indexOf('ADAPTER_AUTO_DECRYPT_NATIVE');
|
|
8853
|
+
if (idx !== -1) {
|
|
8854
|
+
this.SUPPORTED_FEATURES.splice(idx, 1);
|
|
8838
8855
|
}
|
|
8839
8856
|
}
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
this.SUPPORTED_FEATURES.splice(idx, 1);
|
|
8857
|
+
// Wait till all attributes decrypted
|
|
8858
|
+
await Promise.all(promises);
|
|
8859
|
+
if (!this.#states) {
|
|
8860
|
+
// if this.adapterStates was destroyed, we should not continue
|
|
8861
|
+
return;
|
|
8846
8862
|
}
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
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
|
|
8863
|
+
this.outputCount++;
|
|
8864
|
+
// set current loglevel
|
|
8865
|
+
this.#states.setState(`system.adapter.${this.namespace}.logLevel`, {
|
|
8866
|
+
val: this._config.log.level,
|
|
8867
|
+
ack: true,
|
|
8868
|
+
from: `system.adapter.${this.namespace}`
|
|
8872
8869
|
});
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
val: !!this.startedInCompactMode
|
|
8870
|
+
if (this._options.instance === undefined) {
|
|
8871
|
+
this.version = this.pack?.version
|
|
8872
|
+
? this.pack.version
|
|
8873
|
+
: this.ioPack?.common
|
|
8874
|
+
? this.ioPack.common.version
|
|
8875
|
+
: 'unknown';
|
|
8876
|
+
// display if it's a non-official version - only if installedFrom is explicitly given and differs it's not npm
|
|
8877
|
+
const isNpmVersion = isInstalledFromNpm({
|
|
8878
|
+
adapterName: this.name,
|
|
8879
|
+
installedFrom: this.ioPack.common.installedFrom
|
|
8884
8880
|
});
|
|
8885
|
-
this.
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
this
|
|
8890
|
-
this
|
|
8891
|
-
|
|
8892
|
-
this.#states.setState(`${id}.
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
tools.measureEventLoopLag(1_000, lag => {
|
|
8897
|
-
if (lag) {
|
|
8898
|
-
this.eventLoopLags.push(lag);
|
|
8899
|
-
}
|
|
8881
|
+
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}`);
|
|
8882
|
+
this._config.system = this._config.system || {};
|
|
8883
|
+
this._config.system.statisticsInterval = parseInt(this._config.system.statisticsInterval, 10) || 15_000;
|
|
8884
|
+
if (!this._config.isInstall) {
|
|
8885
|
+
this._reportInterval = setInterval(() => this._reportStatus(), this._config.system.statisticsInterval);
|
|
8886
|
+
this._reportStatus();
|
|
8887
|
+
const id = `system.adapter.${this.namespace}`;
|
|
8888
|
+
this.#states.setState(`${id}.compactMode`, {
|
|
8889
|
+
ack: true,
|
|
8890
|
+
from: id,
|
|
8891
|
+
val: this.startedInCompactMode
|
|
8900
8892
|
});
|
|
8893
|
+
this.outputCount++;
|
|
8894
|
+
if (this.startedInCompactMode) {
|
|
8895
|
+
this.#states.setState(`${id}.cpu`, { ack: true, from: id, val: 0 });
|
|
8896
|
+
this.#states.setState(`${id}.cputime`, { ack: true, from: id, val: 0 });
|
|
8897
|
+
this.#states.setState(`${id}.memRss`, { val: 0, ack: true, from: id });
|
|
8898
|
+
this.#states.setState(`${id}.memHeapTotal`, { val: 0, ack: true, from: id });
|
|
8899
|
+
this.#states.setState(`${id}.memHeapUsed`, { val: 0, ack: true, from: id });
|
|
8900
|
+
this.#states.setState(`${id}.eventLoopLag`, { val: 0, ack: true, from: id });
|
|
8901
|
+
this.outputCount += 6;
|
|
8902
|
+
}
|
|
8903
|
+
else {
|
|
8904
|
+
tools.measureEventLoopLag(1_000, lag => {
|
|
8905
|
+
if (lag) {
|
|
8906
|
+
this.eventLoopLags.push(lag);
|
|
8907
|
+
}
|
|
8908
|
+
});
|
|
8909
|
+
}
|
|
8901
8910
|
}
|
|
8902
8911
|
}
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8912
|
+
if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.restartSchedule) {
|
|
8913
|
+
try {
|
|
8914
|
+
this._schedule = await import('node-schedule');
|
|
8915
|
+
}
|
|
8916
|
+
catch {
|
|
8917
|
+
this._logger.error(`${this.namespaceLog} Cannot load node-schedule. Scheduled restart is disabled`);
|
|
8918
|
+
}
|
|
8919
|
+
if (this._schedule) {
|
|
8920
|
+
this._logger.debug(`${this.namespaceLog} Schedule restart: ${adapterConfig.common.restartSchedule}`);
|
|
8921
|
+
this._restartScheduleJob = this._schedule.scheduleJob(adapterConfig.common.restartSchedule, () => {
|
|
8922
|
+
this._logger.info(`${this.namespaceLog} Scheduled restart.`);
|
|
8923
|
+
this._stop({ isPause: false, isScheduled: true });
|
|
8924
|
+
});
|
|
8925
|
+
}
|
|
8910
8926
|
}
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
this.
|
|
8914
|
-
|
|
8915
|
-
|
|
8927
|
+
// auto oStates
|
|
8928
|
+
if (this._options.states) {
|
|
8929
|
+
this.getStates('*', null, (err, _states) => {
|
|
8930
|
+
if (this._stopInProgress) {
|
|
8931
|
+
return;
|
|
8932
|
+
}
|
|
8933
|
+
this.oStates = _states;
|
|
8934
|
+
this.subscribeStates('*');
|
|
8935
|
+
if (this._firstConnection) {
|
|
8936
|
+
this._firstConnection = false;
|
|
8937
|
+
this._callReadyHandler();
|
|
8938
|
+
}
|
|
8939
|
+
this.adapterReady = true;
|
|
8916
8940
|
});
|
|
8917
8941
|
}
|
|
8918
|
-
|
|
8919
|
-
|
|
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
|
-
}
|
|
8942
|
+
else if (!this._stopInProgress) {
|
|
8943
|
+
this._callReadyHandler();
|
|
8931
8944
|
this.adapterReady = true;
|
|
8932
|
-
}
|
|
8933
|
-
}
|
|
8934
|
-
else if (!this._stopInProgress) {
|
|
8935
|
-
this._callReadyHandler();
|
|
8936
|
-
this.adapterReady = true;
|
|
8937
|
-
}
|
|
8945
|
+
}
|
|
8946
|
+
});
|
|
8938
8947
|
}
|
|
8939
8948
|
/**
|
|
8940
8949
|
* Calls the ready handler, if it is an install run it calls the install handler instead
|