Skip to content

Commit

Permalink
Merge pull request #4978 from ebaauw/master
Browse files Browse the repository at this point in the history
Fix KNYCKLAN receiver doesn't turn off.
  • Loading branch information
manup authored Jun 12, 2021
2 parents fa1f07c + ff81c28 commit 49217fb
Showing 1 changed file with 40 additions and 39 deletions.
79 changes: 40 additions & 39 deletions rest_lights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++)
{
Expand Down Expand Up @@ -1987,26 +1988,26 @@ 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
{
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)
Expand All @@ -2015,7 +2016,7 @@ int DeRestPluginPrivate::setTuyaDeviceState(const ApiRequest &req, ApiResponse &
QByteArray data = QByteArray("\x00\x00", 2);
data.append(static_cast<qint8>((bri >> 8) & 0xff));
data.append(static_cast<qint8>(bri & 0xff));

if (R_GetProductId(taskRef.lightNode) == QLatin1String("Tuya_DIMSWITCH Earda Dimmer") ||
R_GetProductId(taskRef.lightNode) == QLatin1String("Tuya_DIMSWITCH EDM-1ZAA-EU"))
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 49217fb

Please sign in to comment.