fixed discovery for temperature and humidity sensors

This commit is contained in:
Boernsman 2021-04-20 13:06:09 +02:00
parent e99643feef
commit f7308e4d9f

View File

@ -43,16 +43,17 @@ void IntegrationPluginOneWire::discoverThings(ThingDiscoveryInfo *info)
{ {
ThingClassId deviceClassId = info->thingClassId(); ThingClassId deviceClassId = info->thingClassId();
if (!m_w1Interface) {
m_w1Interface = new W1(this);
}
if (deviceClassId == temperatureSensorThingClassId || if (deviceClassId == temperatureSensorThingClassId ||
deviceClassId == temperatureHumiditySensorThingClassId ||
deviceClassId == singleChannelSwitchThingClassId || deviceClassId == singleChannelSwitchThingClassId ||
deviceClassId == dualChannelSwitchThingClassId || deviceClassId == dualChannelSwitchThingClassId ||
deviceClassId == eightChannelSwitchThingClassId) { deviceClassId == eightChannelSwitchThingClassId) {
if (myThings().filterByThingClassId(oneWireInterfaceThingClassId).isEmpty()) { if (myThings().filterByThingClassId(oneWireInterfaceThingClassId).isEmpty()) {
if (!m_w1Interface) {
m_w1Interface = new W1(this);
}
if (!m_w1Interface->interfaceIsAvailable()) { if (!m_w1Interface->interfaceIsAvailable()) {
return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No one wire interface initialized. Please set up a one wire interface first.")); return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No one wire interface initialized. Please set up a one wire interface first."));
} }
@ -101,7 +102,7 @@ void IntegrationPluginOneWire::discoverThings(ThingDiscoveryInfo *info)
} }
return; return;
} else { } else {
qCWarning(dcOneWire()) << "Discovery called for a deviceclass which does not support discovery? Device class ID:" << info->thingClassId().toString(); qCWarning(dcOneWire()) << "Discovery called for a device class which does not support discovery? Device class ID:" << info->thingClassId().toString();
info->finish(Thing::ThingErrorThingClassNotFound); info->finish(Thing::ThingErrorThingClassNotFound);
} }
} }
@ -410,7 +411,7 @@ void IntegrationPluginOneWire::onPluginTimer()
void IntegrationPluginOneWire::onOneWireDevicesDiscovered(QList<Owfs::OwfsDevice> oneWireDevices) void IntegrationPluginOneWire::onOneWireDevicesDiscovered(QList<Owfs::OwfsDevice> oneWireDevices)
{ {
foreach(Thing *parentDevice, myThings().filterByThingClassId(oneWireInterfaceThingClassId)) { Thing *parentDevice = myThings().filterByThingClassId(oneWireInterfaceThingClassId).first();
ThingDescriptors descriptors; ThingDescriptors descriptors;
foreach (Owfs::OwfsDevice oneWireDevice, oneWireDevices){ foreach (Owfs::OwfsDevice oneWireDevice, oneWireDevices){
@ -506,6 +507,4 @@ void IntegrationPluginOneWire::onOneWireDevicesDiscovered(QList<Owfs::OwfsDevice
info->addThingDescriptors(descriptors); info->addThingDescriptors(descriptors);
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
} }
break;
}
} }