mirror of
https://github.com/lehanspb/tuya-mqtt.git
synced 2025-12-16 17:54:36 +00:00
ADD: support to toggle device state
This commit is contained in:
24
tuya-mqtt.js
24
tuya-mqtt.js
@@ -151,10 +151,14 @@ function getCommandFromTopic(_topic, _message) {
|
||||
debug("command is JSON");
|
||||
command = JSON.parse(command);
|
||||
} else {
|
||||
// convert simple commands (on, off, 1, 0) to TuyAPI-Commands
|
||||
var convertString = command.toLowerCase() == "on" || command == "1" || command == 1 ? true : false;
|
||||
command = {
|
||||
set: convertString
|
||||
if (command.toLowerCase() != "toggle") {
|
||||
// convert simple commands (on, off, 1, 0) to TuyAPI-Commands
|
||||
var convertString = command.toLowerCase() == "on" || command == "1" || command == 1 ? true : false;
|
||||
command = {
|
||||
set: convertString
|
||||
}
|
||||
} else {
|
||||
command = command.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,9 +186,15 @@ mqtt_client.on('message', function (topic, message) {
|
||||
case "command":
|
||||
var command = getCommandFromTopic(topic, message);
|
||||
debug("receive command", command);
|
||||
device.set(command).then((data) => {
|
||||
debug("set device status completed", data);
|
||||
});
|
||||
if (command == "toggle") {
|
||||
device.switch(command).then((data) => {
|
||||
debug("set device status completed", data);
|
||||
});
|
||||
} else {
|
||||
device.set(command).then((data) => {
|
||||
debug("set device status completed", data);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "color":
|
||||
var color = message.toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user