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 */ /** Destructor */
~Idm(); ~Idm();
QHostAddress getIdmAddress() const {return m_hostAddress;};
private: private:
/** Modbus Unit ID of Idm device */ /** Modbus Unit ID of Idm device */

View File

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