From 721dcf6bc910fb8114d2702df881e8b6488486f1 Mon Sep 17 00:00:00 2001 From: ebaauw Date: Sat, 5 Jun 2021 17:00:33 +0200 Subject: [PATCH] Update rest_lights.cpp Don't send _Off with Effect_ to KNYCKLAN receiver, see #4964. Untested as I don't have this device. --- rest_lights.cpp | 79 +++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/rest_lights.cpp b/rest_lights.cpp index 306a67dcc5..4c32ebf43c 100644 --- a/rest_lights.cpp +++ b/rest_lights.cpp @@ -548,7 +548,7 @@ int DeRestPluginPrivate::setLightState(const ApiRequest &req, ApiResponse &rsp) { return setWarningDeviceState(req, rsp, taskRef, map); } - + // Danalock support. You need to check for taskRef.lightNode->type() == QLatin1String("Door lock"), similar to what I've done under hasAlert for the Siren. bool isDoorLockDevice = false; if (taskRef.lightNode->type() == QLatin1String("Door Lock")) @@ -1473,7 +1473,8 @@ int DeRestPluginPrivate::setLightState(const ApiRequest &req, ApiResponse &rsp) else { const quint16 manufacturerCode = taskRef.lightNode->manufacturerCode(); - const quint8 cmd = (manufacturerCode == VENDOR_PHILIPS || manufacturerCode == VENDOR_IKEA) + const quint8 cmd = (manufacturerCode == VENDOR_PHILIPS || + (manufacturerCode == VENDOR_IKEA && taskRef.lightNode->modelId() != QLatin1String("KNYCKLAN receiver"))) ? ONOFF_COMMAND_OFF_WITH_EFFECT : ONOFF_COMMAND_OFF; ok = addTaskSetOnOff(task, cmd, 0, 0); @@ -1946,15 +1947,15 @@ int DeRestPluginPrivate::setWindowCoveringState(const ApiRequest &req, ApiRespon int DeRestPluginPrivate::setTuyaDeviceState(const ApiRequest &req, ApiResponse &rsp, TaskItem &taskRef, QVariantMap &map) { QString id = req.path[3]; - + bool targetOn = false; bool hasOn = false; bool hasBri = false; bool hasAlert = false; uint targetBri = 0; - + bool ok = false; - + //Parse all parameters for (QVariantMap::const_iterator p = map.begin(); p != map.end(); p++) { @@ -1987,13 +1988,13 @@ int DeRestPluginPrivate::setTuyaDeviceState(const ApiRequest &req, ApiResponse & rsp.list.append(errorToMap(ERR_INVALID_VALUE, QString("/lights/%1/state").arg(id), QString("invalid value, %1, for parameter, on").arg(map["on"].toString()))); } } - - else if (p.key() == "alert") - { - if (map[p.key()].type() == QVariant::String) - { - hasAlert = true; - } + + else if (p.key() == "alert") + { + if (map[p.key()].type() == QVariant::String) + { + hasAlert = true; + } } else @@ -2001,12 +2002,12 @@ int DeRestPluginPrivate::setTuyaDeviceState(const ApiRequest &req, ApiResponse & rsp.list.append(errorToMap(ERR_PARAMETER_NOT_AVAILABLE, QString("/lights/%1/state").arg(id), QString("parameter, %1, not available").arg(p.key()))); } } - + // Return direct if there is already error if (!rsp.list.isEmpty()) { - rsp.httpStatus = HttpStatusBadRequest; - return REQ_READY_SEND; + rsp.httpStatus = HttpStatusBadRequest; + return REQ_READY_SEND; } if (hasBri) @@ -2015,7 +2016,7 @@ int DeRestPluginPrivate::setTuyaDeviceState(const ApiRequest &req, ApiResponse & QByteArray data = QByteArray("\x00\x00", 2); data.append(static_cast((bri >> 8) & 0xff)); data.append(static_cast(bri & 0xff)); - + if (R_GetProductId(taskRef.lightNode) == QLatin1String("Tuya_DIMSWITCH Earda Dimmer") || R_GetProductId(taskRef.lightNode) == QLatin1String("Tuya_DIMSWITCH EDM-1ZAA-EU")) { @@ -2025,7 +2026,7 @@ int DeRestPluginPrivate::setTuyaDeviceState(const ApiRequest &req, ApiResponse & { ok = sendTuyaRequest(taskRef, TaskTuyaRequest, DP_TYPE_VALUE, DP_IDENTIFIER_DIMMER_LEVEL_MODE1, data); } - + if (ok) { QVariantMap rspItem; @@ -2080,28 +2081,28 @@ int DeRestPluginPrivate::setTuyaDeviceState(const ApiRequest &req, ApiResponse & } } - - if (hasAlert) - { - QByteArray data("\x00", 1); - - if (map["alert"].toString() == "lselect") - { - data = QByteArray("\x01",1); - } - - if (sendTuyaRequest(taskRef, TaskTuyaRequest, DP_TYPE_BOOL, DP_IDENTIFIER_ALARM, data)) - { - QVariantMap rspItem; - QVariantMap rspItemState; - rspItemState[QString("/lights/%1/state/alert").arg(id)] = map["alert"].toString(); - rspItem["success"] = rspItemState; - rsp.list.append(rspItem); - } - else - { - rsp.list.append(errorToMap(ERR_INTERNAL_ERROR, QString("/lights/%1").arg(id), QString("Internal error, %1").arg(ERR_BRIDGE_BUSY))); - } + + if (hasAlert) + { + QByteArray data("\x00", 1); + + if (map["alert"].toString() == "lselect") + { + data = QByteArray("\x01",1); + } + + if (sendTuyaRequest(taskRef, TaskTuyaRequest, DP_TYPE_BOOL, DP_IDENTIFIER_ALARM, data)) + { + QVariantMap rspItem; + QVariantMap rspItemState; + rspItemState[QString("/lights/%1/state/alert").arg(id)] = map["alert"].toString(); + rspItem["success"] = rspItemState; + rsp.list.append(rspItem); + } + else + { + rsp.list.append(errorToMap(ERR_INTERNAL_ERROR, QString("/lights/%1").arg(id), QString("Internal error, %1").arg(ERR_BRIDGE_BUSY))); + } } return REQ_READY_SEND;