status handling
This commit is contained in:
35
dist/RelayBox.js
vendored
35
dist/RelayBox.js
vendored
@ -16,6 +16,7 @@ class RelayBoxThing extends AItem_1.AItem {
|
||||
`${this.deviceStatusTopic}`,
|
||||
`${this.stateTopicPre}/#`
|
||||
];
|
||||
this.oldSwitchStates = '';
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
// logger.info(`RT: ${topic}, ${payload}`)
|
||||
@ -23,21 +24,25 @@ class RelayBoxThing extends AItem_1.AItem {
|
||||
logger.info(`RT: status received`);
|
||||
this.status = JSON.parse(payload);
|
||||
let statusParsed = JSON.stringify(this.status);
|
||||
logger.info(`RT: status parsed: ${statusParsed}`);
|
||||
logger.info(`RT: device: ${this.status.metadata.device}`);
|
||||
logger.info(`RT: uptime: ${this.status.data.uptime}`);
|
||||
for (let i = 0; i < this.itemNames.length; i++) {
|
||||
if (this.status.data.switchStates[i].feedbackState == '0') {
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'ON');
|
||||
}
|
||||
else {
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'OFF');
|
||||
}
|
||||
if (this.status.data.switchStates[i].stateConflict == '0') {
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CLEAR');
|
||||
}
|
||||
else {
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CONFLICT');
|
||||
this.switchStates = JSON.stringify(this.status.data.switchStates);
|
||||
if (this.switchStates != this.oldSwitchStates) {
|
||||
this.oldSwitchStates = this.switchStates;
|
||||
logger.info(`RT: status parsed: ${statusParsed}`);
|
||||
logger.info(`RT: device: ${this.status.metadata.device}`);
|
||||
logger.info(`RT: uptime: ${this.status.data.uptime}`);
|
||||
for (let i = 0; i < this.itemNames.length; i++) {
|
||||
if (this.status.data.switchStates[i].feedbackState == '0') {
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'ON');
|
||||
}
|
||||
else {
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'OFF');
|
||||
}
|
||||
if (this.status.data.switchStates[i].stateConflict == '0') {
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CLEAR');
|
||||
}
|
||||
else {
|
||||
MqttDispatcher_1.mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CONFLICT');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user