3 Commits

Author SHA1 Message Date
f4933cb483 fix 2018-09-23 16:54:40 +02:00
80550321d2 remove openhab and homekit export calls 2018-09-22 18:42:27 +02:00
f98b1c2f39 remove state for switch actors 2018-09-21 13:38:11 +02:00
9 changed files with 87 additions and 101 deletions

View File

@ -31,7 +31,6 @@ class HomematicSwitchItem extends AHomegearItem_1.AHomegearItem {
this.deviceFeedbackTopic this.deviceFeedbackTopic
]; ];
this.state = 'OFF'; this.state = 'OFF';
this.oldState = undefined;
this.type = type; this.type = type;
} }
exportItem() { exportItem() {
@ -42,14 +41,11 @@ class HomematicSwitchItem extends AHomegearItem_1.AHomegearItem {
case this.stateTopic: case this.stateTopic:
this.state = payload; this.state = payload;
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state); MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
if (this.state != this.oldState) { if (this.state == 'ON') {
if (this.state == 'ON') { MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'true');
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'true'); }
} else {
else { MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'false');
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'false');
}
this.oldState = this.state;
} }
break; break;
case this.deviceFeedbackTopic: case this.deviceFeedbackTopic:
@ -59,7 +55,6 @@ class HomematicSwitchItem extends AHomegearItem_1.AHomegearItem {
else { else {
this.state = 'OFF'; this.state = 'OFF';
} }
this.oldState = this.state;
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state); MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
break; break;
} }

View File

@ -26,7 +26,6 @@ class M433SwitchItem extends AItem_1.AItem {
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`; this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
this.actionTopic = 'IoT/Mqtt433Gateway/Message'; this.actionTopic = 'IoT/Mqtt433Gateway/Message';
this.state = 'OFF'; this.state = 'OFF';
this.oldState = undefined;
this.onCode = onCode; this.onCode = onCode;
this.offCode = offCode; this.offCode = offCode;
this.type = type; this.type = type;
@ -37,14 +36,11 @@ class M433SwitchItem extends AItem_1.AItem {
processMessage(topic, payload) { processMessage(topic, payload) {
this.state = payload; this.state = payload;
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state); MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
if (this.state != this.oldState) { if (this.state == 'ON') {
if (this.state == 'ON') { MqttDispatcher_1.mqttHandler.send(this.actionTopic, this.onCode);
MqttDispatcher_1.mqttHandler.send(this.actionTopic, this.onCode); }
} else {
else { MqttDispatcher_1.mqttHandler.send(this.actionTopic, this.offCode);
MqttDispatcher_1.mqttHandler.send(this.actionTopic, this.offCode);
}
this.oldState = this.state;
} }
} }
} }

View File

@ -40,10 +40,10 @@ class SimpleTopicSwitchItem extends AItem_1.AItem {
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state); MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
if (this.state != this.oldState) { if (this.state != this.oldState) {
if (this.state == 'ON') { if (this.state == 'ON') {
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'true'); MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'ON');
} }
else { else {
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'false'); MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'OFF');
} }
this.oldState = this.state; this.oldState = this.state;
} }

61
dist/main.js vendored
View File

@ -477,37 +477,36 @@ let watchdogTimer = setInterval(() => {
watchdogCounter += 1; watchdogCounter += 1;
MqttDispatcher_1.mqttHandler.send(config.dict.watchdogTopic, `${config.dict.watchdogMessage} ${watchdogCounter}`); MqttDispatcher_1.mqttHandler.send(config.dict.watchdogTopic, `${config.dict.watchdogMessage} ${watchdogCounter}`);
}, config.dict.watchdogInterval); }, config.dict.watchdogInterval);
// ---------------------------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------------------------
// Homekit export // // Homekit export
let homekitObject = {}; // let homekitObject : { [key:string]:{} } = {}
let openhabList = []; // let openhabList : string[] = []
// logger.info("allLabeledItems") // // logger.info("allLabeledItems")
// logger.info(JSON.stringify(allLabeledItems)) // // logger.info(JSON.stringify(allLabeledItems))
allLabeledItems.forEach((item) => { // allLabeledItems.forEach((item: AItem) => {
let exportData = item.exportItem(); // let exportData : ExportType|null = item.exportItem()
if (exportData != null) { // if (exportData != null) {
if ('id' in exportData['homekit']) { // if ('id' in exportData['homekit']) {
homekitObject[exportData['homekit']['id']] = exportData['homekit']['object']; // homekitObject[exportData['homekit']['id']] = exportData['homekit']['object']
} // }
if (exportData['openhab'] instanceof Array) { // if (exportData['openhab'] instanceof Array) {
let da = exportData['openhab']; // let da : string[] = exportData['openhab'] as string[]
da.forEach((o) => openhabList.push(o)); // da.forEach((o: string) => openhabList.push(o))
} // } else {
else { // let da : string = exportData['openhab'] as string
let da = exportData['openhab']; // openhabList.push(da)
openhabList.push(da); // }
} // // logger.info("openHabList")
// logger.info("openHabList") // // logger.info(JSON.stringify(openhabList))
// logger.info(JSON.stringify(openhabList)) // }
} // })
}); // let heatingMainSwitchExport : ExportType|null = MaxThermostat.exportHeatingMainSwitchItem()
let heatingMainSwitchExport = MaxThermostat_1.MaxThermostat.exportHeatingMainSwitchItem(); // if (heatingMainSwitchExport != null) {
if (heatingMainSwitchExport != null) { // let da : string = heatingMainSwitchExport['openhab'] as string
let da = heatingMainSwitchExport['openhab']; // openhabList.push(da)
openhabList.push(da); // }
} // fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4))
fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4)); // fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n'))
fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n'));
let roomSwitches = {}; let roomSwitches = {};
allLights.forEach((item) => { allLights.forEach((item) => {
let switchItem = { 'label': item.getLabel(), 'actionTopic': item.getStateTopic(), 'feedbackTopic': item.getStateFeedbackTopic() }; let switchItem = { 'label': item.getLabel(), 'actionTopic': item.getStateTopic(), 'feedbackTopic': item.getStateFeedbackTopic() };

View File

@ -48,6 +48,11 @@
"actionTopic": "dispatcher_ng/items/Gnd/Esszimmer/CupboardLight/state", "actionTopic": "dispatcher_ng/items/Gnd/Esszimmer/CupboardLight/state",
"feedbackTopic": "dispatcher_ng/items/Gnd/Esszimmer/CupboardLight/state/feedback" "feedbackTopic": "dispatcher_ng/items/Gnd/Esszimmer/CupboardLight/state/feedback"
}, },
{
"label": "Regallicht",
"actionTopic": "dispatcher_ng/items/Gnd/Esszimmer/ShelfLight/state",
"feedbackTopic": "dispatcher_ng/items/Gnd/Esszimmer/ShelfLight/state/feedback"
},
{ {
"label": "Nähkästchen", "label": "Nähkästchen",
"actionTopic": "dispatcher_ng/items/Gnd/Esszimmer/NaehkaestchenLight/state", "actionTopic": "dispatcher_ng/items/Gnd/Esszimmer/NaehkaestchenLight/state",

View File

@ -46,7 +46,6 @@ export class HomematicSwitchItem extends AHomegearItem implements HasStateAndFee
this.deviceFeedbackTopic this.deviceFeedbackTopic
] ]
this.state = 'OFF' this.state = 'OFF'
this.oldState = undefined
this.type = type this.type = type
} }
@ -59,13 +58,10 @@ export class HomematicSwitchItem extends AHomegearItem implements HasStateAndFee
case this.stateTopic: case this.stateTopic:
this.state = payload this.state = payload
mqttHandler.send(this.stateFeedbackTopic, this.state) mqttHandler.send(this.stateFeedbackTopic, this.state)
if (this.state != this.oldState) { if (this.state == 'ON') {
if (this.state == 'ON') { mqttHandler.send(this.actionTopic, 'true')
mqttHandler.send(this.actionTopic, 'true') } else {
} else { mqttHandler.send(this.actionTopic, 'false')
mqttHandler.send(this.actionTopic, 'false')
}
this.oldState = this.state
} }
break break
case this.deviceFeedbackTopic: case this.deviceFeedbackTopic:
@ -74,7 +70,6 @@ export class HomematicSwitchItem extends AHomegearItem implements HasStateAndFee
} else { } else {
this.state = 'OFF' this.state = 'OFF'
} }
this.oldState = this.state
mqttHandler.send(this.stateFeedbackTopic, this.state) mqttHandler.send(this.stateFeedbackTopic, this.state)
break break
} }

View File

@ -41,7 +41,6 @@ export class M433SwitchItem extends AItem implements HasStateAndFeedbackTopicAnd
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback` this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
this.actionTopic = 'IoT/Mqtt433Gateway/Message' this.actionTopic = 'IoT/Mqtt433Gateway/Message'
this.state = 'OFF' this.state = 'OFF'
this.oldState = undefined
this.onCode = onCode this.onCode = onCode
this.offCode = offCode this.offCode = offCode
this.type = type this.type = type
@ -54,13 +53,10 @@ export class M433SwitchItem extends AItem implements HasStateAndFeedbackTopicAnd
processMessage(topic: string, payload: string) { processMessage(topic: string, payload: string) {
this.state = payload; this.state = payload;
mqttHandler.send(this.stateFeedbackTopic, this.state); mqttHandler.send(this.stateFeedbackTopic, this.state);
if (this.state != this.oldState) { if (this.state == 'ON') {
if (this.state == 'ON') { mqttHandler.send(this.actionTopic, this.onCode);
mqttHandler.send(this.actionTopic, this.onCode); } else {
} else { mqttHandler.send(this.actionTopic, this.offCode);
mqttHandler.send(this.actionTopic, this.offCode);
}
this.oldState = this.state;
} }
} }
} }

View File

@ -57,9 +57,9 @@ export class SimpleTopicSwitchItem extends AItem implements HasStateAndFeedbackT
mqttHandler.send(this.stateFeedbackTopic, this.state) mqttHandler.send(this.stateFeedbackTopic, this.state)
if (this.state != this.oldState) { if (this.state != this.oldState) {
if (this.state == 'ON') { if (this.state == 'ON') {
mqttHandler.send(this.actionTopic, 'true') mqttHandler.send(this.actionTopic, 'ON')
} else { } else {
mqttHandler.send(this.actionTopic, 'false') mqttHandler.send(this.actionTopic, 'OFF')
} }
this.oldState = this.state this.oldState = this.state
} }

View File

@ -597,40 +597,40 @@ let watchdogTimer = setInterval(() => {
// ---------------------------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------------------------
// Homekit export // // Homekit export
let homekitObject : { [key:string]:{} } = {} // let homekitObject : { [key:string]:{} } = {}
let openhabList : string[] = [] // let openhabList : string[] = []
// logger.info("allLabeledItems") // // logger.info("allLabeledItems")
// logger.info(JSON.stringify(allLabeledItems)) // // logger.info(JSON.stringify(allLabeledItems))
allLabeledItems.forEach((item: AItem) => { // allLabeledItems.forEach((item: AItem) => {
let exportData : ExportType|null = item.exportItem() // let exportData : ExportType|null = item.exportItem()
if (exportData != null) { // if (exportData != null) {
if ('id' in exportData['homekit']) { // if ('id' in exportData['homekit']) {
homekitObject[exportData['homekit']['id']] = exportData['homekit']['object'] // homekitObject[exportData['homekit']['id']] = exportData['homekit']['object']
} // }
if (exportData['openhab'] instanceof Array) { // if (exportData['openhab'] instanceof Array) {
let da : string[] = exportData['openhab'] as string[] // let da : string[] = exportData['openhab'] as string[]
da.forEach((o: string) => openhabList.push(o)) // da.forEach((o: string) => openhabList.push(o))
} else { // } else {
let da : string = exportData['openhab'] as string // let da : string = exportData['openhab'] as string
openhabList.push(da) // openhabList.push(da)
} // }
// logger.info("openHabList") // // logger.info("openHabList")
// logger.info(JSON.stringify(openhabList)) // // logger.info(JSON.stringify(openhabList))
} // }
}) // })
let heatingMainSwitchExport : ExportType|null = MaxThermostat.exportHeatingMainSwitchItem() // let heatingMainSwitchExport : ExportType|null = MaxThermostat.exportHeatingMainSwitchItem()
if (heatingMainSwitchExport != null) { // if (heatingMainSwitchExport != null) {
let da : string = heatingMainSwitchExport['openhab'] as string // let da : string = heatingMainSwitchExport['openhab'] as string
openhabList.push(da) // openhabList.push(da)
} // }
fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4)) // fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4))
fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n')) // fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n'))
let roomSwitches: any = {} let roomSwitches: any = {}