Update discovery to renamed network device

This commit is contained in:
Simon Stürz 2021-06-11 11:04:00 +02:00
parent a690689ab8
commit dfcebb0f6b

View File

@ -56,41 +56,41 @@ void IntegrationPluginGoECharger::discoverThings(ThingDiscoveryInfo *info)
// Perform a network device discovery and filter for "go-eCharger" hosts // Perform a network device discovery and filter for "go-eCharger" hosts
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
foreach (const NetworkDevice &networkDevice, discoveryReply->networkDevices()) { foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
qCDebug(dcGoECharger()) << "Checking discovered" << networkDevice; qCDebug(dcGoECharger()) << "Checking discovered" << networkDeviceInfo;
// Filter by hostname // Filter by hostname
if (!networkDevice.hostName().toLower().contains("go-echarger")) if (!networkDeviceInfo.hostName().contains("go-eCharger"))
continue; continue;
// We need also the mac address // We need also the mac address
if (networkDevice.macAddress().isEmpty()) if (networkDeviceInfo.macAddress().isEmpty())
continue; continue;
QString title; QString title;
if (networkDevice.hostName().isEmpty()) { if (networkDeviceInfo.hostName().isEmpty()) {
title = networkDevice.address().toString(); title = networkDeviceInfo.address().toString();
} else { } else {
title = "go-eCharger (" + networkDevice.address().toString() + ")"; title = "go-eCharger (" + networkDeviceInfo.address().toString() + ")";
} }
QString description; QString description;
if (networkDevice.macAddressManufacturer().isEmpty()) { if (networkDeviceInfo.macAddressManufacturer().isEmpty()) {
description = networkDevice.macAddress(); description = networkDeviceInfo.macAddress();
} else { } else {
description = networkDevice.macAddress() + " (" + networkDevice.macAddressManufacturer() + ")"; description = networkDeviceInfo.macAddress() + " (" + networkDeviceInfo.macAddressManufacturer() + ")";
} }
ThingDescriptor descriptor(goeHomeThingClassId, title, description); ThingDescriptor descriptor(goeHomeThingClassId, title, description);
ParamList params; ParamList params;
params << Param(goeHomeThingIpAddressParamTypeId, networkDevice.address().toString()); params << Param(goeHomeThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
params << Param(goeHomeThingMacAddressParamTypeId, networkDevice.macAddress()); params << Param(goeHomeThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
descriptor.setParams(params); descriptor.setParams(params);
// Check if we already have set up this device // Check if we already have set up this device
Things existingThings = myThings().filterByParam(goeHomeThingMacAddressParamTypeId, networkDevice.macAddress()); Things existingThings = myThings().filterByParam(goeHomeThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
if (existingThings.count() == 1) { if (existingThings.count() == 1) {
qCDebug(dcGoECharger()) << "This go-eCharger already exists in the system" << networkDevice; qCDebug(dcGoECharger()) << "This go-eCharger already exists in the system" << networkDeviceInfo;
descriptor.setThingId(existingThings.first()->id()); descriptor.setThingId(existingThings.first()->id());
} }