Skip to content
Permalink
Browse files

Prevent creation of a CLIP sensor with already existing uniqueid

  • Loading branch information
manup committed Sep 18, 2019
1 parent 758e22c commit 8239d347ea0bdb5c4b668e495a31e9bd04e1c6de
Showing with 12 additions and 0 deletions.
  1. +5 −0 de_web_plugin.cpp
  2. +7 −0 rest_sensors.cpp
@@ -7134,6 +7134,11 @@ Sensor *DeRestPluginPrivate::getSensorNodeForFingerPrint(quint64 extAddr, const
*/
Sensor *DeRestPluginPrivate::getSensorNodeForUniqueId(const QString &uniqueId)
{
if (uniqueId.isEmpty())
{
return nullptr;
}

for (Sensor &s : sensors)
{
if (s.deletedState() == Sensor::StateNormal && s.uniqueId() == uniqueId)
@@ -330,6 +330,13 @@ int DeRestPluginPrivate::createSensor(const ApiRequest &req, ApiResponse &rsp)
sensor.setSwVersion(map["swversion"].toString());
sensor.setType(type);

if (getSensorNodeForUniqueId(sensor.uniqueId()))
{
rsp.list.append(errorToMap(ERR_DUPLICATE_EXIST, QString("/sensors"), QString("sensor with uniqueid, %1, already exists").arg(sensor.uniqueId())));
rsp.httpStatus = HttpStatusBadRequest;
return REQ_READY_SEND;
}

if (type == QLatin1String("CLIPAlarm")) { item = sensor.addItem(DataTypeBool, RStateAlarm); item->setValue(false); }
else if (type == QLatin1String("CLIPBattery")) { item = sensor.addItem(DataTypeUInt8, RStateBattery); item->setValue(100); }
else if (type == QLatin1String("CLIPCarbonMonoxide")) { item = sensor.addItem(DataTypeBool, RStateCarbonMonoxide); item->setValue(false); }

0 comments on commit 8239d34

Please sign in to comment.
You can’t perform that action at this time.