mirror of
https://github.com/lehanspb/tuya-mqtt.git
synced 2025-12-16 17:54:36 +00:00
This update allows for an essential TuyAPI command to be implemented via the tuya-mqtt.exe MQTT server. {"schema": true} is the ONLY COMMAND that the TuyAPI GET method implements.
{"schema": true} allows the user to establish that proper communications with the tuya device can occur WITHOUT actually changing the present STATE of the device. This is the only command that will query the tuya device.
The current documentation says that you can query the tuya device over the "dps" TOPIC but from what I see the present state of the software does not force the tuya device to respond when using the "dps" TOPIC.
Since {"schema": true} is a command that forces a response from the tuya device, this command has been implemented under the "command" TOPIC. So "command" is the action and '{"schema": true}' becomes the command. The response is returned just like all other commands. I, use this command to guarantee communications has been established with the tuya device. If this "schema" command fails, tuya-mqtt will indicate the result in the openhab.log file and then I, can find out what is physically wrong with the communications. If this command fails the first time due to "socket" error and then goes through on the second attempt then I know that the error was due to TCP communications problem on initial startup. This command helps as a work-a-round for the "ERROR: socket problem"
This commit is contained in:
@@ -265,6 +265,12 @@ var TuyaDevice = (function () {
|
||||
});
|
||||
}
|
||||
|
||||
TuyaDevice.prototype.schema = function(obj){
|
||||
return this.get(obj).then((status) => {
|
||||
debug("get", obj);
|
||||
});
|
||||
}
|
||||
|
||||
TuyaDevice.prototype.setColor = function (hexColor) {
|
||||
if (!this.connected) return;
|
||||
debugColor("Set color to: ", hexColor);
|
||||
@@ -318,4 +324,4 @@ var TuyaDevice = (function () {
|
||||
return TuyaDevice;
|
||||
}());
|
||||
|
||||
module.exports = TuyaDevice;
|
||||
module.exports = TuyaDevice;
|
||||
|
||||
18
tuya-mqtt.js
18
tuya-mqtt.js
@@ -190,6 +190,22 @@ mqtt_client.on('message', function (topic, message) {
|
||||
device.switch(command).then((data) => {
|
||||
debug("set device status completed", data);
|
||||
});
|
||||
}
|
||||
if (command.schema === true) {
|
||||
// this command is very useful. IT IS A COMMAND. It's place under the command topic.
|
||||
// It's the ONLY command that does not use device.set to get a result.
|
||||
// You have to use device.get and send the get method an exact JSON string of { schema: true }
|
||||
// This schema command does NOT
|
||||
// change the state of the device, all it does is query the device
|
||||
// as a confirmation that all communications are working properly.
|
||||
// Otherwise you have to physically change the state of the device just to
|
||||
// find out if you can talk to it. If this command returns no errors than
|
||||
// we know we are have an established communication channel. This is a native TuyAPI call that
|
||||
// the TuyAPI interface defines (its only available via the GET command.
|
||||
// this call returns a object of results
|
||||
device.schema(command).then((data) => {
|
||||
});
|
||||
debug("get (schema) device status completed");
|
||||
} else {
|
||||
device.set(command).then((data) => {
|
||||
debug("set device status completed", data);
|
||||
@@ -355,4 +371,4 @@ var tester = new MQTT_Tester();
|
||||
function onExit() {
|
||||
TuyaDevice.disconnectAll();
|
||||
if (tester) tester.destroy();
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user