should fix #11

This commit is contained in:
KarstenSiedentopp
2019-01-24 17:59:04 +01:00
parent 2c7ed22e14
commit c38b7e9087
2 changed files with 13 additions and 11 deletions

View File

@@ -3,5 +3,6 @@
"port": 1883, "port": 1883,
"topic": "tuya/", "topic": "tuya/",
"mqtt_user": "", "mqtt_user": "",
"mqtt_pass": "" "mqtt_pass": "",
"qos": 2
} }

View File

@@ -36,7 +36,9 @@ mqtt_client.on('connect', function (err) {
debugMqtt("Verbindung mit MQTT-Server hergestellt"); debugMqtt("Verbindung mit MQTT-Server hergestellt");
connected = true; connected = true;
var topic = CONFIG.topic + '#'; var topic = CONFIG.topic + '#';
mqtt_client.subscribe(topic); mqtt_client.subscribe(topic, {
qos: CONFIG.qos
});
}); });
mqtt_client.on("reconnect", function (error) { mqtt_client.on("reconnect", function (error) {
@@ -109,7 +111,7 @@ function publishStatus(device, status) {
var topic = CONFIG.topic + type + "/" + tuyaID + "/" + tuyaKey + "/" + tuyaIP + "/state"; var topic = CONFIG.topic + type + "/" + tuyaID + "/" + tuyaKey + "/" + tuyaIP + "/state";
mqtt_client.publish(topic, status, { mqtt_client.publish(topic, status, {
retain: true, retain: true,
qos: 2 qos: CONFIG.qos
}); });
debugTuya("mqtt status updated to:" + topic + " -> " + status); debugTuya("mqtt status updated to:" + topic + " -> " + status);
} else { } else {
@@ -140,7 +142,7 @@ function publishDPS(device, dps) {
debugTuya("mqtt dps updated to:" + topic + " -> ", data); debugTuya("mqtt dps updated to:" + topic + " -> ", data);
mqtt_client.publish(topic, data, { mqtt_client.publish(topic, data, {
retain: true, retain: true,
qos: 2 qos: CONFIG.qos
}); });
Object.keys(dps).forEach(function (key) { Object.keys(dps).forEach(function (key) {
@@ -149,7 +151,7 @@ function publishDPS(device, dps) {
debugTuya("mqtt dps updated to:" + topic + " -> dps[" + key + "]", data); debugTuya("mqtt dps updated to:" + topic + " -> dps[" + key + "]", data);
mqtt_client.publish(topic, data, { mqtt_client.publish(topic, data, {
retain: true, retain: true,
qos: 2 qos: CONFIG.qos
}); });
}); });
} else { } else {
@@ -169,10 +171,9 @@ TuyaDevice.onAll('data', function (data) {
try { try {
debugTuya('Data from device ' + this.type + ' :', data); debugTuya('Data from device ' + this.type + ' :', data);
var status = data.dps['1']; var status = data.dps['1'];
if (this.type == "lightbulb" && status == undefined) { if (status != undefined) {
status = true;
}
publishStatus(this, bmap(status)); publishStatus(this, bmap(status));
}
publishDPS(this, data.dps); publishDPS(this, data.dps);
} catch (e) { } catch (e) {
debugError(e); debugError(e);