status handling

This commit is contained in:
2018-03-27 21:23:24 +02:00
parent ce78afaa55
commit 0d14933863
2 changed files with 37 additions and 14 deletions

25
dist/RelayBox.js vendored
View File

@ -10,6 +10,8 @@ class RelayBoxThing extends AItem_1.AItem {
this.deviceCommandTopic = deviceCommandTopic;
this.deviceStatusTopic = deviceStatusTopic;
this.stateTopicPre = `${this.topicFirstPart}/state`;
this.feedbackTopicPre = `${this.topicFirstPart}/feedback`;
this.conflictTopicPre = `${this.topicFirstPart}/conflict`;
this.subscribeTopics = [
`${this.deviceStatusTopic}`,
`${this.stateTopicPre}/#`
@ -19,15 +21,24 @@ class RelayBoxThing extends AItem_1.AItem {
// logger.info(`RT: ${topic}, ${payload}`)
if (topic == this.deviceStatusTopic) {
logger.info(`RT: status received`);
let status = JSON.parse(payload);
let statusParsed = JSON.stringify(status);
this.status = JSON.parse(payload);
let statusParsed = JSON.stringify(this.status);
logger.info(`RT: status parsed: ${statusParsed}`);
logger.info(`RT: device: ${status.metadata.device}`);
logger.info(`RT: uptime: ${status.data.uptime}`);
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++) {
logger.info(`RT: state: ${status.data.switchstatus[i].state}`);
logger.info(`RT: feedb: ${status.data.switchstatus[i].feedbackState}`);
logger.info(`RT: confl: ${status.data.switchstatus[i].stateConflict}`);
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');
}
}
}
else {