Update discovery to renamed network device

This commit is contained in:
Simon Stürz 2021-06-11 11:15:16 +02:00 committed by Michael Zanetti
parent 515d8f6e42
commit fdee0d6453
7 changed files with 124 additions and 116 deletions

View File

@ -39,39 +39,45 @@ IntegrationPluginIdm::IntegrationPluginIdm()
void IntegrationPluginIdm::discoverThings(ThingDiscoveryInfo *info) void IntegrationPluginIdm::discoverThings(ThingDiscoveryInfo *info)
{ {
if (!hardwareManager()->networkDeviceDiscovery()->available()) {
qCWarning(dcIdm()) << "Failed to discover network devices. The network device discovery is not available.";
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("The discovery is not available."));
return;
}
qCDebug(dcIdm()) << "Discovering network..."; qCDebug(dcIdm()) << "Discovering network...";
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
ThingDescriptors descriptors; ThingDescriptors descriptors;
qCDebug(dcIdm()) << "Discovery finished. Found" << discoveryReply->networkDevices().count() << "devices"; qCDebug(dcIdm()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
foreach (const NetworkDevice &networkDevice, discoveryReply->networkDevices()) { foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
qCDebug(dcIdm()) << networkDevice; qCDebug(dcIdm()) << networkDeviceInfo;
QString title; QString title;
if (networkDevice.hostName().isEmpty()) { if (networkDeviceInfo.hostName().isEmpty()) {
title += networkDevice.address().toString(); title += networkDeviceInfo.address().toString();
} else { } else {
title += networkDevice.address().toString() + " (" + networkDevice.hostName() + ")"; title += networkDeviceInfo.address().toString() + " (" + networkDeviceInfo.hostName() + ")";
} }
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(navigator2ThingClassId, title, description); ThingDescriptor descriptor(navigator2ThingClassId, title, description);
// Check if we already have set up this device // Check if we already have set up this device
Things existingThings = myThings().filterByParam(navigator2ThingMacAddressParamTypeId, networkDevice.macAddress()); Things existingThings = myThings().filterByParam(navigator2ThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
if (existingThings.count() == 1) { if (existingThings.count() == 1) {
qCDebug(dcIdm()) << "This thing already exists in the system." << existingThings.first() << networkDevice; qCDebug(dcIdm()) << "This thing already exists in the system." << existingThings.first() << networkDeviceInfo;
descriptor.setThingId(existingThings.first()->id()); descriptor.setThingId(existingThings.first()->id());
} }
ParamList params; ParamList params;
params << Param(navigator2ThingMacAddressParamTypeId, networkDevice.macAddress()); params << Param(navigator2ThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
params << Param(navigator2ThingIpAddressParamTypeId, networkDevice.address().toString()); params << Param(navigator2ThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
descriptor.setParams(params); descriptor.setParams(params);
info->addThingDescriptor(descriptor); info->addThingDescriptor(descriptor);
} }

View File

@ -57,14 +57,6 @@ ModbusTCPMaster::~ModbusTCPMaster()
{ {
if (m_reconnectTimer) { if (m_reconnectTimer) {
m_reconnectTimer->stop(); m_reconnectTimer->stop();
delete m_reconnectTimer;
m_reconnectTimer = nullptr;
}
if (m_modbusTcpClient) {
m_modbusTcpClient->disconnectDevice();
delete m_modbusTcpClient;
m_modbusTcpClient = nullptr;
} }
if (m_modbusTcpClient) { if (m_modbusTcpClient) {
@ -92,40 +84,27 @@ void ModbusTCPMaster::setHostAddress(const QHostAddress &hostAddress)
m_hostAddress = hostAddress; m_hostAddress = hostAddress;
} }
QHostAddress ModbusTCPMaster::hostAddress() const
{
return m_hostAddress;
}
uint ModbusTCPMaster::port() const
{
return m_port;
}
bool ModbusTCPMaster::setPort(uint port)
{
m_port = port;
return connectDevice();
}
bool ModbusTCPMaster::setHostAddress(const QHostAddress &hostAddress)
{
m_hostAddress = hostAddress;
return connectDevice();
}
bool ModbusTCPMaster::connectDevice() { bool ModbusTCPMaster::connectDevice() {
// TCP connection to target device // TCP connection to target device
qCDebug(dcModbusTCP()) << "Setting up TCP connecion" << QString("%1:%2").arg(m_hostAddress.toString()).arg(m_port);
if (!m_modbusTcpClient) if (!m_modbusTcpClient)
return false; return false;
m_modbusTcpClient->setConnectionParameter(QModbusDevice::NetworkPortParameter, m_port); // Only connect if we are in the unconnected state
m_modbusTcpClient->setConnectionParameter(QModbusDevice::NetworkAddressParameter, m_hostAddress.toString()); if (m_modbusTcpClient->state() == QModbusDevice::UnconnectedState) {
m_modbusTcpClient->setTimeout(m_timeout); qCDebug(dcModbusTCP()) << "Connecting modbus TCP client to" << QString("%1:%2").arg(m_hostAddress.toString()).arg(m_port);
m_modbusTcpClient->setNumberOfRetries(m_numberOfRetries); m_modbusTcpClient->setConnectionParameter(QModbusDevice::NetworkPortParameter, m_port);
m_modbusTcpClient->setConnectionParameter(QModbusDevice::NetworkAddressParameter, m_hostAddress.toString());
m_modbusTcpClient->setTimeout(m_timeout);
m_modbusTcpClient->setNumberOfRetries(m_numberOfRetries);
return m_modbusTcpClient->connectDevice();
} else if (m_modbusTcpClient->state() != QModbusDevice::ConnectedState) {
// Restart the timer in case of connecting not finished yet or closing
m_reconnectTimer->start();
} else {
qCWarning(dcModbusTCP()) << "Connect modbus TCP device" << QString("%1:%2").arg(m_hostAddress.toString()).arg(m_port) << "called, but the socket is currently in the" << m_modbusTcpClient->state();
}
return m_modbusTcpClient->connectDevice(); return false;
} }
void ModbusTCPMaster::disconnectDevice() void ModbusTCPMaster::disconnectDevice()
@ -133,9 +112,21 @@ void ModbusTCPMaster::disconnectDevice()
if (!m_modbusTcpClient) if (!m_modbusTcpClient)
return; return;
// Stop the reconnect timer since disconnect was explicitly called
m_reconnectTimer->stop();
m_modbusTcpClient->disconnectDevice(); m_modbusTcpClient->disconnectDevice();
} }
bool ModbusTCPMaster::reconnectDevice()
{
qCWarning(dcModbusTCP()) << "Reconnecting modbus TCP device" << QString("%1:%2").arg(m_hostAddress.toString()).arg(m_port);
if (!m_modbusTcpClient)
return false;
disconnectDevice();
return connectDevice();
}
bool ModbusTCPMaster::connected() const bool ModbusTCPMaster::connected() const
{ {
return m_connected; return m_connected;
@ -173,16 +164,6 @@ QModbusDevice::Error ModbusTCPMaster::error() const
return m_modbusTcpClient->error(); return m_modbusTcpClient->error();
} }
QString ModbusTCPMaster::errorString() const
{
return m_modbusTcpClient->errorString();
}
QModbusDevice::Error ModbusTCPMaster::error() const
{
return m_modbusTcpClient->error();
}
QUuid ModbusTCPMaster::readCoil(uint slaveAddress, uint registerAddress, uint size) QUuid ModbusTCPMaster::readCoil(uint slaveAddress, uint registerAddress, uint size)
{ {
if (!m_modbusTcpClient) { if (!m_modbusTcpClient) {
@ -499,6 +480,4 @@ void ModbusTCPMaster::onModbusStateChanged(QModbusDevice::State state)
} else if (state == QModbusDevice::UnconnectedState) { } else if (state == QModbusDevice::UnconnectedState) {
m_reconnectTimer->start(); m_reconnectTimer->start();
} }
emit connectionStateChanged(connected);
} }

View File

@ -59,7 +59,6 @@ public:
int timeout() const; int timeout() const;
void setTimeout(int timeout); void setTimeout(int timeout);
int timeout();
QString errorString() const; QString errorString() const;
QModbusDevice::Error error() const; QModbusDevice::Error error() const;
@ -105,9 +104,9 @@ signals:
void writeRequestExecuted(const QUuid &requestId, bool success); void writeRequestExecuted(const QUuid &requestId, bool success);
void writeRequestError(const QUuid &requestId, const QString &error); void writeRequestError(const QUuid &requestId, const QString &error);
void readRequestError(const QUuid &requestId, const QString &error);
void readRequestExecuted(const QUuid &requestId, bool success); void readRequestExecuted(const QUuid &requestId, bool success);
void readRequestError(const QUuid &requestId, const QString &error);
void receivedCoil(uint slaveAddress, uint modbusRegister, const QVector<quint16> &values); void receivedCoil(uint slaveAddress, uint modbusRegister, const QVector<quint16> &values);
void receivedDiscreteInput(uint slaveAddress, uint modbusRegister, const QVector<quint16> &values); void receivedDiscreteInput(uint slaveAddress, uint modbusRegister, const QVector<quint16> &values);

View File

@ -111,37 +111,43 @@ void IntegrationPluginModbusCommander::discoverThings(ThingDiscoveryInfo *info)
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (thingClassId == modbusTCPClientThingClassId) { } else if (thingClassId == modbusTCPClientThingClassId) {
if (!hardwareManager()->networkDeviceDiscovery()->available()) {
qCWarning(dcModbusCommander()) << "Failed to discover network devices. The network device discovery is not available.";
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("The discovery is not available."));
return;
}
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
ThingDescriptors descriptors; ThingDescriptors descriptors;
qCDebug(dcModbusCommander()) << "Discovery finished. Found" << discoveryReply->networkDevices().count() << "devices"; qCDebug(dcModbusCommander()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
foreach (const NetworkDevice &networkDevice, discoveryReply->networkDevices()) { foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
qCDebug(dcModbusCommander()) << networkDevice; qCDebug(dcModbusCommander()) << networkDeviceInfo;
QString title; QString title;
if (networkDevice.hostName().isEmpty()) { if (networkDeviceInfo.hostName().isEmpty()) {
title += networkDevice.address().toString(); title += networkDeviceInfo.address().toString();
} else { } else {
title += networkDevice.address().toString() + " (" + networkDevice.hostName() + ")"; title += networkDeviceInfo.address().toString() + " (" + networkDeviceInfo.hostName() + ")";
} }
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(modbusTCPClientThingClassId, title, description); ThingDescriptor descriptor(modbusTCPClientThingClassId, title, description);
// Check if we already have set up this device // Check if we already have set up this device
Things existingThings = myThings().filterByParam(modbusTCPClientThingIpAddressParamTypeId, networkDevice.address().toString()); Things existingThings = myThings().filterByParam(modbusTCPClientThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
if (existingThings.count() == 1) { if (existingThings.count() == 1) {
qCDebug(dcModbusCommander()) << "This thing already exists in the system." << existingThings.first() << networkDevice; qCDebug(dcModbusCommander()) << "This thing already exists in the system." << existingThings.first() << networkDeviceInfo;
descriptor.setThingId(existingThings.first()->id()); descriptor.setThingId(existingThings.first()->id());
} }
ParamList params; ParamList params;
params << Param(modbusTCPClientThingIpAddressParamTypeId, networkDevice.address().toString()); params << Param(modbusTCPClientThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
descriptor.setParams(params); descriptor.setParams(params);
info->addThingDescriptor(descriptor); info->addThingDescriptor(descriptor);
} }

View File

@ -101,37 +101,43 @@ void IntegrationPluginSunSpec::init()
void IntegrationPluginSunSpec::discoverThings(ThingDiscoveryInfo *info) void IntegrationPluginSunSpec::discoverThings(ThingDiscoveryInfo *info)
{ {
if (!hardwareManager()->networkDeviceDiscovery()->available()) {
qCWarning(dcSunSpec()) << "Failed to discover network devices. The network device discovery is not available.";
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("The discovery is not available."));
return;
}
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
ThingDescriptors descriptors; ThingDescriptors descriptors;
qCDebug(dcSunSpec()) << "Discovery finished. Found" << discoveryReply->networkDevices().count() << "devices"; qCDebug(dcSunSpec()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
foreach (const NetworkDevice &networkDevice, discoveryReply->networkDevices()) { foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
qCDebug(dcSunSpec()) << networkDevice; qCDebug(dcSunSpec()) << networkDeviceInfo;
QString title; QString title;
if (networkDevice.hostName().isEmpty()) { if (networkDeviceInfo.hostName().isEmpty()) {
title += networkDevice.address().toString(); title += networkDeviceInfo.address().toString();
} else { } else {
title += networkDevice.address().toString() + " (" + networkDevice.hostName() + ")"; title += networkDeviceInfo.address().toString() + " (" + networkDeviceInfo.hostName() + ")";
} }
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(sunspecConnectionThingClassId, title, description); ThingDescriptor descriptor(sunspecConnectionThingClassId, title, description);
// Check if we already have set up this device // Check if we already have set up this device
Things existingThings = myThings().filterByParam(sunspecConnectionThingIpAddressParamTypeId, networkDevice.address().toString()); Things existingThings = myThings().filterByParam(sunspecConnectionThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
if (existingThings.count() == 1) { if (existingThings.count() == 1) {
qCDebug(dcSunSpec()) << "This thing already exists in the system." << existingThings.first() << networkDevice; qCDebug(dcSunSpec()) << "This thing already exists in the system." << existingThings.first() << networkDeviceInfo;
descriptor.setThingId(existingThings.first()->id()); descriptor.setThingId(existingThings.first()->id());
} }
ParamList params; ParamList params;
params << Param(sunspecConnectionThingIpAddressParamTypeId, networkDevice.address().toString()); params << Param(sunspecConnectionThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
descriptor.setParams(params); descriptor.setParams(params);
info->addThingDescriptor(descriptor); info->addThingDescriptor(descriptor);
} }

View File

@ -81,43 +81,49 @@ void IntegrationPluginWallbe::init()
void IntegrationPluginWallbe::discoverThings(ThingDiscoveryInfo *info) void IntegrationPluginWallbe::discoverThings(ThingDiscoveryInfo *info)
{ {
if (info->thingClassId() == wallbeEcoThingClassId){ if (info->thingClassId() == wallbeEcoThingClassId) {
if (!hardwareManager()->networkDeviceDiscovery()->available()) {
qCWarning(dcWallbe()) << "Failed to discover network devices. The network device discovery is not available.";
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("The discovery is not available."));
return;
}
qCDebug(dcWallbe()) << "Start Wallbe eco discovery"; qCDebug(dcWallbe()) << "Start Wallbe eco discovery";
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
ThingDescriptors descriptors; ThingDescriptors descriptors;
qCDebug(dcWallbe()) << "Discovery finished. Found" << discoveryReply->networkDevices().count() << "devices"; qCDebug(dcWallbe()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
foreach (const NetworkDevice &networkDevice, discoveryReply->networkDevices()) { foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
qCDebug(dcWallbe()) << networkDevice; qCDebug(dcWallbe()) << networkDeviceInfo;
if (!networkDevice.macAddressManufacturer().contains("Phoenix", Qt::CaseSensitivity::CaseInsensitive)) if (!networkDeviceInfo.macAddressManufacturer().contains("Phoenix", Qt::CaseSensitivity::CaseInsensitive))
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 += networkDevice.address().toString() + " (" + networkDevice.hostName() + ")"; title += networkDeviceInfo.address().toString() + " (" + networkDeviceInfo.hostName() + ")";
} }
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(wallbeEcoThingClassId, title, description); ThingDescriptor descriptor(wallbeEcoThingClassId, title, description);
// Check if we already have set up this device // Check if we already have set up this device
Things existingThings = myThings().filterByParam(wallbeEcoThingIpParamTypeId, networkDevice.address().toString()); Things existingThings = myThings().filterByParam(wallbeEcoThingIpParamTypeId, networkDeviceInfo.address().toString());
if (existingThings.count() == 1) { if (existingThings.count() == 1) {
qCDebug(dcWallbe()) << "This thing already exists in the system." << existingThings.first() << networkDevice; qCDebug(dcWallbe()) << "This thing already exists in the system." << existingThings.first() << networkDeviceInfo;
descriptor.setThingId(existingThings.first()->id()); descriptor.setThingId(existingThings.first()->id());
} }
ParamList params; ParamList params;
params << Param(wallbeEcoThingIpParamTypeId, networkDevice.address().toString()); params << Param(wallbeEcoThingIpParamTypeId, networkDeviceInfo.address().toString());
params << Param(wallbeEcoThingMacParamTypeId, networkDevice.macAddress()); params << Param(wallbeEcoThingMacParamTypeId, networkDeviceInfo.macAddress());
descriptor.setParams(params); descriptor.setParams(params);
info->addThingDescriptor(descriptor); info->addThingDescriptor(descriptor);
} }

View File

@ -82,42 +82,48 @@ void IntegrationPluginWebasto::init()
void IntegrationPluginWebasto::discoverThings(ThingDiscoveryInfo *info) void IntegrationPluginWebasto::discoverThings(ThingDiscoveryInfo *info)
{ {
if (info->thingClassId() == liveWallboxThingClassId) { if (info->thingClassId() == liveWallboxThingClassId) {
if (!hardwareManager()->networkDeviceDiscovery()->available()) {
qCWarning(dcWebasto()) << "Failed to discover network devices. The network device discovery is not available.";
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("The discovery is not available."));
return;
}
qCDebug(dcWebasto()) << "Discover things"; qCDebug(dcWebasto()) << "Discover things";
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
ThingDescriptors descriptors; ThingDescriptors descriptors;
qCDebug(dcWebasto()) << "Discovery finished. Found" << discoveryReply->networkDevices().count() << "devices"; qCDebug(dcWebasto()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
foreach (const NetworkDevice &networkDevice, discoveryReply->networkDevices()) { foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
qCDebug(dcWebasto()) << networkDevice; qCDebug(dcWebasto()) << networkDeviceInfo;
if (!networkDevice.hostName().contains("webasto", Qt::CaseSensitivity::CaseInsensitive)) if (!networkDeviceInfo.hostName().contains("webasto", Qt::CaseSensitivity::CaseInsensitive))
continue; continue;
QString title = "Wallbox "; QString title = "Wallbox ";
if (networkDevice.hostName().isEmpty()) { if (networkDeviceInfo.hostName().isEmpty()) {
title += networkDevice.address().toString(); title += networkDeviceInfo.address().toString();
} else { } else {
title += networkDevice.address().toString() + " (" + networkDevice.hostName() + ")"; title += networkDeviceInfo.address().toString() + " (" + networkDeviceInfo.hostName() + ")";
} }
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(liveWallboxThingClassId, title, description); ThingDescriptor descriptor(liveWallboxThingClassId, title, description);
// Check if we already have set up this device // Check if we already have set up this device
Things existingThings = myThings().filterByParam(liveWallboxThingIpAddressParamTypeId, networkDevice.address().toString()); Things existingThings = myThings().filterByParam(liveWallboxThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
if (existingThings.count() == 1) { if (existingThings.count() == 1) {
qCDebug(dcWebasto()) << "This thing already exists in the system." << existingThings.first() << networkDevice; qCDebug(dcWebasto()) << "This thing already exists in the system." << existingThings.first() << networkDeviceInfo;
descriptor.setThingId(existingThings.first()->id()); descriptor.setThingId(existingThings.first()->id());
} }
ParamList params; ParamList params;
params << Param(liveWallboxThingIpAddressParamTypeId, networkDevice.address().toString()); params << Param(liveWallboxThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
params << Param(liveWallboxThingMacAddressParamTypeId, networkDevice.macAddress()); params << Param(liveWallboxThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
descriptor.setParams(params); descriptor.setParams(params);
info->addThingDescriptor(descriptor); info->addThingDescriptor(descriptor);
} }