Fix sensors set state and config (todo, test if clip sensors work again)
@@ -678,9 +678,10 @@ int DeRestPluginPrivate::changeSensorConfig(const ApiRequest &req, ApiResponse &
for (; pi != pend; ++pi)
{
ResourceItemDescriptor rid;
+ ResourceItem *item = 0;
if (getResourceItemDescriptor(QString("config/%1").arg(pi.key()), rid))
{
- ResourceItem *item = sensor->item(rid.suffix);
+ item = sensor->item(rid.suffix);
if (!item)
{
break; // not found
@@ -704,11 +705,14 @@ int DeRestPluginPrivate::changeSensorConfig(const ApiRequest &req, ApiResponse &
}
}
+ if (!item)
+ {
// not found
rsp.list.append(errorToMap(ERR_PARAMETER_NOT_AVAILABLE, QString("/sensors/%1/config/%2").arg(id).arg(pi.key()), QString("parameter, %1, not available").arg(pi.key())));
rsp.httpStatus = HttpStatusBadRequest;
return REQ_READY_SEND;
}
+ }
// TODO handle this in event, this is relevant for FLS-NB.
@@ -772,10 +776,11 @@ int DeRestPluginPrivate::changeSensorState(const ApiRequest &req, ApiResponse &r
for (; pi != pend; ++pi)
{
+ ResourceItem *item = 0;
ResourceItemDescriptor rid;
if (isClip && getResourceItemDescriptor(QString("state/%1").arg(pi.key()), rid))
{
- ResourceItem *item = sensor->item(rid.suffix);
+ item = sensor->item(rid.suffix);
if (!item)
{
break; // not found
@@ -799,11 +804,14 @@ int DeRestPluginPrivate::changeSensorState(const ApiRequest &req, ApiResponse &r
}
}
+ if (!item)
+ {
// not found
rsp.list.append(errorToMap(ERR_PARAMETER_NOT_AVAILABLE, QString("/sensors/%1/state/%2").arg(id).arg(pi.key()), QString("parameter, %1, not available").arg(pi.key())));
rsp.httpStatus = HttpStatusBadRequest;
return REQ_READY_SEND;
}
+ }
sensor->setNeedSaveDatabase(true);
rsp.list.append(rspItem);
