Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Aug 16, 2024
1 parent 537f0ad commit 69e3b6b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/impulsegenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/mainzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/surround.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/zone2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/zone3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 69e3b6b

Please sign in to comment.