fixed discovery for temperature and humidity sensors

master
Boernsman 2021-04-20 13:06:09 +02:00
parent e99643feef
commit f7308e4d9f
1 changed files with 88 additions and 89 deletions

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,102 +411,100 @@ 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){
switch (oneWireDevice.family) { switch (oneWireDevice.family) {
//https://github.com/owfs/owfs-doc/wiki/1Wire-Device-List //https://github.com/owfs/owfs-doc/wiki/1Wire-Device-List
case 0x10: //DS18S20 case 0x10: //DS18S20
case 0x22: //DS1822 case 0x22: //DS1822
case 0x28: //DS18B20 case 0x28: //DS18B20
case 0x3b: {//DS1825, MAX31826, MAX31850 case 0x3b: {//DS1825, MAX31826, MAX31850
ThingDescriptor descriptor(temperatureSensorThingClassId, oneWireDevice.type, "One wire temperature sensor", parentDevice->id()); ThingDescriptor descriptor(temperatureSensorThingClassId, oneWireDevice.type, "One wire temperature sensor", parentDevice->id());
ParamList params; ParamList params;
params.append(Param(temperatureSensorThingAddressParamTypeId, oneWireDevice.address)); params.append(Param(temperatureSensorThingAddressParamTypeId, oneWireDevice.address));
params.append(Param(temperatureSensorThingTypeParamTypeId, oneWireDevice.type)); params.append(Param(temperatureSensorThingTypeParamTypeId, oneWireDevice.type));
foreach (Thing *existingThing, myThings().filterByThingClassId(temperatureSensorThingClassId)){ foreach (Thing *existingThing, myThings().filterByThingClassId(temperatureSensorThingClassId)){
if (existingThing->paramValue(temperatureSensorThingAddressParamTypeId).toString() == oneWireDevice.address) { if (existingThing->paramValue(temperatureSensorThingAddressParamTypeId).toString() == oneWireDevice.address) {
descriptor.setThingId(existingThing->id()); descriptor.setThingId(existingThing->id());
break; break;
}
} }
descriptor.setParams(params);
descriptors.append(descriptor);
break;
} }
case 0x26: {//DS2834 descriptor.setParams(params);
ThingDescriptor descriptor(temperatureHumiditySensorThingClassId, oneWireDevice.type, "One wire temperature and humidity sensor", parentDevice->id()); descriptors.append(descriptor);
ParamList params; break;
params.append(Param(temperatureHumiditySensorThingAddressParamTypeId, oneWireDevice.address)); }
params.append(Param(temperatureHumiditySensorThingTypeParamTypeId, oneWireDevice.type)); case 0x26: {//DS2834
foreach (Thing *existingThing, myThings().filterByThingClassId(temperatureHumiditySensorThingClassId)){ ThingDescriptor descriptor(temperatureHumiditySensorThingClassId, oneWireDevice.type, "One wire temperature and humidity sensor", parentDevice->id());
if (existingThing->paramValue(temperatureHumiditySensorThingAddressParamTypeId).toString() == oneWireDevice.address) { ParamList params;
descriptor.setThingId(existingThing->id()); params.append(Param(temperatureHumiditySensorThingAddressParamTypeId, oneWireDevice.address));
break; params.append(Param(temperatureHumiditySensorThingTypeParamTypeId, oneWireDevice.type));
} foreach (Thing *existingThing, myThings().filterByThingClassId(temperatureHumiditySensorThingClassId)){
if (existingThing->paramValue(temperatureHumiditySensorThingAddressParamTypeId).toString() == oneWireDevice.address) {
descriptor.setThingId(existingThing->id());
break;
} }
descriptor.setParams(params);
descriptors.append(descriptor);
break;
} }
case 0x05: { //single channel switch descriptor.setParams(params);
ThingDescriptor descriptor(singleChannelSwitchThingClassId, oneWireDevice.type, "One wire single channel switch", parentDevice->id()); descriptors.append(descriptor);
ParamList params; break;
params.append(Param(singleChannelSwitchThingAddressParamTypeId, oneWireDevice.address)); }
params.append(Param(singleChannelSwitchThingTypeParamTypeId, oneWireDevice.type)); case 0x05: { //single channel switch
foreach (Thing *existingThing, myThings().filterByThingClassId(singleChannelSwitchThingClassId)){ ThingDescriptor descriptor(singleChannelSwitchThingClassId, oneWireDevice.type, "One wire single channel switch", parentDevice->id());
if (existingThing->paramValue(singleChannelSwitchThingAddressParamTypeId).toString() == oneWireDevice.address) { ParamList params;
descriptor.setThingId(existingThing->id()); params.append(Param(singleChannelSwitchThingAddressParamTypeId, oneWireDevice.address));
break; params.append(Param(singleChannelSwitchThingTypeParamTypeId, oneWireDevice.type));
} foreach (Thing *existingThing, myThings().filterByThingClassId(singleChannelSwitchThingClassId)){
if (existingThing->paramValue(singleChannelSwitchThingAddressParamTypeId).toString() == oneWireDevice.address) {
descriptor.setThingId(existingThing->id());
break;
} }
descriptor.setParams(params);
descriptors.append(descriptor);
break;
} }
case 0x12: descriptor.setParams(params);
case 0x3a: {//dual channel switch descriptors.append(descriptor);
ThingDescriptor descriptor(dualChannelSwitchThingClassId, oneWireDevice.type, "One wire dual channel switch", parentDevice->id()); break;
ParamList params; }
params.append(Param(dualChannelSwitchThingAddressParamTypeId, oneWireDevice.address)); case 0x12:
params.append(Param(dualChannelSwitchThingTypeParamTypeId, oneWireDevice.type)); case 0x3a: {//dual channel switch
foreach (Thing *existingThing, myThings().filterByThingClassId(dualChannelSwitchThingClassId)){ ThingDescriptor descriptor(dualChannelSwitchThingClassId, oneWireDevice.type, "One wire dual channel switch", parentDevice->id());
if (existingThing->paramValue(dualChannelSwitchThingAddressParamTypeId).toString() == oneWireDevice.address) { ParamList params;
descriptor.setThingId(existingThing->id()); params.append(Param(dualChannelSwitchThingAddressParamTypeId, oneWireDevice.address));
break; params.append(Param(dualChannelSwitchThingTypeParamTypeId, oneWireDevice.type));
} foreach (Thing *existingThing, myThings().filterByThingClassId(dualChannelSwitchThingClassId)){
if (existingThing->paramValue(dualChannelSwitchThingAddressParamTypeId).toString() == oneWireDevice.address) {
descriptor.setThingId(existingThing->id());
break;
} }
descriptor.setParams(params);
descriptors.append(descriptor);
break;
} }
case 0x29: { //eight channel switch descriptor.setParams(params);
ThingDescriptor descriptor(eightChannelSwitchThingClassId, oneWireDevice.type, "One wire eight channel switch", parentDevice->id()); descriptors.append(descriptor);
ParamList params; break;
params.append(Param(eightChannelSwitchThingAddressParamTypeId, oneWireDevice.address)); }
params.append(Param(eightChannelSwitchThingTypeParamTypeId, oneWireDevice.type)); case 0x29: { //eight channel switch
foreach (Thing *existingThing, myThings().filterByThingClassId(eightChannelSwitchThingClassId)){ ThingDescriptor descriptor(eightChannelSwitchThingClassId, oneWireDevice.type, "One wire eight channel switch", parentDevice->id());
if (existingThing->paramValue(eightChannelSwitchThingAddressParamTypeId).toString() == oneWireDevice.address) { ParamList params;
descriptor.setThingId(existingThing->id()); params.append(Param(eightChannelSwitchThingAddressParamTypeId, oneWireDevice.address));
break; params.append(Param(eightChannelSwitchThingTypeParamTypeId, oneWireDevice.type));
} foreach (Thing *existingThing, myThings().filterByThingClassId(eightChannelSwitchThingClassId)){
if (existingThing->paramValue(eightChannelSwitchThingAddressParamTypeId).toString() == oneWireDevice.address) {
descriptor.setThingId(existingThing->id());
break;
} }
descriptor.setParams(params);
descriptors.append(descriptor);
break;
} }
default: descriptor.setParams(params);
qDebug(dcOneWire()) << "Unknown Device discovered" << oneWireDevice.type << oneWireDevice.address; descriptors.append(descriptor);
break; break;
}
default:
qDebug(dcOneWire()) << "Unknown Device discovered" << oneWireDevice.type << oneWireDevice.address;
break;
}
} }
ThingDiscoveryInfo *info = m_runningDiscoveries.take(parentDevice); }
if (info && m_runningDiscoveries.isEmpty()) { ThingDiscoveryInfo *info = m_runningDiscoveries.take(parentDevice);
info->addThingDescriptors(descriptors); if (info && m_runningDiscoveries.isEmpty()) {
info->finish(Thing::ThingErrorNoError); info->addThingDescriptors(descriptors);
} info->finish(Thing::ThingErrorNoError);
break;
} }
} }