mirror of
https://github.com/lehanspb/tuya-mqtt.git
synced 2025-12-18 08:13:23 +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. Also fixes a problem with the setColor method of TuyaColorLight. When passing colorValue the curly braces are part of the colorValue string, but when you hit the .split to break up the string into Hue, Saturation and Brightness the curly braces are still considered part of the string so the Hue value was always returning a NaN value due to { was part of the Hue. Therefore I created a private function that strips off the beginning and ending curly braces so the right numeric values can be found.
{"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:
@@ -181,20 +181,26 @@ TuyaColorLight.prototype.setHSL = function (hue, saturation, brightness) {
|
||||
this.setHue(hue);
|
||||
}
|
||||
|
||||
TuyaColorLight.prototype._stripBraces = function (string) {
|
||||
return string.slice(1,-1);
|
||||
}
|
||||
/**
|
||||
* Set color from given string
|
||||
* @param {String} colorValue could be HEX or HSL color type
|
||||
* @returns {Object} dps settings for given color
|
||||
*/
|
||||
TuyaColorLight.prototype.setColor = function (colorValue) {
|
||||
debug("Recieved color", colorValue);
|
||||
var colorValue2;
|
||||
|
||||
if (this._ValIsHex(colorValue)) {
|
||||
debug("Received color", colorValue);
|
||||
colorValue2 = this._stripBraces(colorValue);
|
||||
debug("colorValue2 = "+colorValue2);
|
||||
if (this._ValIsHex(colorValue2)) {
|
||||
debug("Color is Hex");
|
||||
var color = convert.hex.hsl(colorValue);
|
||||
color = convert.hex.hsl(colorValue2);
|
||||
} else {
|
||||
debug("Color is HSL");
|
||||
var color = colorValue.split(",");
|
||||
var color = colorValue2.split(",");
|
||||
// convert strings to numbers
|
||||
color.forEach(function (element, key) {
|
||||
color[key] = parseInt(element, 10);
|
||||
@@ -244,4 +250,4 @@ TuyaColorLight.prototype.getDps = function () {
|
||||
return dpsTmp;
|
||||
}
|
||||
|
||||
module.exports = TuyaColorLight;
|
||||
module.exports = TuyaColorLight;
|
||||
|
||||
Reference in New Issue
Block a user