Fix preventing adding the same IP a second time

master
Hermann Detz 2020-11-17 11:17:48 +01:00 committed by Michael Zanetti
parent e202b328b7
commit af93c6c9a0
2 changed files with 23 additions and 8 deletions

View File

@ -74,6 +74,8 @@ public:
/** Destructor */
~Idm();
QHostAddress getIdmAddress() const {return m_hostAddress;};
private:
/** Modbus Unit ID of Idm device */

View File

@ -39,7 +39,7 @@ IntegrationPluginIdm::IntegrationPluginIdm()
void IntegrationPluginIdm::discoverThings(ThingDiscoveryInfo *info)
{
if (info->thingClassId() == navigator2ThingClassId) {
// TODO Is a discovery method actually needed?
// TODO Is a discovery method actually possible?
// The plugin has a parameter for the IP address
QString description = "Navigator 2";
@ -59,16 +59,29 @@ void IntegrationPluginIdm::setupThing(ThingSetupInfo *info)
if (thing->thingClassId() == navigator2ThingClassId) {
QHostAddress hostAddress = QHostAddress(thing->paramValue(navigator2ThingIpAddressParamTypeId).toString());
/* Create new Idm object and store it in hash table */
Idm *idm = new Idm(hostAddress, this);
m_idmConnections.insert(thing, idm);
if (hostAddress.isNull() == false) {
/* Check, if address is already in use for another device */
bool found = false;
/* Store thing info in hash table */
m_idmInfos.insert(thing, info);
for (QHash<Thing *, Idm *>::iterator item=m_idmConnections.begin(); item != m_idmConnections.end(); item++) {
if (hostAddress.isEqual(item.value()->getIdmAddress()))
found = true;
}
info->finish(Thing::ThingErrorNoError);
if (found == false) {
/* Create new Idm object and store it in hash table */
Idm *idm = new Idm(hostAddress, this);
m_idmConnections.insert(thing, idm);
/* Store thing info in hash table */
m_idmInfos.insert(thing, info);
info->finish(Thing::ThingErrorNoError);
} else {
info->finish(Thing::ThingErrorThingInUse);
}
}
}
}
void IntegrationPluginIdm::postSetupThing(Thing *thing)