Add toggle support for groups
This allows to change a group from on to off ja vice versa with the
same button event.
@@ -764,6 +764,7 @@ int DeRestPluginPrivate::setGroupState(const ApiRequest &req, ApiResponse &rsp)
bool hasEffect = map.contains("effect");
bool hasEffectColorLoop = false;
bool hasAlert = map.contains("alert");
+ bool hasToggle = map.contains("toggle");
bool on = false;
uint bri = 0;
@@ -784,6 +785,25 @@ int DeRestPluginPrivate::setGroupState(const ApiRequest &req, ApiResponse &rsp)
}
}
+ // toggle
+ if (hasToggle)
+ {
+ if (map["toggle"].type() == QVariant::Bool)
+ {
+ if (map["toggle"] == true)
+ {
+ map["on"] = group->item(RStateAnyOn)->toBool() ? false : true;
+ hasOn = true;
+ }
+ }
+ else
+ {
+ rsp.list.append(errorToMap(ERR_INVALID_VALUE, QString("/groups/%1/action/toggle").arg(id), QString("invalid value, %1, for parameter, toggle").arg(map["toggle"].toString())));
+ rsp.httpStatus = HttpStatusBadRequest;
+ return REQ_READY_SEND;
+ }
+ }
+
// on/off
if (hasOn)
{
