Skip to content

Commit

Permalink
Prevent creation of a CLIP sensor with already existing uniqueid
Browse files Browse the repository at this point in the history
  • Loading branch information
manup committed Sep 18, 2019
1 parent 758e22c commit 8239d34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions de_web_plugin.cpp
Expand Up @@ -7134,6 +7134,11 @@ Sensor *DeRestPluginPrivate::getSensorNodeForFingerPrint(quint64 extAddr, const
*/ */
Sensor *DeRestPluginPrivate::getSensorNodeForUniqueId(const QString &uniqueId) Sensor *DeRestPluginPrivate::getSensorNodeForUniqueId(const QString &uniqueId)
{ {
if (uniqueId.isEmpty())
{
return nullptr;
}

for (Sensor &s : sensors) for (Sensor &s : sensors)
{ {
if (s.deletedState() == Sensor::StateNormal && s.uniqueId() == uniqueId) if (s.deletedState() == Sensor::StateNormal && s.uniqueId() == uniqueId)
Expand Down
7 changes: 7 additions & 0 deletions rest_sensors.cpp
Expand Up @@ -330,6 +330,13 @@ int DeRestPluginPrivate::createSensor(const ApiRequest &req, ApiResponse &rsp)
sensor.setSwVersion(map["swversion"].toString()); sensor.setSwVersion(map["swversion"].toString());
sensor.setType(type); 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); } 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("CLIPBattery")) { item = sensor.addItem(DataTypeUInt8, RStateBattery); item->setValue(100); }
else if (type == QLatin1String("CLIPCarbonMonoxide")) { item = sensor.addItem(DataTypeBool, RStateCarbonMonoxide); item->setValue(false); } else if (type == QLatin1String("CLIPCarbonMonoxide")) { item = sensor.addItem(DataTypeBool, RStateCarbonMonoxide); item->setValue(false); }
Expand Down

0 comments on commit 8239d34

Please sign in to comment.