OneWire: Fix manual discovering of connected devices

This commit is contained in:
Michael Zanetti 2020-04-14 11:17:58 +02:00
parent ac6dcf0765
commit 37081a51bd
3 changed files with 9 additions and 11 deletions

View File

@ -59,15 +59,16 @@ void IntegrationPluginOneWire::discoverThings(ThingDiscoveryInfo *info)
//devices cannot be discovered since auto mode is enabled //devices cannot be discovered since auto mode is enabled
return info->finish(Thing::ThingErrorNoError); return info->finish(Thing::ThingErrorNoError);
} else { } else {
m_runningDiscoveries.insert(parentDevice, info);
connect(info, &ThingDiscoveryInfo::destroyed, this, [this, parentDevice](){
m_runningDiscoveries.remove(parentDevice);
});
if (m_oneWireInterface) if (m_oneWireInterface)
m_oneWireInterface->discoverDevices(); m_oneWireInterface->discoverDevices();
} }
} }
m_runningDiscoveries.append(info);
connect(info, &ThingDiscoveryInfo::destroyed, this, [this, info](){
m_runningDiscoveries.removeAll(info);
});
return; return;
} }
@ -370,9 +371,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;
} }