status handling

This commit is contained in:
2018-03-27 21:27:59 +02:00
parent 0d14933863
commit 166f958cac
2 changed files with 40 additions and 28 deletions

35
dist/RelayBox.js vendored
View File

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

View File

@ -12,6 +12,8 @@ export class RelayBoxThing extends AItem {
private readonly feedbackTopicPre: string private readonly feedbackTopicPre: string
private readonly conflictTopicPre: string private readonly conflictTopicPre: string
private status : any private status : any
private switchStates : string
private oldSwitchStates : string
constructor(floor: string, room: string, item: string, deviceCommandTopic: string, constructor(floor: string, room: string, item: string, deviceCommandTopic: string,
deviceStatusTopic: string, itemNames: string[]) { deviceStatusTopic: string, itemNames: string[]) {
@ -26,6 +28,7 @@ export class RelayBoxThing extends AItem {
`${this.deviceStatusTopic}`, `${this.deviceStatusTopic}`,
`${this.stateTopicPre}/#` `${this.stateTopicPre}/#`
] ]
this.oldSwitchStates = ''
} }
processMessage(topic: string, payload: string) { processMessage(topic: string, payload: string) {
@ -34,19 +37,23 @@ export class RelayBoxThing extends AItem {
logger.info(`RT: status received`) logger.info(`RT: status received`)
this.status = JSON.parse(payload) this.status = JSON.parse(payload)
let statusParsed = JSON.stringify(this.status) let statusParsed = JSON.stringify(this.status)
logger.info(`RT: status parsed: ${statusParsed}`) this.switchStates = JSON.stringify(this.status.data.switchStates)
logger.info(`RT: device: ${this.status.metadata.device}`) if (this.switchStates != this.oldSwitchStates) {
logger.info(`RT: uptime: ${this.status.data.uptime}`) this.oldSwitchStates = this.switchStates
for (let i : number = 0; i < this.itemNames.length; i ++) { logger.info(`RT: status parsed: ${statusParsed}`)
if (this.status.data.switchStates[i].feedbackState == '0') { logger.info(`RT: device: ${this.status.metadata.device}`)
mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'ON') logger.info(`RT: uptime: ${this.status.data.uptime}`)
} else { for (let i : number = 0; i < this.itemNames.length; i ++) {
mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'OFF') if (this.status.data.switchStates[i].feedbackState == '0') {
} mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'ON')
if (this.status.data.switchStates[i].stateConflict == '0') { } else {
mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CLEAR') mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'OFF')
} else { }
mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CONFLICT') if (this.status.data.switchStates[i].stateConflict == '0') {
mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CLEAR')
} else {
mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CONFLICT')
}
} }
} }
} else { } else {