klf-200-api
Version:
This module provides a wrapper to the socket API of a Velux KLF-200 interface. You will need at least firmware 0.2.0.0.71 on your KLF interface for this library to work.
78 lines • 3.43 kB
JavaScript
"use strict";
import { GW_FRAME_COMMAND_REQ } from "./common.js";
import { LockTime as lt, } from "./GW_COMMAND.js";
export class GW_COMMAND_SEND_REQ extends GW_FRAME_COMMAND_REQ {
Nodes;
MainValue;
PriorityLevel;
CommandOriginator;
ParameterActive;
FunctionalParameters;
PriorityLevelLock;
PriorityLevels;
LockTime;
constructor(Nodes, MainValue, PriorityLevel = 3, CommandOriginator = 1, ParameterActive = 0, FunctionalParameters = [], PriorityLevelLock = 0, PriorityLevels = [], LockTime = Infinity) {
super(66);
this.Nodes = Nodes;
this.MainValue = MainValue;
this.PriorityLevel = PriorityLevel;
this.CommandOriginator = CommandOriginator;
this.ParameterActive = ParameterActive;
this.FunctionalParameters = FunctionalParameters;
this.PriorityLevelLock = PriorityLevelLock;
this.PriorityLevels = PriorityLevels;
this.LockTime = LockTime;
const buff = this.Data.subarray(this.offset);
buff.writeUInt16BE(this.SessionID, 0);
buff.writeUInt8(this.CommandOriginator, 2);
buff.writeUInt8(this.PriorityLevel, 3);
buff.writeUInt8(this.ParameterActive, 4);
let FPI1 = 0;
let FPI2 = 0;
for (let functionalParameterIndex = 0; functionalParameterIndex < this.FunctionalParameters.length; functionalParameterIndex++) {
const functionalParameter = this.FunctionalParameters[functionalParameterIndex];
const functionalParameterID = functionalParameter.ID - 1;
if (functionalParameterID < 0 || functionalParameterID > 15)
throw new Error("Functional paramter ID out of range.");
if (functionalParameterID < 8) {
FPI1 |= 0x80 >>> functionalParameterID;
}
else {
FPI2 |= 0x80 >>> (functionalParameterID - 8);
}
buff.writeUInt16BE(functionalParameter.Value, 9 + 2 * functionalParameterID);
}
buff.writeUInt8(FPI1, 5);
buff.writeUInt8(FPI2, 6);
buff.writeUInt16BE(this.MainValue, 7);
// Multiple nodes are provided
if (Array.isArray(this.Nodes)) {
if (this.Nodes.length > 20)
throw new Error("Too many nodes.");
buff.writeUInt8(this.Nodes.length, 41);
for (let nodeIndex = 0; nodeIndex < this.Nodes.length; nodeIndex++) {
const node = this.Nodes[nodeIndex];
buff.writeUInt8(node, 42 + nodeIndex);
}
}
else {
buff.writeUInt8(1, 41);
buff.writeUInt8(this.Nodes, 42);
}
buff.writeUInt8(this.PriorityLevelLock, 62);
if (this.PriorityLevels.length > 8)
throw new Error("Too many priority levels.");
let PLI = 0;
for (let pliIndex = 0; pliIndex < this.PriorityLevels.length; pliIndex++) {
const pli = this.PriorityLevels[pliIndex];
if (pli < 0 || pli > 3)
throw new Error("Priority level lock out of range.");
PLI <<= 2;
PLI |= pli;
}
PLI <<= 2 * (8 - this.PriorityLevels.length); // Shift remaining, if provided priority leves are less than 8
buff.writeUInt16BE(PLI, 63);
buff.writeUInt8(lt.lockTimeTolockTimeValue(this.LockTime), 65);
}
}
//# sourceMappingURL=GW_COMMAND_SEND_REQ.js.map