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

5
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,6 +24,9 @@ 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);
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: status parsed: ${statusParsed}`);
logger.info(`RT: device: ${this.status.metadata.device}`); logger.info(`RT: device: ${this.status.metadata.device}`);
logger.info(`RT: uptime: ${this.status.data.uptime}`); logger.info(`RT: uptime: ${this.status.data.uptime}`);
@ -41,6 +45,7 @@ class RelayBoxThing extends AItem_1.AItem {
} }
} }
} }
}
else { else {
logger.info(`RT: ${topic}, ${payload}`); logger.info(`RT: ${topic}, ${payload}`);
let thingRelatedPart = topic.substring(this.stateTopicPre.length + 1); let thingRelatedPart = topic.substring(this.stateTopicPre.length + 1);

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,6 +37,9 @@ 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)
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: status parsed: ${statusParsed}`)
logger.info(`RT: device: ${this.status.metadata.device}`) logger.info(`RT: device: ${this.status.metadata.device}`)
logger.info(`RT: uptime: ${this.status.data.uptime}`) logger.info(`RT: uptime: ${this.status.data.uptime}`)
@ -49,6 +55,7 @@ export class RelayBoxThing extends AItem {
mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CONFLICT') mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CONFLICT')
} }
} }
}
} else { } else {
logger.info(`RT: ${topic}, ${payload}`) logger.info(`RT: ${topic}, ${payload}`)
let thingRelatedPart = topic.substring(this.stateTopicPre.length+1) let thingRelatedPart = topic.substring(this.stateTopicPre.length+1)