status handling
This commit is contained in:
25
dist/RelayBox.js
vendored
25
dist/RelayBox.js
vendored
@ -10,6 +10,8 @@ class RelayBoxThing extends AItem_1.AItem {
|
|||||||
this.deviceCommandTopic = deviceCommandTopic;
|
this.deviceCommandTopic = deviceCommandTopic;
|
||||||
this.deviceStatusTopic = deviceStatusTopic;
|
this.deviceStatusTopic = deviceStatusTopic;
|
||||||
this.stateTopicPre = `${this.topicFirstPart}/state`;
|
this.stateTopicPre = `${this.topicFirstPart}/state`;
|
||||||
|
this.feedbackTopicPre = `${this.topicFirstPart}/feedback`;
|
||||||
|
this.conflictTopicPre = `${this.topicFirstPart}/conflict`;
|
||||||
this.subscribeTopics = [
|
this.subscribeTopics = [
|
||||||
`${this.deviceStatusTopic}`,
|
`${this.deviceStatusTopic}`,
|
||||||
`${this.stateTopicPre}/#`
|
`${this.stateTopicPre}/#`
|
||||||
@ -19,15 +21,24 @@ class RelayBoxThing extends AItem_1.AItem {
|
|||||||
// logger.info(`RT: ${topic}, ${payload}`)
|
// logger.info(`RT: ${topic}, ${payload}`)
|
||||||
if (topic == this.deviceStatusTopic) {
|
if (topic == this.deviceStatusTopic) {
|
||||||
logger.info(`RT: status received`);
|
logger.info(`RT: status received`);
|
||||||
let status = JSON.parse(payload);
|
this.status = JSON.parse(payload);
|
||||||
let statusParsed = JSON.stringify(status);
|
let statusParsed = JSON.stringify(this.status);
|
||||||
logger.info(`RT: status parsed: ${statusParsed}`);
|
logger.info(`RT: status parsed: ${statusParsed}`);
|
||||||
logger.info(`RT: device: ${status.metadata.device}`);
|
logger.info(`RT: device: ${this.status.metadata.device}`);
|
||||||
logger.info(`RT: uptime: ${status.data.uptime}`);
|
logger.info(`RT: uptime: ${this.status.data.uptime}`);
|
||||||
for (let i = 0; i < this.itemNames.length; i++) {
|
for (let i = 0; i < this.itemNames.length; i++) {
|
||||||
logger.info(`RT: state: ${status.data.switchstatus[i].state}`);
|
if (this.status.data.switchStates[i].feedbackState == '0') {
|
||||||
logger.info(`RT: feedb: ${status.data.switchstatus[i].feedbackState}`);
|
MqttDispatcher_1.mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'ON');
|
||||||
logger.info(`RT: confl: ${status.data.switchstatus[i].stateConflict}`);
|
}
|
||||||
|
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 {
|
else {
|
||||||
|
@ -9,6 +9,9 @@ export class RelayBoxThing extends AItem {
|
|||||||
private readonly deviceCommandTopic: string
|
private readonly deviceCommandTopic: string
|
||||||
private readonly deviceStatusTopic: string
|
private readonly deviceStatusTopic: string
|
||||||
private readonly stateTopicPre: 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,
|
constructor(floor: string, room: string, item: string, deviceCommandTopic: string,
|
||||||
deviceStatusTopic: string, itemNames: string[]) {
|
deviceStatusTopic: string, itemNames: string[]) {
|
||||||
@ -17,6 +20,8 @@ export class RelayBoxThing extends AItem {
|
|||||||
this.deviceCommandTopic = deviceCommandTopic
|
this.deviceCommandTopic = deviceCommandTopic
|
||||||
this.deviceStatusTopic = deviceStatusTopic
|
this.deviceStatusTopic = deviceStatusTopic
|
||||||
this.stateTopicPre = `${this.topicFirstPart}/state`
|
this.stateTopicPre = `${this.topicFirstPart}/state`
|
||||||
|
this.feedbackTopicPre = `${this.topicFirstPart}/feedback`
|
||||||
|
this.conflictTopicPre = `${this.topicFirstPart}/conflict`
|
||||||
this.subscribeTopics = [
|
this.subscribeTopics = [
|
||||||
`${this.deviceStatusTopic}`,
|
`${this.deviceStatusTopic}`,
|
||||||
`${this.stateTopicPre}/#`
|
`${this.stateTopicPre}/#`
|
||||||
@ -27,15 +32,22 @@ export class RelayBoxThing extends AItem {
|
|||||||
// logger.info(`RT: ${topic}, ${payload}`)
|
// logger.info(`RT: ${topic}, ${payload}`)
|
||||||
if (topic == this.deviceStatusTopic) {
|
if (topic == this.deviceStatusTopic) {
|
||||||
logger.info(`RT: status received`)
|
logger.info(`RT: status received`)
|
||||||
let status : any = JSON.parse(payload)
|
this.status = JSON.parse(payload)
|
||||||
let statusParsed: string = JSON.stringify(status)
|
let statusParsed = JSON.stringify(this.status)
|
||||||
logger.info(`RT: status parsed: ${statusParsed}`)
|
logger.info(`RT: status parsed: ${statusParsed}`)
|
||||||
logger.info(`RT: device: ${status.metadata.device}`)
|
logger.info(`RT: device: ${this.status.metadata.device}`)
|
||||||
logger.info(`RT: uptime: ${status.data.uptime}`)
|
logger.info(`RT: uptime: ${this.status.data.uptime}`)
|
||||||
for (let i : number = 0; i < this.itemNames.length; i ++) {
|
for (let i : number = 0; i < this.itemNames.length; i ++) {
|
||||||
logger.info(`RT: state: ${status.data.switchStates[i].state}`)
|
if (this.status.data.switchStates[i].feedbackState == '0') {
|
||||||
logger.info(`RT: feedb: ${status.data.switchStates[i].feedbackState}`)
|
mqttHandler.send(`${this.feedbackTopicPre}/${i}`, 'ON')
|
||||||
logger.info(`RT: confl: ${status.data.switchStates[i].stateConflict}`)
|
} 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 {
|
} else {
|
||||||
logger.info(`RT: ${topic}, ${payload}`)
|
logger.info(`RT: ${topic}, ${payload}`)
|
||||||
|
Reference in New Issue
Block a user