DEV_AddResource prevent double entries
@@ -17799,23 +17799,33 @@ Resource *DEV_GetResource(Resource::Handle hnd)
// Used by Device class when creating Sensors.
// Testing code uses a mocked implementation.
Resource *DEV_AddResource(const Sensor &sensor)
+{
+ Resource *r = DEV_GetResource(sensor.prefix(), sensor.item(RAttrUniqueId)->toString());
+
+ if (!r)
{
plugin->sensors.push_back(sensor);
- auto &s = plugin->sensors.back();
- s.setHandle(R_CreateResourceHandle(&s, plugin->sensors.size() - 1));
+ r = &plugin->sensors.back();
+ r->setHandle(R_CreateResourceHandle(r, plugin->sensors.size() - 1));
+ }
- return &s;
+ return r;
}
// Used by Device class when creating LightNodes.
// Testing code uses a mocked implementation.
Resource *DEV_AddResource(const LightNode &lightNode)
+{
+ Resource *r = DEV_GetResource(lightNode.prefix(), lightNode.item(RAttrUniqueId)->toString());
+
+ if (!r)
{
plugin->nodes.push_back(lightNode);
- auto &l = plugin->nodes.back();
- l.setHandle(R_CreateResourceHandle(&l, plugin->nodes.size() - 1));
+ r = &plugin->nodes.back();
+ r->setHandle(R_CreateResourceHandle(r, plugin->nodes.size() - 1));
+ }
- return &l;
+ return r;
}
/*! Called by init DDF to allocate new groups for config.group = "auto [,auto, ...]".
