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

View File

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

View File

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

View File

@ -10,13 +10,18 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<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> <source>There can only be one one wire interface per system.</source>
<extracomment>Error setting up thing</extracomment> <extracomment>Error setting up thing</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../integrationpluginonewire.cpp" line="97"/> <location filename="../integrationpluginonewire.cpp" line="100"/>
<source>Error initializing one wire interface.</source> <source>Error initializing one wire interface.</source>
<extracomment>Error setting up thing</extracomment> <extracomment>Error setting up thing</extracomment>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>