lifxlan
Version:
TypeScript library for controlling LIFX products over LAN
78 lines • 2.88 kB
JavaScript
import * as Encoding from '../encoding.js';
import { Type } from '../constants/index.js';
import { NOOP } from '../utils/index.js';
export function GetDeviceChainCommand() {
return {
type: Type.GetDeviceChain,
decode: Encoding.decodeStateDeviceChain,
defaultResponseMode: 'response',
};
}
export function Get64Command(tileIndex, length, x, y, width, onResponse) {
let tilesSeen = 0;
const responses = [];
const decode = (bytes, offsetRef, continuation, responseType) => {
let response;
if (responseType === Type.State64) {
response = Encoding.decodeState64(bytes, offsetRef);
tilesSeen++;
}
// Update continuation to indicate if more responses are expected
if (continuation) {
if (response) {
responses.push(response);
// Call user callback if provided
let shouldContinue = true;
if (onResponse) {
const result = onResponse(response);
shouldContinue = result !== false; // false = stop early
}
continuation.expectMore = shouldContinue && tilesSeen < length;
}
else {
// Unknown response type - still expect more responses
continuation.expectMore = tilesSeen < length;
}
}
return responses; // Always return the accumulated array
};
return {
type: Type.Get64,
payload: Encoding.encodeGet64(tileIndex, length, x, y, width),
decode,
defaultResponseMode: 'response',
};
}
export function SetUserPositionCommand(tileIndex, userX, userY) {
return {
type: Type.SetUserPosition,
payload: Encoding.encodeSetUserPosition(tileIndex, userX, userY),
decode: NOOP,
defaultResponseMode: 'ack-only',
};
}
export function Set64Command(tileIndex, length, x, y, width, duration, colors) {
return {
type: Type.Set64,
payload: Encoding.encodeSet64(tileIndex, length, x, y, width, duration, colors),
decode: NOOP,
defaultResponseMode: 'ack-only',
};
}
export function GetTileEffectCommand() {
return {
type: Type.GetTileEffect,
payload: Encoding.encodeGetTileEffect(),
decode: Encoding.decodeStateTileEffect,
defaultResponseMode: 'response',
};
}
export function SetTileEffectCommand(instanceid, effectType, speed, duration, skyType, cloudSaturationMin, paletteCount, palette) {
return {
type: Type.SetTileEffect,
payload: Encoding.encodeSetTileEffect(instanceid, effectType, speed, duration, skyType, cloudSaturationMin, paletteCount, palette),
decode: Encoding.decodeStateTileEffect,
defaultResponseMode: 'ack-only',
};
}
//# sourceMappingURL=tile.js.map