lifxlan
Version:
TypeScript library for controlling LIFX products over LAN
119 lines • 4.69 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetDeviceChainCommand = GetDeviceChainCommand;
exports.Get64Command = Get64Command;
exports.SetUserPositionCommand = SetUserPositionCommand;
exports.Set64Command = Set64Command;
exports.GetTileEffectCommand = GetTileEffectCommand;
exports.SetTileEffectCommand = SetTileEffectCommand;
const Encoding = __importStar(require("../encoding.js"));
const index_js_1 = require("../constants/index.js");
const index_js_2 = require("../utils/index.js");
function GetDeviceChainCommand() {
return {
type: index_js_1.Type.GetDeviceChain,
decode: Encoding.decodeStateDeviceChain,
defaultResponseMode: 'response',
};
}
function Get64Command(tileIndex, length, x, y, width, onResponse) {
let tilesSeen = 0;
const responses = [];
const decode = (bytes, offsetRef, continuation, responseType) => {
let response;
if (responseType === index_js_1.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: index_js_1.Type.Get64,
payload: Encoding.encodeGet64(tileIndex, length, x, y, width),
decode,
defaultResponseMode: 'response',
};
}
function SetUserPositionCommand(tileIndex, userX, userY) {
return {
type: index_js_1.Type.SetUserPosition,
payload: Encoding.encodeSetUserPosition(tileIndex, userX, userY),
decode: index_js_2.NOOP,
defaultResponseMode: 'ack-only',
};
}
function Set64Command(tileIndex, length, x, y, width, duration, colors) {
return {
type: index_js_1.Type.Set64,
payload: Encoding.encodeSet64(tileIndex, length, x, y, width, duration, colors),
decode: index_js_2.NOOP,
defaultResponseMode: 'ack-only',
};
}
function GetTileEffectCommand() {
return {
type: index_js_1.Type.GetTileEffect,
payload: Encoding.encodeGetTileEffect(),
decode: Encoding.decodeStateTileEffect,
defaultResponseMode: 'response',
};
}
function SetTileEffectCommand(instanceid, effectType, speed, duration, skyType, cloudSaturationMin, paletteCount, palette) {
return {
type: index_js_1.Type.SetTileEffect,
payload: Encoding.encodeSetTileEffect(instanceid, effectType, speed, duration, skyType, cloudSaturationMin, paletteCount, palette),
decode: Encoding.decodeStateTileEffect,
defaultResponseMode: 'ack-only',
};
}
//# sourceMappingURL=tile.js.map