Skip to content

Commit 8239d34

Browse files
committed
Prevent creation of a CLIP sensor with already existing uniqueid
1 parent 758e22c commit 8239d34

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

de_web_plugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7134,6 +7134,11 @@ Sensor *DeRestPluginPrivate::getSensorNodeForFingerPrint(quint64 extAddr, const
71347134
*/
71357135
Sensor *DeRestPluginPrivate::getSensorNodeForUniqueId(const QString &uniqueId)
71367136
{
7137+
if (uniqueId.isEmpty())
7138+
{
7139+
return nullptr;
7140+
}
7141+
71377142
for (Sensor &s : sensors)
71387143
{
71397144
if (s.deletedState() == Sensor::StateNormal && s.uniqueId() == uniqueId)

rest_sensors.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ int DeRestPluginPrivate::createSensor(const ApiRequest &req, ApiResponse &rsp)
330330
sensor.setSwVersion(map["swversion"].toString());
331331
sensor.setType(type);
332332

333+
if (getSensorNodeForUniqueId(sensor.uniqueId()))
334+
{
335+
rsp.list.append(errorToMap(ERR_DUPLICATE_EXIST, QString("/sensors"), QString("sensor with uniqueid, %1, already exists").arg(sensor.uniqueId())));
336+
rsp.httpStatus = HttpStatusBadRequest;
337+
return REQ_READY_SEND;
338+
}
339+
333340
if (type == QLatin1String("CLIPAlarm")) { item = sensor.addItem(DataTypeBool, RStateAlarm); item->setValue(false); }
334341
else if (type == QLatin1String("CLIPBattery")) { item = sensor.addItem(DataTypeUInt8, RStateBattery); item->setValue(100); }
335342
else if (type == QLatin1String("CLIPCarbonMonoxide")) { item = sensor.addItem(DataTypeBool, RStateCarbonMonoxide); item->setValue(false); }

0 commit comments

Comments
 (0)