fixed udp init, polished debug output, fixed missing debian dependency

This commit is contained in:
Boernsman 2021-01-14 22:02:15 +01:00
parent 1c2c04f187
commit 238efba31c
5 changed files with 26 additions and 13 deletions

1
debian/control vendored
View File

@ -973,6 +973,7 @@ Depends: ${shlibs:Depends},
${misc:Depends},
nymea-plugins-translations,
nmap,
arping,
Replaces: guh-plugin-keba
Description: nymea.io plugin for keba
The nymea daemon is a plugin based IoT (Internet of Things) server. The

View File

@ -109,7 +109,7 @@ void Discovery::discoveryFinished(int exitCode, QProcess::ExitStatus exitStatus)
QXmlStreamReader reader(data);
int foundHosts = 0;
qCDebug(dcKebaKeContact()) << "nmap finished network discovery:";
while (!reader.atEnd() && !reader.hasError()) {
QXmlStreamReader::TokenType token = reader.readNext();
if(token == QXmlStreamReader::StartDocument)
@ -143,7 +143,7 @@ void Discovery::discoveryFinished(int exitCode, QProcess::ExitStatus exitStatus)
if (isUp) {
foundHosts++;
qCDebug(dcKebaKeContact()) << "Have host:" << address;
qCDebug(dcKebaKeContact()) << " - host:" << address;
Host *host = new Host();
host->setAddress(address);
@ -264,7 +264,7 @@ void Discovery::finishDiscovery()
qDeleteAll(m_scanResults);
m_scanResults.clear();
qCDebug(dcKebaKeContact()) << "Emitting device discovered for" << hosts.count() << "devices";
qCDebug(dcKebaKeContact()) << "Found" << hosts.count() << "network devices";
m_timeoutTimer.stop();
emit finished(hosts);
}

View File

@ -85,11 +85,13 @@ void IntegrationPluginKeba::discoverThings(ThingDiscoveryInfo *info)
if (!host.hostName().contains("keba", Qt::CaseSensitivity::CaseInsensitive))
continue;
qCDebug(dcKebaKeContact()) << " - Keba Wallbox" << host.address() << host.macAddress();
ThingDescriptor descriptor(wallboxThingClassId, "Wallbox", host.address() + " (" + host.macAddress() + ")");
// Rediscovery
foreach (Thing *existingThing, myThings()) {
if (existingThing->paramValue(wallboxThingMacAddressParamTypeId).toString() == host.macAddress()) {
qCDebug(dcKebaKeContact()) << " - Device is already added";
descriptor.setThingId(existingThing->id());
break;
}
@ -118,7 +120,7 @@ void IntegrationPluginKeba::setupThing(ThingSetupInfo *info)
if(!m_udpSocket){
m_udpSocket = new QUdpSocket(this);
if (!m_udpSocket->bind(QHostAddress::AnyIPv4, 7090, QAbstractSocket::ShareAddress)) {
if (!m_udpSocket->bind(QHostAddress::AnyIPv4, 7090, QAbstractSocket::DefaultForPlatform)) {
qCWarning(dcKebaKeContact()) << "Cannot bind to port" << 7090;
return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Error opening network port."));
}
@ -137,9 +139,8 @@ void IntegrationPluginKeba::setupThing(ThingSetupInfo *info)
return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Error opening network port."));
}
m_kebaDevices.insert(thing->id(), keba);
keba->getReport1();
connect(keba, &KeContact::reportOneReceived, info, [info] (const KeContact::ReportOne &report) {
connect(keba, &KeContact::reportOneReceived, info, [info, this, keba] (const KeContact::ReportOne &report) {
Thing *thing = info->thing();
qCDebug(dcKebaKeContact()) << "Report one received for" << thing->name();
@ -152,12 +153,13 @@ void IntegrationPluginKeba::setupThing(ThingSetupInfo *info)
thing->setStateValue(wallboxFirmwareStateTypeId, report.firmware);
thing->setStateValue(wallboxModelStateTypeId, report.product);
thing->setStateValue(wallboxUptimeStateTypeId, report.seconds);
m_kebaDevices.insert(thing->id(), keba);
info->finish(Thing::ThingErrorNoError);
});
connect(info, &ThingSetupInfo::aborted, keba, &KeContact::deleteLater);
connect(keba, &KeContact::destroyed, this, [thing, keba, this]{
connect(keba, &KeContact::destroyed, this, [thing, this]{
m_kebaDevices.remove(thing->id());
keba->deleteLater();
});
} else {
qCWarning(dcKebaKeContact()) << "setupDevice, unhandled device class" << thing->thingClass();
@ -224,6 +226,11 @@ void IntegrationPluginKeba::thingRemoved(Thing *thing)
}
if (myThings().empty()) {
qCDebug(dcKebaKeContact()) << "Closing UDP Ports";
m_udpSocket->close();
m_udpSocket->deleteLater();
m_udpSocket = nullptr;
qCDebug(dcKebaKeContact()) << "Stopping plugin timers";
hardwareManager()->pluginTimerManager()->unregisterTimer(m_reconnectTimer);
m_reconnectTimer = nullptr;

View File

@ -142,7 +142,7 @@
"displayNameAction": "Set maximal charging current",
"type": "uint",
"unit": "MilliAmpere",
"defaultValue": 6000,
"defaultValue": 6,
"minValue": 6000,
"maxValue": 63000,
"writable": true
@ -158,6 +158,15 @@
"minValue": 0,
"maxValue": 100
},
{
"id": "08bb9872-8d63-49b0-a8ce-7a449341f13b",
"name": "maxPossibleChargingCurrent",
"displayName": "Maximum possible charging current",
"displayNameEvent": "Maximum possible charging current changed",
"type": "double",
"unit": "Ampere",
"defaultValue": 6.00
},
{
"id": "4a2d75d8-a3a0-4b40-9ca7-e8b6f11d0ef9",
"name": "voltagePhase1",

View File

@ -58,10 +58,6 @@ bool KeContact::init(){
qCDebug(dcKebaKeContact()) << "Initializing Keba connection";
if(m_udpSocket){
connect(m_udpSocket, &QUdpSocket::readyRead, this, &KeContact::readPendingDatagrams);
if (!m_udpSocket->bind(QHostAddress::AnyIPv4, m_port, QAbstractSocket::ShareAddress)) {
qCWarning(dcKebaKeContact()) << "Cannot bind to port" << m_port;
return false;
}
} else {
qCWarning(dcKebaKeContact()) << "UDP socket not valid";
return false;