diff --git a/src/impulsegenerator.js b/src/impulsegenerator.js index 1b09d0d..e6512d2 100644 --- a/src/impulsegenerator.js +++ b/src/impulsegenerator.js @@ -8,13 +8,17 @@ class ImpulseGenerator extends EventEmitter { } start(timers) { + if (this.timersState) { + this.stop(); + } + this.timers = []; - timers.forEach(({ timerName, sampling }) => { - const timer = setInterval(() => { - this.emit(timerName); - }, sampling); - this.timers.push(timer); - }); + for (const timer of timers) { + const newTimer = setInterval(() => { + this.emit(timer.name); + }, timer.sampling); + this.timers.push(newTimer); + }; //update state this.timersState = true; diff --git a/src/mainzone.js b/src/mainzone.js index c3a3515..81bd7fe 100644 --- a/src/mainzone.js +++ b/src/mainzone.js @@ -349,7 +349,7 @@ class MainZone extends EventEmitter { const sortInputsDisplayOrder = this.televisionService ? await this.displayOrder() : false; //start check state - this.denon.impulseGenerator.start([{ timerName: 'checkState', sampling: refreshInterval }]); + this.denon.impulseGenerator.start([{ name: 'checkState', sampling: refreshInterval }]); } catch (error) { this.emit('error', `Prepare accessory error: ${error}`); await new Promise(resolve => setTimeout(resolve, 15000)); diff --git a/src/surround.js b/src/surround.js index d1c2cad..610582d 100644 --- a/src/surround.js +++ b/src/surround.js @@ -317,7 +317,7 @@ class Surround extends EventEmitter { const sortInputsDisplayOrder = this.televisionService ? await this.displayOrder() : false; //start check state - this.denon.impulseGenerator.start([{ timerName: 'checkState', sampling: refreshInterval }]); + this.denon.impulseGenerator.start([{ name: 'checkState', sampling: refreshInterval }]); } catch (error) { this.emit('error', `prepare accessory error: ${error}`); await new Promise(resolve => setTimeout(resolve, 15000)); diff --git a/src/zone2.js b/src/zone2.js index ef454c6..e44f97c 100644 --- a/src/zone2.js +++ b/src/zone2.js @@ -347,7 +347,7 @@ class Zone2 extends EventEmitter { const sortInputsDisplayOrder = this.televisionService ? await this.displayOrder() : false; //start check state - this.denon.impulseGenerator.start([{ timerName: 'checkState', sampling: refreshInterval }]); + this.denon.impulseGenerator.start([{ name: 'checkState', sampling: refreshInterval }]); } catch (error) { this.emit('error', `prepare accessory error: ${error}`); await new Promise(resolve => setTimeout(resolve, 15000)); diff --git a/src/zone3.js b/src/zone3.js index 051c5d2..f0774d3 100644 --- a/src/zone3.js +++ b/src/zone3.js @@ -347,7 +347,7 @@ class Zone3 extends EventEmitter { const sortInputsDisplayOrder = this.televisionService ? await this.displayOrder() : false; //start check state - this.denon.impulseGenerator.start([{ timerName: 'checkState', sampling: refreshInterval }]); + this.denon.impulseGenerator.start([{ name: 'checkState', sampling: refreshInterval }]); } catch (error) { this.emit('error', `prepare accessory error: ${error}`); await new Promise(resolve => setTimeout(resolve, 15000));