TwoLedSignal stuff
This commit is contained in:
78
dist/TwoLedSignal.js
vendored
Normal file
78
dist/TwoLedSignal.js
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const AItem_1 = require("./AItem");
|
||||
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||
const logger = require("./log");
|
||||
var SignalState;
|
||||
(function (SignalState) {
|
||||
SignalState[SignalState["SIGNAL_RED"] = 0] = "SIGNAL_RED";
|
||||
SignalState[SignalState["SIGNAL_GREEN"] = 1] = "SIGNAL_GREEN";
|
||||
SignalState[SignalState["SIGNAL_UNKNOWN"] = 2] = "SIGNAL_UNKNOWN";
|
||||
})(SignalState || (SignalState = {}));
|
||||
class SignalItem {
|
||||
constructor(item, redToken, greenToken) {
|
||||
this.item = item;
|
||||
this.signalState = SignalState.SIGNAL_UNKNOWN;
|
||||
this.redToken = redToken;
|
||||
this.greenToken = greenToken;
|
||||
}
|
||||
getSignalState() {
|
||||
return this.signalState;
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
if (topic == this.item.getStateFeedbackTopic()) {
|
||||
logger.info(`${topic}, ${payload}`);
|
||||
if (payload == this.greenToken) {
|
||||
this.signalState = SignalState.SIGNAL_GREEN;
|
||||
}
|
||||
else if (payload == this.redToken) {
|
||||
this.signalState = SignalState.SIGNAL_RED;
|
||||
}
|
||||
else {
|
||||
this.signalState = SignalState.SIGNAL_UNKNOWN;
|
||||
}
|
||||
// logger.info(`DBG: SignalItem: ${topic}, ${payload}, ${this.signalState}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
class TwoLedSignal extends AItem_1.AItem {
|
||||
constructor(floor, room, item, label, led1Items, led1GreenToken, led1RedToken, led2Items, led2GreenToken, led2RedToken) {
|
||||
super(floor, room, item, label);
|
||||
this.led1Items = [];
|
||||
this.led2Items = [];
|
||||
this.subscribeTopics = [];
|
||||
led1Items.forEach((item) => {
|
||||
this.led1Items.push(new SignalItem(item, led1RedToken, led1GreenToken));
|
||||
this.subscribeTopics.push(item.getStateFeedbackTopic());
|
||||
});
|
||||
led2Items.forEach((item) => {
|
||||
this.led2Items.push(new SignalItem(item, led2RedToken, led2GreenToken));
|
||||
this.subscribeTopics.push(item.getStateFeedbackTopic());
|
||||
});
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
let reds = 0;
|
||||
const RED_VALUES = [SignalState.SIGNAL_RED, SignalState.SIGNAL_UNKNOWN];
|
||||
this.led1Items.forEach((item) => {
|
||||
item.processMessage(topic, payload);
|
||||
if (RED_VALUES.indexOf(item.getSignalState()) != -1) {
|
||||
reds++;
|
||||
}
|
||||
// logger.info(`DBG: TwoLedSignal ${item.getSignalState()}, ${reds}`)
|
||||
});
|
||||
let msg = (reds > 0) ? "RED" : "GREEN";
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.topicFirstPart}/led1`, msg);
|
||||
reds = 0;
|
||||
this.led2Items.forEach((item) => {
|
||||
item.processMessage(topic, payload);
|
||||
if (RED_VALUES.indexOf(item.getSignalState()) != -1) {
|
||||
reds++;
|
||||
}
|
||||
// logger.info(`DBG: TwoLedSignal ${item.getSignalState()}, ${reds}`)
|
||||
});
|
||||
msg = (reds > 0) ? "RED" : "GREEN";
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.topicFirstPart}/led2`, msg);
|
||||
}
|
||||
}
|
||||
exports.TwoLedSignal = TwoLedSignal;
|
||||
//# sourceMappingURL=TwoLedSignal.js.map
|
Reference in New Issue
Block a user