Merge PR #256: OneWire: Fix manual discovery of connected devices

This commit is contained in:
Jenkins nymea 2020-04-14 17:29:26 +02:00
commit 64bfd2394a
4 changed files with 22 additions and 17 deletions

View File

@ -57,17 +57,20 @@ void IntegrationPluginOneWire::discoverThings(ThingDiscoveryInfo *info)
foreach(Thing *parentDevice, myThings().filterByThingClassId(oneWireInterfaceThingClassId)) {
if (parentDevice->stateValue(oneWireInterfaceAutoAddStateTypeId).toBool()) {
//devices cannot be discovered since auto mode is enabled
return info->finish(Thing::ThingErrorNoError);
} else {
if (m_oneWireInterface)
m_oneWireInterface->discoverDevices();
continue;
}
m_runningDiscoveries.insert(parentDevice, info);
connect(info, &ThingDiscoveryInfo::destroyed, this, [this, parentDevice](){
m_runningDiscoveries.remove(parentDevice);
});
if (m_oneWireInterface)
m_oneWireInterface->discoverDevices();
}
m_runningDiscoveries.append(info);
connect(info, &ThingDiscoveryInfo::destroyed, this, [this, info](){
m_runningDiscoveries.removeAll(info);
});
if (m_runningDiscoveries.isEmpty()) {
info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("All configured one wire interfaces are set up to automatically add new devices."));
}
return;
}
@ -370,9 +373,8 @@ void IntegrationPluginOneWire::onOneWireDevicesDiscovered(QList<OneWire::OneWire
if (autoDiscoverEnabled) {
emit autoThingsAppeared(descriptors);
} else {
while (!m_runningDiscoveries.isEmpty()) {
ThingDiscoveryInfo *info = m_runningDiscoveries.takeFirst();
ThingDiscoveryInfo *info = m_runningDiscoveries.take(parentDevice);
if (info && m_runningDiscoveries.isEmpty()) {
info->addThingDescriptors(descriptors);
info->finish(Thing::ThingErrorNoError);
}

View File

@ -56,7 +56,7 @@ private:
PluginTimer *m_pluginTimer = nullptr;
OneWire *m_oneWireInterface = nullptr;
QList<ThingDiscoveryInfo*> m_runningDiscoveries;
QHash<Thing*, ThingDiscoveryInfo*> m_runningDiscoveries;
private slots:
void onPluginTimer();

View File

@ -101,9 +101,7 @@ bool OneWire::discoverDevices()
oneWireDevices.append(thing);
}
}
if(!oneWireDevices.isEmpty()) {
emit devicesDiscovered(oneWireDevices);
}
emit devicesDiscovered(oneWireDevices);
return true;
}

View File

@ -10,13 +10,18 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginonewire.cpp" line="88"/>
<location filename="../integrationpluginonewire.cpp" line="72"/>
<source>All configured one wire interfaces are set up to automatically add new devices.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginonewire.cpp" line="91"/>
<source>There can only be one one wire interface per system.</source>
<extracomment>Error setting up thing</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginonewire.cpp" line="97"/>
<location filename="../integrationpluginonewire.cpp" line="100"/>
<source>Error initializing one wire interface.</source>
<extracomment>Error setting up thing</extracomment>
<translation type="unfinished"></translation>