Skip to content

Commit

Permalink
Fix bright_value not sent for the C/CW lights who doesn't have `w…
Browse files Browse the repository at this point in the history
…ork_mode` (#171)
  • Loading branch information
0x5e authored Dec 25, 2022
1 parent d5740d5 commit 3fd273d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/accessory/LightAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ export default class LightAccessory extends BaseAccessory {
}

inWhiteMode() {
if (this.getAccessoryType() === LightAccessoryType.C
|| this.getAccessoryType() === LightAccessoryType.CW) {
return true;
}

const mode = this.getSchema(...SCHEMA_CODE.WORK_MODE);
if (!mode) {
return false;
Expand All @@ -142,6 +147,10 @@ export default class LightAccessory extends BaseAccessory {
}

inColorMode() {
if (this.getAccessoryType() === LightAccessoryType.RGB) {
return true;
}

const mode = this.getSchema(...SCHEMA_CODE.WORK_MODE);
if (!mode) {
return false;
Expand Down Expand Up @@ -188,7 +197,6 @@ export default class LightAccessory extends BaseAccessory {
colorValue.v = Math.round(value as number * max / 100);
colorValue.v = limit(colorValue.v, min, max);
this.sendCommands([{ code: colorSchema.code, value: JSON.stringify(colorValue) }], true);
return;
} else if (this.inWhiteMode()) {
// White mode, set brightness to `brightness_value`
const brightSchema = this.getSchema(...SCHEMA_CODE.BRIGHTNESS)!;
Expand All @@ -198,6 +206,7 @@ export default class LightAccessory extends BaseAccessory {
this.sendCommands([{ code: brightSchema.code, value: brightValue }], true);
} else {
// Unsupported mode
this.log.warn('Neither color mode nor white mode.');
}
});

Expand Down

0 comments on commit 3fd273d

Please sign in to comment.