Skip to content

Commit

Permalink
feat: Add colorloop effect for color lights (#7479)
Browse files Browse the repository at this point in the history
* Add colorloop to light effect expose

* Adapt colorloop speed according to transition parameter

* add separate key stop_colorloop
  • Loading branch information
slugzero authored May 5, 2024
1 parent cd16388 commit b251e87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/converters/toZigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,17 @@ const converters2 = {
utils.assertString(value, key);
const lookup = {blink: 0, breathe: 1, okay: 2, channel_change: 11, finish_effect: 254, stop_effect: 255};
value = value.toLowerCase();
const payload = {effectid: utils.getFromLookup(value, lookup), effectvariant: 0};
await entity.command('genIdentify', 'triggerEffect', payload, utils.getOptions(meta.mapped, entity));
if (value === 'colorloop') {
const transition = meta.message.transition ?? 15;
utils.assertNumber(transition, 'transition');
const speed = Math.min(255, Math.max(1, Math.round(255 / transition)));
converters2.light_hue_saturation_move.convertSet(entity, 'hue_move', speed, meta);
} else if (value === 'stop_colorloop') {
converters2.light_hue_saturation_move.convertSet(entity, 'hue_move', 'stop', meta);
} else {
const payload = {effectid: utils.getFromLookup(value, lookup), effectvariant: 0};
await entity.command('genIdentify', 'triggerEffect', payload, utils.getOptions(meta.mapped, entity));
}
} else if (key === 'alert' || key === 'flash') { // Deprecated
let effectid = 0;
const lookup = {'select': 0x00, 'lselect': 0x01, 'none': 0xFF};
Expand Down
6 changes: 5 additions & 1 deletion src/lib/modernExtend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,11 @@ export function light(args?: LightArgs): ModernExtend {
const exposes: Expose[] = lightExpose;

if (args.effect) {
exposes.push(e.effect());
const effects = e.effect();
if (args.color) {
effects.values.push('colorloop', 'stop_colorloop');
}
exposes.push(effects);
toZigbee.push(tz.effect);
}

Expand Down

0 comments on commit b251e87

Please sign in to comment.