From 238efba31c5a1ce46123a9fe65a038a204365a49 Mon Sep 17 00:00:00 2001 From: Boernsman Date: Thu, 14 Jan 2021 22:02:15 +0100 Subject: [PATCH] fixed udp init, polished debug output, fixed missing debian dependency --- debian/control | 1 + keba/discovery.cpp | 6 +++--- keba/integrationpluginkeba.cpp | 17 ++++++++++++----- keba/integrationpluginkeba.json | 11 ++++++++++- keba/kecontact.cpp | 4 ---- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/debian/control b/debian/control index a3c0e990..a782dbe0 100644 --- a/debian/control +++ b/debian/control @@ -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 diff --git a/keba/discovery.cpp b/keba/discovery.cpp index 070f64e1..a41192c4 100644 --- a/keba/discovery.cpp +++ b/keba/discovery.cpp @@ -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); } diff --git a/keba/integrationpluginkeba.cpp b/keba/integrationpluginkeba.cpp index 2b3ee8e0..2a022422 100644 --- a/keba/integrationpluginkeba.cpp +++ b/keba/integrationpluginkeba.cpp @@ -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; diff --git a/keba/integrationpluginkeba.json b/keba/integrationpluginkeba.json index c21b1ee2..d87bc29d 100644 --- a/keba/integrationpluginkeba.json +++ b/keba/integrationpluginkeba.json @@ -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", diff --git a/keba/kecontact.cpp b/keba/kecontact.cpp index 286d087b..9e681aab 100644 --- a/keba/kecontact.cpp +++ b/keba/kecontact.cpp @@ -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;