Skip to content

Commit

Permalink
Fix: Only set the mode if it differs from the current one
Browse files Browse the repository at this point in the history
Closes #68
  • Loading branch information
Andrey Okonetchnikov committed Aug 29, 2020
1 parent a7ec540 commit 535c7c1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions bulbs/moonlight.js
Expand Up @@ -39,14 +39,17 @@ const MoonlightMode = Device =>

async setMoonlightMode(state) {
const { brightness: transition = 400 } = this.config.transitions || {};
this.log.debug(
`Setting ${state ? '🌙' : '☀️'} mode on device ${this.did}`
);
await this.sendCmd({
method: 'set_power',
params: ['on', 'smooth', transition, state ? 5 : 1],
});
this.activeMode = state ? 1 : 0;
// Only set the mode if it differs from the current one. Closes #68
if (state !== this.activeMode) {
this.log.debug(
`Setting ${state ? '🌙' : '☀️'} mode on device ${this.did}`
);
await this.sendCmd({
method: 'set_power',
params: ['on', 'smooth', transition, state ? 5 : 1],
});
this.activeMode = state ? 1 : 0;
}
}

updateStateFromProp(prop, value) {
Expand Down

0 comments on commit 535c7c1

Please sign in to comment.