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

View File

@ -9,6 +9,9 @@ export class RelayBoxThing extends AItem {
private readonly deviceCommandTopic: string
private readonly deviceStatusTopic: string
private readonly stateTopicPre: string
private readonly feedbackTopicPre: string
private readonly conflictTopicPre: string
private status : any
constructor(floor: string, room: string, item: string, deviceCommandTopic: string,
deviceStatusTopic: string, itemNames: string[]) {
@ -17,6 +20,8 @@ export class RelayBoxThing extends 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}/#`
@ -27,15 +32,22 @@ export class RelayBoxThing extends AItem {
// logger.info(`RT: ${topic}, ${payload}`)
if (topic == this.deviceStatusTopic) {
logger.info(`RT: status received`)
let status : any = JSON.parse(payload)
let statusParsed: string = 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 : number = 0; i < this.itemNames.length; i ++) {
logger.info(`RT: state: ${status.data.switchStates[i].state}`)
logger.info(`RT: feedb: ${status.data.switchStates[i].feedbackState}`)
logger.info(`RT: confl: ${status.data.switchStates[i].stateConflict}`)
if (this.status.data.switchStates[i].feedbackState == '0') {
mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'ON')
} else {
mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'OFF')
}
if (this.status.data.switchStates[i].stateConflict == '0') {
mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CLEAR')
} else {
mqttHandler.send(`${this.conflictTopicPre}/${i}`, 'CONFLICT')
}
}
} else {
logger.info(`RT: ${topic}, ${payload}`)