Clean up discovery and check if we need a grace period after discovery has finished
parent
9d3bb72849
commit
462535e359
|
|
@ -164,7 +164,7 @@ void IntegrationPluginKostal::setupThing(ThingSetupInfo *info)
|
||||||
thing->setStateValue(kostalMeterCurrentPowerStateTypeId, powerMeterTotalActivePower);
|
thing->setStateValue(kostalMeterCurrentPowerStateTypeId, powerMeterTotalActivePower);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: set toal energy consumed/produced
|
// TODO: set total energy consumed/produced
|
||||||
|
|
||||||
connect(kostalConnection, &KostalModbusTcpConnection::powerMeterTotalActivePowerChanged, this, [thing](float powerMeterTotalActivePower){
|
connect(kostalConnection, &KostalModbusTcpConnection::powerMeterTotalActivePowerChanged, this, [thing](float powerMeterTotalActivePower){
|
||||||
thing->setStateValue(kostalMeterCurrentPowerStateTypeId, powerMeterTotalActivePower);
|
thing->setStateValue(kostalMeterCurrentPowerStateTypeId, powerMeterTotalActivePower);
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,7 @@ KostalDiscovery::KostalDiscovery(NetworkDeviceDiscovery *networkDeviceDiscovery,
|
||||||
m_port{port},
|
m_port{port},
|
||||||
m_modbusAddress{modbusAddress}
|
m_modbusAddress{modbusAddress}
|
||||||
{
|
{
|
||||||
m_gracePeriodTimer.setSingleShot(true);
|
|
||||||
m_gracePeriodTimer.setInterval(3000);
|
|
||||||
connect(&m_gracePeriodTimer, &QTimer::timeout, this, [this](){
|
|
||||||
qCDebug(dcKostal()) << "Discovery: SunnyWebBox: Grace period timer triggered.";
|
|
||||||
finishDiscovery();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KostalDiscovery::startDiscovery()
|
void KostalDiscovery::startDiscovery()
|
||||||
|
|
@ -51,9 +46,9 @@ void KostalDiscovery::startDiscovery()
|
||||||
NetworkDeviceDiscoveryReply *discoveryReply = m_networkDeviceDiscovery->discover();
|
NetworkDeviceDiscoveryReply *discoveryReply = m_networkDeviceDiscovery->discover();
|
||||||
|
|
||||||
// Check any already discovered infos..
|
// Check any already discovered infos..
|
||||||
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
|
// FIXME: this is not required any more once each discovery request receives it's own object getting the added signal for every info
|
||||||
|
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos())
|
||||||
checkNetworkDevice(networkDeviceInfo);
|
checkNetworkDevice(networkDeviceInfo);
|
||||||
}
|
|
||||||
|
|
||||||
// Imedialty check any new device gets discovered
|
// Imedialty check any new device gets discovered
|
||||||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::networkDeviceInfoAdded, this, &KostalDiscovery::checkNetworkDevice);
|
connect(discoveryReply, &NetworkDeviceDiscoveryReply::networkDeviceInfoAdded, this, &KostalDiscovery::checkNetworkDevice);
|
||||||
|
|
@ -62,15 +57,25 @@ void KostalDiscovery::startDiscovery()
|
||||||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
||||||
qCDebug(dcKostal()) << "Discovery: Network discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "network devices";
|
qCDebug(dcKostal()) << "Discovery: Network discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "network devices";
|
||||||
m_networkDeviceInfos = discoveryReply->networkDeviceInfos();
|
m_networkDeviceInfos = discoveryReply->networkDeviceInfos();
|
||||||
qCDebug(dcKostal()) << "Discovery: Network discovery finished. Start finishing discovery...";
|
|
||||||
// Send a report request to nework device info not sent already...
|
// Send a report request to nework device info not sent already...
|
||||||
|
bool networkdevicesLeft = false;
|
||||||
foreach (const NetworkDeviceInfo &networkDeviceInfo, m_networkDeviceInfos) {
|
foreach (const NetworkDeviceInfo &networkDeviceInfo, m_networkDeviceInfos) {
|
||||||
if (!m_verifiedNetworkDeviceInfos.contains(networkDeviceInfo)) {
|
if (!m_verifiedNetworkDeviceInfos.contains(networkDeviceInfo)) {
|
||||||
|
networkdevicesLeft = true;
|
||||||
checkNetworkDevice(networkDeviceInfo);
|
checkNetworkDevice(networkDeviceInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_gracePeriodTimer.start();
|
if (networkdevicesLeft) {
|
||||||
|
// Give the last connections added right before the network discovery finished a chance to check the device...
|
||||||
|
QTimer::singleShot(3000, this, [this](){
|
||||||
|
qCDebug(dcKostal()) << "Discovery: Grace period timer triggered.";
|
||||||
|
finishDiscovery();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
finishDiscovery();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,6 +112,7 @@ void KostalDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDeviceI
|
||||||
cleanupConnection(connection);
|
cleanupConnection(connection);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
KostalDiscoveryResult result;
|
KostalDiscoveryResult result;
|
||||||
result.productName = connection->productName();
|
result.productName = connection->productName();
|
||||||
result.manufacturerName = connection->inverterManufacturer();
|
result.manufacturerName = connection->inverterManufacturer();
|
||||||
|
|
@ -129,12 +135,11 @@ void KostalDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDeviceI
|
||||||
cleanupConnection(connection);
|
cleanupConnection(connection);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Initializing...
|
||||||
if (!connection->initialize()) {
|
if (!connection->initialize()) {
|
||||||
qCDebug(dcKostal()) << "Discovery: Unable to initialize connection on" << networkDeviceInfo.address().toString() << "Continue...";;
|
qCDebug(dcKostal()) << "Discovery: Unable to initialize connection on" << networkDeviceInfo.address().toString() << "Continue...";;
|
||||||
cleanupConnection(connection);
|
cleanupConnection(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializing...
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// If we get any error...skip this host...
|
// If we get any error...skip this host...
|
||||||
|
|
@ -170,9 +175,7 @@ void KostalDiscovery::finishDiscovery()
|
||||||
foreach (KostalModbusTcpConnection *connection, m_connections)
|
foreach (KostalModbusTcpConnection *connection, m_connections)
|
||||||
cleanupConnection(connection);
|
cleanupConnection(connection);
|
||||||
|
|
||||||
qCInfo(dcKostal()) << "Discovery: Finished the discovery process. Found" << m_discoveryResults.count()
|
qCInfo(dcKostal()) << "Discovery: Finished the discovery process. Found" << m_discoveryResults.count() << "Kostal Inverters in" << QTime::fromMSecsSinceStartOfDay(durationMilliSeconds).toString("mm:ss.zzz");
|
||||||
<< "Kostal Inverters in" << QTime::fromMSecsSinceStartOfDay(durationMilliSeconds).toString("mm:ss.zzz");
|
|
||||||
m_gracePeriodTimer.stop();
|
|
||||||
|
|
||||||
emit discoveryFinished();
|
emit discoveryFinished();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue