@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.
@@ -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.isPluginInstantiated(pluginName)) {
8292
- this.pluginHandler.instantiatePlugin(pluginName, this.pluginHandler.getPluginConfig(pluginName) || {}, thisDir);
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
- 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`);
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
- !this._config.isInstall && this._logger.error(`${this.namespaceLog} no config found for adapter`);
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
- 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);
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
- }, 1_000);
8716
- return;
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
- 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;
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._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 (
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.common.mode === 'schedule' ||
8837
+ if (Array.isArray(adapterConfig.encryptedNative)) {
8777
8838
  // @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;
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
- this.stop = params => this._stop({ ...params, isPause: false });
8787
- }
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
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
- 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);
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
- // 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
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
- 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
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.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
- }
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
- 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`);
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
- 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 });
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
- // 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
- }
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