homebridge-smartsystem
Version:
SmartServer (Proxy Websockets to TCP sockets, Smappee MQTT, Duotecno IP Nodes, Homekit interface)
831 lines • 33 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Master = void 0;
const protocol_1 = require("./protocol");
const types_1 = require("./types");
const logger_1 = require("./logger");
const base_1 = require("../server/base");
const Q_1 = require("./Q");
const smartsocket_1 = require("./smartsocket");
class Master extends base_1.Base {
// command was sent, no response received yet
/* system.config: {
"socketserver": "akiworks.be",
"socketport": 9999,
"mood": "sfeer",
"cmasters": [
{
"address": "192.168.0.98",
"port": 5001,
"password": "duotecno",
"name": "Smartbox",
"active": false,
"debug": false
},
{
"address": "gm.coppieters.be",
"port": 5005,
"password": "duotecno",
"name": "IP Master GM",
"active": true,
"debug": false
}
],
"cunits": [
{
"active": "Y",
"group": 0,
"name": "rgb|Hue1",
"displayName": "Lamp - Brightness",
"type": 1,
"masterAddress": "gm.coppieters.be",
"masterPort": 5005,
"logicalNodeAddress": 6,
"logicalAddress": 38
},
{
"active": "Y",
"group": 0,
"name": "rgB|Hue1",
"displayName": "Lamp - Hue",
"type": 1,
"masterAddress": "gm.coppieters.be",
"masterPort": 5005,
"logicalNodeAddress": 6,
"logicalAddress": 37
},
{
"active": "Y",
"group": 0,
"name": "rGb|Hue1",
"displayName": "rGb Hue1",
"type": 1,
"masterAddress": "gm.coppieters.be",
"masterPort": 5005,
"logicalNodeAddress": 6,
"logicalAddress": 36
},
{
"active": "Y",
"group": 0,
"name": "Rgb|Hue1",
"displayName": "Rgb Hue1",
"type": 1,
"masterAddress": "gm.coppieters.be",
"masterPort": 5005,
"logicalNodeAddress": 6,
"logicalAddress": 35
},
{
"active": "Y",
"group": 0,
"name": "Sticks",
"displayName": "Sticks",
"type": 1,
"masterAddress": "gm.coppieters.be",
"masterPort": 5005,
"logicalNodeAddress": 6,
"logicalAddress": 34
},
{
"active": "Y",
"group": 0,
"name": "Vintage",
"displayName": "Vintage",
"type": 1,
"masterAddress": "gm.coppieters.be",
"masterPort": 5005,
"logicalNodeAddress": 6,
"logicalAddress": 33
},
{
"active": "Y",
"group": 0,
"name": "Driveway",
"displayName": "Driveway",
"type": 2,
"masterAddress": "gm.coppieters.be",
"masterPort": 5005,
"logicalNodeAddress": 6,
"logicalAddress": 40
},
{
"active": "Y",
"group": 0,
"name": "Trees",
"displayName": "Trees",
"type": 2,
"masterAddress": "gm.coppieters.be",
"masterPort": 5005,
"logicalNodeAddress": 6,
"logicalAddress": 39
}
]
}
*/
constructor(system, config) {
super("master", types_1.Sanitizers.masterConfig(config));
this.protocol = 0; // major * 100 + minor
this.version = 0; // idem
this.registers = {};
this.resolveLogin = null;
this.Q = new Q_1.Q();
// save my eco system
this.system = system;
// all nodes in this master
this.nodes = [];
this.nrNodes = 0;
this.schedule = 0;
this.date = null;
// connection to an IP node / smartbox
this.socket = null;
this.isOpen = false;
this.isLoggedIn = false;
this.closing = false;
// incoming data
this.buffer = "";
// init to v1.00
this.version = 100;
this.protocol = 100;
}
getName() {
return this.config.name || "master";
}
getSort() {
return this.getName().toLowerCase();
}
// overwrite to add IP address
log(msg) {
(0, logger_1.log)("master", this.getAddress() + ": " + msg);
}
info(msg) {
(0, logger_1.debug)("master", this.getAddress() + ": " + msg);
}
err(msg) {
(0, logger_1.log)("master", this.getAddress() + ": " + msg);
}
writeConfig(config, fn) {
// overwrite: don't do anything, all is stored in the system-config
}
getConfig() {
return this.config;
}
hasAddress(ip) {
return this.config.address === ip;
}
getAddress() {
return this.config.address;
}
getPort() {
return this.config.port;
}
hasPort(port) {
return this.config.port == port;
}
getURL() {
return this.config.address + ":" + this.config.port;
}
inMultiNode() {
return (this.nodes.length > 1);
}
same(master, port) {
if (typeof master === "string") {
if (typeof port === "undefined") {
// master is probably url ip:port
const url = master.split(":");
master = url[0];
port = parseInt(url[1] || "5001");
}
return this.hasAddress(master) && this.hasPort(port);
}
else {
return master && this.hasAddress(master.getAddress()) && this.hasPort(master.getPort());
}
}
/* ************* */
/* Communication */
/* ************* */
open(cnt = 1) {
return __awaiter(this, void 0, void 0, function* () {
// open a socket to the master
// check to see if for some reason there is still a heartbeat around???
if (this.beater && this.closing) {
this.stopHeartbeat("We still had a heartbeat timer, but were asked for a new socket... ###############");
}
try {
// params 3-6: data message, closed, log and error functions
this.socket = yield (0, smartsocket_1.getSocket)(this.config.address, this.config.port, (msg) => {
this.handleData(msg);
}, (end) => {
this.isOpen = false;
this.isLoggedIn = false;
if (this.closing) {
this.log("end -> socket got closed as requested");
this.closing = false;
}
else {
// our program didn't request the close, on next send it should automatically be reopened in Master.send()
this.log("end -> socket got unexpectedly disconnected -> will be reopened on next send ###############");
}
// stop sending heartbeats
this.stopHeartbeat("Stopping the heartbeat because the socket received and 'end'");
}, (logMessage) => {
this.log(logMessage);
}, (err) => {
this.err(err);
// on error restart the connection... you never know
this.forceClose();
});
this.isOpen = true;
this.closing = false;
this.log("master opened -> " + this.config.address);
// close the socket on timeouts, normally it should be automatically reopened
if (this.socket)
this.socket.addListener("timeout", () => this.forceClose());
}
catch (e) {
this.log("Open socket on -> " + this.config.address + " had an error: " + JSON.stringify(e));
}
this.startHeartbeat();
});
}
forceClose() {
return __awaiter(this, void 0, void 0, function* () {
try {
this.log("master force closed");
//console.log("*HB* master force closed");
this.isOpen = false;
this.isLoggedIn = false;
this.closing = false;
this.stopHeartbeat("Stopping heartbeat because we are force-closing the socket");
this.socket.destroy();
}
catch (e) {
this.log("Error while force-closing socket: " + JSON.stringify(e));
}
});
}
stopHeartbeat(msg, dontShow = false) {
if (this.beater) {
clearInterval(this.beater);
this.beater = null;
this.lastHeartbeat = 0;
if (msg)
this.log("*HB* " + msg);
}
else if (!dontShow) {
this.err("*HB* There was no heartbeat when receiving: " + msg);
}
}
startHeartbeat() {
// setup a heartbeat
const kInterval = 30 * 1000;
if (this.beater)
clearInterval(this.beater);
this.beater = setInterval(() => {
this.info("*HB* heartbeat time at " + new Date());
if (this.lastHeartbeat && ((new Date().getTime() - this.lastHeartbeat) > 2.5 * kInterval)) {
this.err("*HB* Didn't receive a heartbeat in 2.5 times our interval -> try to close manually");
if (this.isOpen) {
this.forceClose();
}
}
// always try to send a heartbeat, even if we're late.
this.send(protocol_1.Protocol.buildHeartbeat());
//console.log("*HB* send HB at " + new Date());
}, kInterval);
this.log("Heartbeat timer started");
}
close(closing = true) {
return __awaiter(this, void 0, void 0, function* () {
if (this.isOpen) {
const message = protocol_1.Protocol.buildDisconnect();
try {
this.closing = closing;
this.log("master closing -> " + this.config.address);
yield this.send(message);
// server will close the socket, no need to call socket.close()
}
catch (err) {
this.err("Disconnect failure: " + err);
}
}
});
}
login() {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
try {
const message = protocol_1.Protocol.buildLogin(this.config.password);
protocol_1.Protocol.write(this.socket, message);
// to be called when logged in
this.resolveLogin = resolve;
}
catch (err) {
this.resolveLogin = null;
this.err("Login call failed: " + err);
reject(false);
}
});
});
}
send(message) {
return __awaiter(this, void 0, void 0, function* () {
return this.Q.exec(() => __awaiter(this, void 0, void 0, function* () {
if (!this.isOpen) {
this.log("Opening socket because we receive a 'send' request, but socket was closed.");
yield this.open();
if (!(yield this.login())) {
return types_1.WriteError.writeFatal;
}
}
return protocol_1.Protocol.write(this.socket, message);
}));
});
}
handleData(message) {
// put the incoming data into a buffer and only use complete data
this.buffer += message;
while ((this.buffer.length > 0) && this.processData())
;
}
processData() {
// fetch next message and store the rest of unused data (if any)
const next = protocol_1.Protocol.nextMessage(this.buffer);
this.buffer = next.rest;
if (!next.cmd) {
return false;
}
else {
// don't log all incoming (no time, no sensor status messages)
if ((next.cmd != protocol_1.Rec.TimeDateStatus) && (next.cmd != protocol_1.Rec.Sensor))
this.info("received -> " + (0, protocol_1.recName)(next.cmd) + " -> " + ((!next.message) ?
"--" : ((next.message instanceof Array) ? next.message.join(",") : next.message)));
this.Q.do();
if (next.isStatus) {
this.receiveStatus(next);
// non-unit specific info
}
else if (next.cmd === protocol_1.Rec.TimeDateStatus) {
this.receiveDateTime(next.message);
}
else if (next.cmd === protocol_1.Rec.Info) {
this.receiveInfo(next);
}
else if (next.cmd === protocol_1.Rec.HeartbeatStatus) {
this.receiveHeartbeat(next.message);
}
else if (next.cmd === protocol_1.Rec.ConnectStatus) {
this.receiveLogin(next.message);
}
else if (next.cmd === protocol_1.Rec.ScheduleStatus) {
this.receiveSchedule(next.message);
}
else if (next.cmd === protocol_1.Rec.NodeMgtInfo) {
this.receiveNodeMgtInfo(next.message);
}
else if (next.cmd === protocol_1.Rec.Register) {
this.receiveRegister(next.message);
}
else {
this.info("not handled: " + next.message);
}
return true;
}
}
///////////////////
// Login message //
///////////////////
receiveLogin(message) {
this.isLoggedIn = (message[2] === 1);
if (this.resolveLogin) {
this.resolveLogin(this.isLoggedIn);
this.resolveLogin = null;
// if logged in, ask protocol version
if (this.isLoggedIn) {
this.send(protocol_1.Protocol.buildRequestNodeMgt(protocol_1.reqNodeAttributes.nodeProtocol));
}
}
else {
this.err("unexpected ConnectStatus ?");
}
}
///////////////////
// Info messages //
///////////////////
receiveNodeMgtInfo(message) {
if (message[1] === protocol_1.reqNodeAttributes.isMaster) {
this.log("NodeMgtInfo - master " + this.getName() + " is set to master: " + message[2]);
}
else if (message[1] === protocol_1.reqNodeAttributes.nodeInfo) {
// should be the same as the one from the DBInfo (64)
this.log("NodeMgtInfo - node info for " + this.getName() + ": " + message);
}
else if (message[1] === protocol_1.reqNodeAttributes.masterSupported) {
this.log("NodeMgtInfo - master " + this.getName() + " can be master: " + message[2]);
}
else if (message[1] === protocol_1.reqNodeAttributes.nodeVersion) {
this.log("NodeMgtInfo - version " + this.getName() + ", version: " + message[2] + "." + message[3]);
this.version = message[2] * 100 + message[3];
console.log("*** version -> " + message + " -> " + this.version + " ***");
}
else if (message[1] === protocol_1.reqNodeAttributes.nodeProtocol) {
this.log("NodeMgtInfo - protocol " + this.getName() + ", protocol: " + message[2] + "." + message[3]);
this.protocol = message[2] * 100 + message[3];
console.log("*** protocol -> " + message + " -> " + this.protocol + " ***");
}
else {
this.err("dropped NodeMgtInfo info message = " + message[1] + ", message: " + message);
}
}
receiveRegister(message) {
const register = protocol_1.Protocol.makeWord(message, 2);
const value = protocol_1.Protocol.makeSigned(message, 4);
if ((register >= 0) && (register < 1024)) {
this.registers[register] = value;
this.log("receiveRegister(" + register + ") = " + value);
}
else {
this.err("Received register out of bound: " + register);
}
}
receiveHeartbeat(message) {
this.lastHeartbeat = new Date().getTime();
//console.log("*HB* Received HB");
this.log("Received heartbeat at " + (new Date()));
}
receiveInfo(next) {
if (next.message[1] === protocol_1.Rec.DBInfo) {
this.receiveDBInfo(next.message);
}
else if (next.message[1] === protocol_1.Rec.NodeInfo) {
this.receiveNodeInfo(next.message);
}
else if (next.message[1] === protocol_1.Rec.UnitInfo) {
this.receiveUnitInfo(next.message);
}
else {
this.err("What is this? info type = " + next.message[1] + ", message: " + next.message);
}
this.system.triggerRebuild();
}
receiveSchedule(message) {
this.schedule = message[2];
this.info("received week schedule = " + this.schedule);
}
receiveDateTime(message) {
// 71,0,9,37,3,3,4,3,21,20 -> 09:37:03 Wednesday(3) 4 march 2120
this.date = new Date((message[8] - 1) * 100 + message[9], message[7] - 1, message[6], message[2], message[3], message[4]);
//this.info("Received date/time: " + this.date);
}
receiveDBInfo(message) {
const dbInfo = protocol_1.Protocol.makeDBInfo(message);
this.nrNodes = dbInfo.nrNodes;
for (let nodeInx = 0; nodeInx < this.nrNodes; nodeInx++) {
this.fetchNode(nodeInx);
}
}
receiveNodeInfo(message) {
const nodeInfo = protocol_1.Protocol.makeNodeInfo(message);
let node = this.findNode(nodeInfo.logicalAddress);
if (!node) {
node = new protocol_1.Node(this, nodeInfo);
this.nodes.push(node);
}
else {
types_1.Sanitizers.nodeInfo(nodeInfo, node);
}
this.log("> received node info: " + nodeInfo.name + " (" + nodeInfo.logicalAddress + ")");
this.system.setActiveState(node);
this.config.nodenames[node.logicalAddress] = node.name;
this.system.updateMasterConfig(this);
if (node.active && (node.nrUnits !== node.units.length)) {
this.fetchAllUnits(node);
}
else {
this.info("Skipping node: " + node.getDescription());
}
}
receiveUnitInfo(message) {
const unitInfo = protocol_1.Protocol.makeUnitInfo(message);
let unit = this.findUnit(unitInfo.logicalNodeAddress, unitInfo.logicalAddress);
this.info("> received unit info: " + unitInfo.name + " (" + unitInfo.logicalNodeAddress + "," + unitInfo.logicalAddress + ") for unit: " + (unit === null || unit === void 0 ? void 0 : unit.name));
if (!unit) {
// find if in config
const cunit = this.system.config.cunits.find(u => ((u.logicalNodeAddress == unitInfo.logicalNodeAddress) && (u.logicalAddress == unitInfo.logicalAddress)));
if (cunit)
unitInfo.extendedType = cunit.extendedType;
const node = this.findNode(unitInfo.logicalNodeAddress);
if (node) {
unit = new protocol_1.Unit(node, unitInfo, this.system.config.mood);
node.units.push(unit);
}
else {
this.err("Node not found: " + unitInfo.logicalNodeAddress);
}
}
else {
types_1.Sanitizers.unitInfo(unitInfo, unit);
}
this.system.setActiveState(unit);
}
//////////////////
// request info //
//////////////////
fetchAllUnits(node) {
return __awaiter(this, void 0, void 0, function* () {
for (let unitInx = 0; unitInx < node.nrUnits; unitInx++) {
yield this.fetchUnit(node, unitInx);
}
});
}
fetchDbInfo() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield this.send(protocol_1.Protocol.buildDBInfo());
yield this.send(protocol_1.Protocol.buildRequestSchedule());
}
catch (err) {
this.err("dbInfo call failed -> " + err);
}
});
}
fetchNode(nodeInx) {
return __awaiter(this, void 0, void 0, function* () {
const message = protocol_1.Protocol.buildNodeInfo(nodeInx);
try {
yield this.send(message);
}
catch (err) {
this.err("nodeInfo call failed -> " + err);
}
});
}
fetchUnit(node, unitInx) {
return __awaiter(this, void 0, void 0, function* () {
const message = protocol_1.Protocol.buildUnitInfo(node, unitInx);
try {
// unit with index "unitInx" in node "logicalAddress"
yield this.send(message);
}
catch (err) {
this.err("unitInfo call failed -> " + err);
}
});
}
getDatabase(readDB = false) {
return __awaiter(this, void 0, void 0, function* () {
this.nodes = [];
const hasNames = this.system.config.cunits.filter(u => this.same(u.masterAddress, u.masterPort)).some(u => u.name);
if (readDB || !hasNames) {
this.log("Fetching info from master DB for: " + this.getAddress());
yield this.fetchDbInfo();
// upon reception of the DB info,
// getNode info will be called,
// which in it's turn will trigger getUnitInfo through fetchAllUnits
}
else {
// loop over all nodes/units in the config with a matching ip address
// fill: this.nrNodes
// call: kind of receive-Node/Unit-Info
this.log("Building info from config for: " + this.getAddress());
this.system.config.cunits
.filter(u => this.same(u.masterAddress, u.masterPort))
.forEach(u => {
let node = this.findNode(u.logicalNodeAddress);
if (!node) {
let name = this.config.nodenames[u.logicalNodeAddress] ||
((u.logicalNodeAddress == 255) ? "Virtual Node" :
("Node-" + ((u.logicalNodeAddress < 16) ? '0' : '') + u.logicalNodeAddress.toString(16)));
node = new protocol_1.Node(this, { logicalAddress: u.logicalNodeAddress, name });
this.nodes.push(node);
this.system.setActiveState(node);
this.info("new node: " + node.getName());
}
let unit = this.findUnit(u.logicalNodeAddress, u.logicalAddress);
if (!unit) {
unit = new protocol_1.Unit(node, u);
node.units.push(unit);
this.info("new unit: " + unit.getName() + " -> " + u.logicalAddress);
}
this.system.setActiveState(unit);
});
}
});
}
allNodes(doToNode) {
this.nodes.forEach(node => {
doToNode(node);
});
}
allUnits(doToUnit) {
this.nodes.forEach(node => {
node.units.forEach(unit => {
doToUnit(unit);
});
});
}
displayDatabase(onlyNodes = false) {
this.info("Showing " + this.nodes.length + " nodes");
this.nodes.forEach((node, nodeInx) => {
if (onlyNodes)
this.log("===================================================================================");
this.log(nodeInx + ". " + node.name +
", type = " + node.typeName() +
", nrUnits = " + node.nrUnits +
", logical address = " + node.logicalAddress);
if (onlyNodes) {
this.log("-----------------------------------------------------------------------------------");
node.units.forEach((unit, unitInx) => {
this.log("> " + unitInx + ". '" + unit.name + "' => '" + unit.getName() +
"', type = " + unit.typeName() +
", logical address: " + unit.logicalAddress +
", value: " + unit.value +
(unit.status ? (", status = " + unit.status) : ""));
});
}
});
}
findUnit(logicalNodeAddress, logicalAddress) {
const node = this.findNode(logicalNodeAddress);
if (node)
return node.units.find((u) => u.logicalAddress === logicalAddress);
else
return null;
}
findNode(logicalAddress) {
return this.nodes.find((n) => n && (n.logicalAddress === logicalAddress));
}
getNodeAndUnit(node, unit) {
// allow for index numbers or real nodes to be passed
if (typeof node === "number") {
if (node >= this.nodes.length) {
this.err("getNodeAndUnit -> node nr " + node + " out of bounds");
node = null;
}
else {
node = this.nodes[node];
}
}
if (!node) {
this.err("getNodeAndUnit -> node not found ");
return null;
}
if (typeof unit === "number") {
if (unit >= node.units.length) {
this.err("getNodeAndUnit -> unit nr " + unit + " out of bounds");
unit = null;
}
else {
unit = node.units[unit];
}
}
if (!unit) {
this.err("getNodeAndUnit -> unit not found");
return null;
}
return { node, unit };
}
/* ****************************************************************************** */
/* Status requests */
/* Database (all known nodes) */
/* Node (all known units in this node) */
/* Unit (only dimmer, switch, input, temperature, motor and mood implemented) */
/* ****************************************************************************** */
receiveStatus(next) {
// called when an incoming message was received and classified as a status message
// find node
const nodeLogical = next.message[2];
const node = this.nodes.find(node => node && (node.logicalAddress == nodeLogical));
if (!node) {
this.info("status message " + next.cmd + " for unknown node = " + nodeLogical);
return;
}
// find unit
const unitLogical = next.message[3];
const unit = node.units.find(unit => unit && (unit.logicalAddress == unitLogical));
if (!unit) {
this.info("status message " + next.cmd + " for unknown unit = " + unitLogical +
" in node = " + nodeLogical);
return;
}
// Parse the status into the unit and propagate
protocol_1.Protocol.receiveStatus(next, unit);
}
requestStatus() {
return __awaiter(this, void 0, void 0, function* () {
for (let nodeInx = 0; nodeInx < this.nodes.length; nodeInx++) {
const node = this.nodes[nodeInx];
if (node.active) {
for (let unitInx = 0; unitInx < node.units.length; unitInx++) {
yield this.requestUnitStatus(node.units[unitInx]);
}
}
}
});
}
requestNodeStatus(node) {
return __awaiter(this, void 0, void 0, function* () {
for (let unitInx = 0; unitInx < node.units.length; unitInx++) {
if (node.units[unitInx].active)
yield this.requestUnitStatus(node.units[unitInx]);
}
});
}
requestUnitStatus(unit) {
return __awaiter(this, void 0, void 0, function* () {
const message = protocol_1.Protocol.buildRequestUnitStatus(unit.node, unit);
let res = yield this.send(message);
// results will be set by the data event listener
this.info("get value of " + unit.node.getName() + "-" + unit.getName());
});
}
requestRegisterValue(register) {
return __awaiter(this, void 0, void 0, function* () {
if (this.protocol >= 209) {
yield this.send(protocol_1.Protocol.buildRegister(register));
this.info("request register: " + register);
}
else {
this.err("FC_REGISTERMAP not available before protocol v2.09");
}
});
}
/////////////////////
// Settings values //
/////////////////////
setUnitStatus(unit, value) {
return __awaiter(this, void 0, void 0, function* () {
const params = protocol_1.Protocol.buildSetCmd(unit.node, unit, value);
if (params.cmd) {
yield this.send(params.message);
}
});
}
setRegisterValue(register, value) {
return __awaiter(this, void 0, void 0, function* () {
if (this.protocol >= 209) {
yield this.send(protocol_1.Protocol.buildRegister(register, value));
this.info("set register: " + register + ", to: " + value);
}
else {
this.err("FC_REGISTERMAP not available before protocol v2.09");
}
});
}
setSensorValue(unit, value) {
return __awaiter(this, void 0, void 0, function* () {
this.info("SetSensorValue of " + unit.node.logicalAddress + "/" + unit.logicalAddress + " to " + value);
yield this.send(protocol_1.Protocol.buildSetPreset(unit.node, unit, protocol_1.TempPreset.sun, Math.trunc(value / 100 / 100 / 100) % 100));
yield this.send(protocol_1.Protocol.buildSetPreset(unit.node, unit, protocol_1.TempPreset.hsun, Math.trunc(value / 100 / 100) % 100));
yield this.send(protocol_1.Protocol.buildSetPreset(unit.node, unit, protocol_1.TempPreset.moon, Math.trunc(value / 100) % 100));
yield this.send(protocol_1.Protocol.buildSetPreset(unit.node, unit, protocol_1.TempPreset.hmoon, Math.trunc(value % 100)));
});
}
setSensorStatus(unit, value) {
return __awaiter(this, void 0, void 0, function* () {
yield this.send(protocol_1.Protocol.buildSetSensor(unit.node, unit, value));
});
}
setPreset(unit, preset, temp) {
return __awaiter(this, void 0, void 0, function* () {
yield this.send(protocol_1.Protocol.buildSetPreset(unit.node, unit, preset, temp));
this.info("set temp preset: " + preset + " of " + unit.node.getName() + "-" + unit.getName() + " to temp " + temp);
});
}
selectPreset(unit, preset) {
return __awaiter(this, void 0, void 0, function* () {
yield this.send(protocol_1.Protocol.buildSelectPreset(unit.node, unit, preset));
this.info("set temp preset of " + unit.node.getName() + "-" + unit.getName() + " to: " + preset);
});
}
setSchedule() {
return __awaiter(this, void 0, void 0, function* () {
yield this.send(protocol_1.Protocol.buildSendSchedule(this.schedule));
this.info("set schedule to week nr: " + this.schedule);
});
}
setTempOnOff(unit, on) {
return __awaiter(this, void 0, void 0, function* () {
yield this.send(protocol_1.Protocol.buildSensorOnOff(unit.node, unit, on));
this.info("turn temp sensor of " + unit.node.getName() + "-" + unit.getName() + ": " + (on ? "on" : "off"));
});
}
doIncDecPreset(unit, inc) {
return __awaiter(this, void 0, void 0, function* () {
yield this.send(protocol_1.Protocol.buildIncDecPreset(unit.node, unit, inc));
this.info("set temp preset of " + unit.node.getName() + "-" + unit.getName() + ": " + (inc ? "up" : "down"));
});
}
}
exports.Master = Master;
//# sourceMappingURL=master.js.map