diff --git a/debian/control b/debian/control index 6efef76e..4537c2ea 100644 --- a/debian/control +++ b/debian/control @@ -870,6 +870,7 @@ Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, nymea-plugins-translations, + nmap, 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 9d2b98b7..070f64e1 100644 --- a/keba/discovery.cpp +++ b/keba/discovery.cpp @@ -62,7 +62,6 @@ void Discovery::discoverHosts(int timeout) qCDebug(dcKebaKeContact()) << "Scanning network:" << "nmap" << arguments.join(" "); discoveryProcess->start(QStringLiteral("nmap"), arguments); } - } void Discovery::abort() diff --git a/keba/discovery.h b/keba/discovery.h index 59914cf1..02284c38 100644 --- a/keba/discovery.h +++ b/keba/discovery.h @@ -46,12 +46,10 @@ public: void discoverHosts(int timeout); void abort(); - bool isRunning() const; - signals: - void finished(QList hosts); + void finished(const QList &hosts); private: QStringList getDefaultTargets(); @@ -71,7 +69,6 @@ private: QHash m_pendingArpLookups; QHash m_pendingNameLookups; QList m_scanResults; - }; #endif // DISCOVERY_H diff --git a/keba/integrationpluginkeba.cpp b/keba/integrationpluginkeba.cpp index 9a8d2188..ddbcf7db 100644 --- a/keba/integrationpluginkeba.cpp +++ b/keba/integrationpluginkeba.cpp @@ -28,13 +28,12 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "integrationpluginkeba.h" +#include "devicepluginkeba.h" +#include "plugininfo.h" #include #include #include -#include -#include "plugininfo.h" #include IntegrationPluginKeba::IntegrationPluginKeba() @@ -42,27 +41,19 @@ IntegrationPluginKeba::IntegrationPluginKeba() } -void DevicePluginKeba::init() -{ - -} - void DevicePluginKeba::discoverDevices(DeviceDiscoveryInfo *info) { if (info->deviceClassId() == wallboxDeviceClassId) { - Discovery *discovery = new Discovery(this); + Discovery *discovery = new Discovery(info); discovery->discoverHosts(25); - // clean up discovery object when this discovery info is deleted - connect(info, &DeviceDiscoveryInfo::destroyed, discovery, &Discovery::deleteLater); - connect(discovery, &Discovery::finished, info, [this, info](const QList &hosts) { qCDebug(dcKebaKeContact()) << "Discovery finished. Found" << hosts.count() << "devices"; foreach (const Host &host, hosts) { if (!host.hostName().contains("keba", Qt::CaseSensitivity::CaseInsensitive)) continue; - DeviceDescriptor descriptor(wallboxDeviceClassId, host.hostName().isEmpty() ? host.address() : host.hostName(), host.address() + " (" + host.macAddress() + ")"); + DeviceDescriptor descriptor(wallboxDeviceClassId, "Wallbox", host.address() + " (" + host.macAddress() + ")"); foreach (Device *existingDevice, myDevices()) { if (existingDevice->paramValue(wallboxDeviceMacAddressParamTypeId).toString() == host.macAddress()) { @@ -79,6 +70,7 @@ void DevicePluginKeba::discoverDevices(DeviceDiscoveryInfo *info) info->finish(Device::DeviceErrorNoError); }); } else { + qCWarning(dcKebaKeContact()) << "Discover device, unhandled device class" << info->deviceClassId(); info->finish(Device::DeviceErrorDeviceClassNotFound); } } @@ -115,6 +107,7 @@ void IntegrationPluginKeba::setupThing(ThingSetupInfo *info) keba->deleteLater(); }); } else { + qCWarning(dcKebaKeContact()) << "setupDevice, unhandled device class" << device->deviceClass(); info->finish(Device::DeviceErrorDeviceClassNotFound); } } @@ -138,13 +131,8 @@ void IntegrationPluginKeba::postSetupThing(Thing *thing) void DevicePluginKeba::deviceRemoved(Device *device) { if (device->deviceClassId() == wallboxDeviceClassId) { - m_kebaDevices.remove(device->id()); - } - - if(m_kebaDevices.isEmpty()){ - m_kebaSocket->close(); - m_kebaSocket->deleteLater(); - qCDebug(dcKebaKeContact()) << "clear socket"; + KeContact *keba = m_kebaDevices.take(device->id()); + keba->deleteLater(); } if (myDevices().empty()) { @@ -162,6 +150,51 @@ void IntegrationPluginKeba::updateData() } } +void DevicePluginKeba::setDeviceState(Device *device, KeContact::State state) +{ + switch (state) { + case KeContact::StateStarting: + device->setStateValue(wallboxActivityStateTypeId, "Starting"); + break; + case KeContact::StateNotReady: + device->setStateValue(wallboxActivityStateTypeId, "Not ready for charging"); + break; + case KeContact::StateReady: + device->setStateValue(wallboxActivityStateTypeId, "Ready for charging"); + break; + case KeContact::StateCharging: + device->setStateValue(wallboxActivityStateTypeId, "Charging"); + break; + case KeContact::StateError: + device->setStateValue(wallboxActivityStateTypeId, "Error"); + break; + case KeContact::StateAuthorizationRejected: + device->setStateValue(wallboxActivityStateTypeId, "Authorization rejected"); + break; + } +} + +void DevicePluginKeba::setDevicePlugState(Device *device, KeContact::PlugState plugState) +{ + switch (plugState) { + case KeContact::PlugStateUnplugged: + device->setStateValue(wallboxPlugStateStateTypeId, "Unplugged"); + break; + case KeContact::PlugStatePluggedOnChargingStation: + device->setStateValue(wallboxPlugStateStateTypeId, "Plugged in charging station"); + break; + case KeContact::PlugStatePluggedOnChargingStationAndPluggedOnEV: + device->setStateValue(wallboxPlugStateStateTypeId, "Plugged in on EV"); + break; + case KeContact::PlugStatePluggedOnChargingStationAndPlugLocked: + device->setStateValue(wallboxPlugStateStateTypeId, "Plugged in and locked"); + break; + case KeContact::PlugStatePluggedOnChargingStationAndPlugLockedAndPluggedOnEV: + device->setStateValue(wallboxPlugStateStateTypeId, "Plugged in on EV and locked"); + break; + } +} + void DevicePluginKeba::onConnectionChanged(bool status) { KeContact *keba = static_cast(sender()); @@ -217,44 +250,8 @@ void DevicePluginKeba::onReportTwoReceived(const KeContact::ReportTwo &reportTwo device->setStateValue(wallboxPowerStateTypeId, reportTwo.enableUser); device->setStateValue(wallboxMaxChargingCurrentPercentStateTypeId, reportTwo.MaxCurrentPercentage); - switch (reportTwo.state) { - case KeContact::StateStarting: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Starting")); - break; - case KeContact::StateNotReady: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Not ready for charging")); - break; - case KeContact::StateReady: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Ready for charging")); - break; - case KeContact::StateCharging: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Charging")); - break; - case KeContact::StateError: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Erro")); - break; - case KeContact::StateAuthorizationRejected: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Authorization rejected")); - break; - } - - switch (reportTwo.plugState) { - case KeContact::PlugStateUnplugged: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Unplugged")); - break; - case KeContact::PlugStatePluggedOnChargingStation: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Plugged in charging station")); - break; - case KeContact::PlugStatePluggedOnChargingStationAndPluggedOnEV: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Plugged in on EV")); - break; - case KeContact::PlugStatePluggedOnChargingStationAndPlugLocked: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Plugged in and locked")); - break; - case KeContact::PlugStatePluggedOnChargingStationAndPlugLockedAndPluggedOnEV: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Plugged in on EV and locked")); - break; - } + setDeviceState(device, reportTwo.state); + setDevicePlugState(device, reportTwo.plugState); } void DevicePluginKeba::onReportThreeReceived(const KeContact::ReportThree &reportThree) @@ -284,23 +281,7 @@ void DevicePluginKeba::onBroadcastReceived(KeContact::BroadcastType type, const switch (type) { case KeContact::BroadcastTypePlug: - switch (KeContact::PlugState(content.toInt())) { - case KeContact::PlugStateUnplugged: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Unplugged")); - break; - case KeContact::PlugStatePluggedOnChargingStation: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Plugged in charging station")); - break; - case KeContact::PlugStatePluggedOnChargingStationAndPluggedOnEV: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Plugged in on EV")); - break; - case KeContact::PlugStatePluggedOnChargingStationAndPlugLocked: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Plugged in and locked")); - break; - case KeContact::PlugStatePluggedOnChargingStationAndPlugLockedAndPluggedOnEV: - device->setStateValue(wallboxPlugStateStateTypeId, QT_TR_NOOP("Plugged in on EV and locked")); - break; - } + setDevicePlugState(device, KeContact::PlugState(content.toInt())); break; case KeContact::BroadcastTypeInput: break; @@ -308,26 +289,7 @@ void DevicePluginKeba::onBroadcastReceived(KeContact::BroadcastType type, const device->setStateValue(wallboxEPStateTypeId, content.toInt()); break; case KeContact::BroadcastTypeState: - switch (KeContact::State(content.toInt())) { - case KeContact::StateStarting: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Starting")); - break; - case KeContact::StateNotReady: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Not ready for charging")); - break; - case KeContact::StateReady: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Ready for charging")); - break; - case KeContact::StateCharging: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Charging")); - break; - case KeContact::StateError: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Erro")); - break; - case KeContact::StateAuthorizationRejected: - device->setStateValue(wallboxActivityStateTypeId, QT_TR_NOOP("Authorization rejected")); - break; - } + setDeviceState(device, KeContact::State(content.toInt())); break; case KeContact::BroadcastTypeMaxCurr: device->setStateValue(wallboxMaxChargingCurrentStateTypeId, content.toInt()); diff --git a/keba/integrationpluginkeba.h b/keba/integrationpluginkeba.h index a6907e6c..b8df1b7c 100644 --- a/keba/integrationpluginkeba.h +++ b/keba/integrationpluginkeba.h @@ -67,7 +67,9 @@ private: QHash m_kebaDevices; QHash m_asyncSetup; QHash m_asyncActions; - QUdpSocket *m_kebaSocket; + + void setDeviceState(Device *device, KeContact::State state); + void setDevicePlugState(Device *device, KeContact::PlugState plugState); private slots: void onConnectionChanged(bool status); diff --git a/keba/kecontact.cpp b/keba/kecontact.cpp index f7d369c8..3477ec72 100644 --- a/keba/kecontact.cpp +++ b/keba/kecontact.cpp @@ -51,11 +51,6 @@ KeContact::KeContact(QHostAddress address, QObject *parent) : KeContact::~KeContact() { qCDebug(dcKebaKeContact()) << "Deleting KeContact connection for address" << m_address; - - m_requestTimeoutTimer->deleteLater(); - m_requestTimeoutTimer->stop(); - m_udpSocket->close(); - m_udpSocket->deleteLater(); } bool KeContact::init(){ diff --git a/keba/translations/9142b09f-30a9-43d0-9ede-2f8debe075ac-en_US.ts b/keba/translations/9142b09f-30a9-43d0-9ede-2f8debe075ac-en_US.ts index 1e6ec97b..8f23c4f5 100644 --- a/keba/translations/9142b09f-30a9-43d0-9ede-2f8debe075ac-en_US.ts +++ b/keba/translations/9142b09f-30a9-43d0-9ede-2f8debe075ac-en_US.ts @@ -4,71 +4,16 @@ IntegrationPluginKeba - + Error opening network port. - - - Starting - - - - - Not ready for charging - - - - - Ready for charging - - - - - Charging - - - - - Erro - - - - - Authorization rejected - - - - - Unplugged - - - - - Plugged in charging station - - - - - Plugged in on EV - - - - - Plugged in and locked - - - - - Plugged in on EV and locked - - KebaKeContact - - + + Keba KeContact The name of the DeviceClass ({900dacec-cae7-4a37-95ba-501846368ea2}) ---------- @@ -76,20 +21,20 @@ The name of the plugin KebaKeContact ({9142b09f-30a9-43d0-9ede-2f8debe075ac}) - + Keba The name of the vendor ({f7cda40b-829a-4675-abaa-485697430f5f}) - + Activity changed The name of the EventType ({539e5602-6dd9-465d-9705-3bb59bcf8982}) of DeviceClass wallbox - - + + Activity The name of the ParamType (DeviceClass: wallbox, EventType: activity, ID: {539e5602-6dd9-465d-9705-3bb59bcf8982}) ---------- @@ -97,8 +42,8 @@ The name of the StateType ({539e5602-6dd9-465d-9705-3bb59bcf8982}) of DeviceClas - - + + Connected The name of the ParamType (DeviceClass: wallbox, EventType: connected, ID: {ce813458-d7d8-4f40-9648-dba4c41e92f0}) ---------- @@ -106,14 +51,14 @@ The name of the StateType ({ce813458-d7d8-4f40-9648-dba4c41e92f0}) of DeviceClas - + Connection changed The name of the EventType ({ce813458-d7d8-4f40-9648-dba4c41e92f0}) of DeviceClass wallbox - - + + Current Phase 1 The name of the ParamType (DeviceClass: wallbox, EventType: I1, ID: {31ec17b0-11e3-4332-92b0-fea821cf024f}) ---------- @@ -121,8 +66,8 @@ The name of the StateType ({31ec17b0-11e3-4332-92b0-fea821cf024f}) of DeviceClas - - + + Current Phase 2 The name of the ParamType (DeviceClass: wallbox, EventType: I2, ID: {cdc7e10a-0d0a-4e93-ad2c-d34ffca45c97}) ---------- @@ -130,8 +75,8 @@ The name of the StateType ({cdc7e10a-0d0a-4e93-ad2c-d34ffca45c97}) of DeviceClas - - + + Current Phase 3 The name of the ParamType (DeviceClass: wallbox, EventType: I3, ID: {da838dc8-85f0-4e55-b4b5-cb93a43b373d}) ---------- @@ -139,51 +84,51 @@ The name of the StateType ({da838dc8-85f0-4e55-b4b5-cb93a43b373d}) of DeviceClas - + Current phase 1 changed The name of the EventType ({31ec17b0-11e3-4332-92b0-fea821cf024f}) of DeviceClass wallbox - + Current phase 2 changed The name of the EventType ({cdc7e10a-0d0a-4e93-ad2c-d34ffca45c97}) of DeviceClass wallbox - + Current phase 3 changed The name of the EventType ({da838dc8-85f0-4e55-b4b5-cb93a43b373d}) of DeviceClass wallbox - + Display The name of the ActionType ({158b1a8f-fde9-4191-bf42-4ece5fe582e6}) of DeviceClass wallbox - + Display message The name of the ParamType (DeviceClass: wallbox, ActionType: display, ID: {4e69a761-f4f1-42d0-83db-380894a86ebc}) - + IPv4 Address The name of the ParamType (DeviceClass: wallbox, Type: device, ID: {730cd3d3-5f0e-4028-a8c2-ced7574f13f3}) - + MAC Address The name of the ParamType (DeviceClass: wallbox, Type: device, ID: {c2df921d-ff8b-411c-9b1d-04a437d7dfa6}) - - - + + + Maximal charging current The name of the ParamType (DeviceClass: wallbox, ActionType: maxChargingCurrent, ID: {593656f0-babf-4308-8767-68f34e10fb15}) ---------- @@ -193,14 +138,14 @@ The name of the StateType ({593656f0-babf-4308-8767-68f34e10fb15}) of ThingClass - + Maximal charging current changed The name of the EventType ({593656f0-babf-4308-8767-68f34e10fb15}) of DeviceClass wallbox - - + + Maximal charging current in Percent The name of the ParamType (DeviceClass: wallbox, EventType: maxChargingCurrentPercent, ID: {3c7b83a0-0e42-47bf-9788-dde6aab5ceea}) ---------- @@ -208,14 +153,14 @@ The name of the StateType ({3c7b83a0-0e42-47bf-9788-dde6aab5ceea}) of DeviceClas - + Maximal charging current percentage changed The name of the EventType ({3c7b83a0-0e42-47bf-9788-dde6aab5ceea}) of DeviceClass wallbox - - + + Plug State The name of the ParamType (DeviceClass: wallbox, EventType: plugState, ID: {3b4d29f3-3101-47ad-90fd-269b6348783b}) ---------- @@ -223,8 +168,8 @@ The name of the StateType ({3b4d29f3-3101-47ad-90fd-269b6348783b}) of DeviceClas - - + + Power consumption The name of the ParamType (DeviceClass: wallbox, EventType: P, ID: {7af9e93b-099d-4d9d-a480-9c0f66aecd8b}) ---------- @@ -232,14 +177,14 @@ The name of the StateType ({7af9e93b-099d-4d9d-a480-9c0f66aecd8b}) of DeviceClas - + Power consumtion changed The name of the EventType ({7af9e93b-099d-4d9d-a480-9c0f66aecd8b}) of DeviceClass wallbox - - + + Present energy The name of the ParamType (DeviceClass: wallbox, EventType: EP, ID: {8e277efe-21ef-4536-bfc0-901b32d44d7c}) ---------- @@ -247,32 +192,26 @@ The name of the StateType ({8e277efe-21ef-4536-bfc0-901b32d44d7c}) of DeviceClas - + Present energy changed The name of the EventType ({8e277efe-21ef-4536-bfc0-901b32d44d7c}) of DeviceClass wallbox - - Serialnumber - The name of the ParamType (DeviceClass: wallbox, Type: device, ID: {1a600fb6-08b2-4155-a4ad-ceca1d4fa7e1}) - - - - + Set Power The name of the ActionType ({83ed0774-2a91-434d-b03c-d920d02f2981}) of DeviceClass wallbox - + Set maximal charging current The name of the ActionType ({593656f0-babf-4308-8767-68f34e10fb15}) of DeviceClass wallbox - - + + Total energy consumed The name of the ParamType (DeviceClass: wallbox, EventType: totalEnergyConsumed, ID: {41e179b3-29a2-43ec-b537-023a527081e8}) ---------- @@ -280,14 +219,14 @@ The name of the StateType ({41e179b3-29a2-43ec-b537-023a527081e8}) of DeviceClas - + Total energy consumption changed The name of the EventType ({41e179b3-29a2-43ec-b537-023a527081e8}) of DeviceClass wallbox - - + + Voltage Phase 2 The name of the ParamType (DeviceClass: wallbox, EventType: U2, ID: {c8344ca5-21ac-4cd1-8f4b-e5ed202c5862}) ---------- @@ -295,8 +234,8 @@ The name of the StateType ({c8344ca5-21ac-4cd1-8f4b-e5ed202c5862}) of DeviceClas - - + + Voltage Phase 3 The name of the ParamType (DeviceClass: wallbox, EventType: U3, ID: {5f01e86c-0943-4849-a01a-db441916ebd5}) ---------- @@ -304,8 +243,8 @@ The name of the StateType ({5f01e86c-0943-4849-a01a-db441916ebd5}) of DeviceClas - - + + Voltage phase 1 The name of the ParamType (DeviceClass: wallbox, EventType: U1, ID: {4a2d75d8-a3a0-4b40-9ca7-e8b6f11d0ef9}) ---------- @@ -313,26 +252,26 @@ The name of the StateType ({4a2d75d8-a3a0-4b40-9ca7-e8b6f11d0ef9}) of DeviceClas - + Voltage phase 1 changed The name of the EventType ({4a2d75d8-a3a0-4b40-9ca7-e8b6f11d0ef9}) of DeviceClass wallbox - + Voltage phase 2 changed The name of the EventType ({c8344ca5-21ac-4cd1-8f4b-e5ed202c5862}) of DeviceClass wallbox - + Voltage phase 3 changed The name of the EventType ({5f01e86c-0943-4849-a01a-db441916ebd5}) of DeviceClass wallbox - - + + Current The name of the ParamType (DeviceClass: wallbox, EventType: current, ID: {a29c1748-fe97-4830-a56e-e1cc4e618385}) ---------- @@ -340,9 +279,9 @@ The name of the StateType ({a29c1748-fe97-4830-a56e-e1cc4e618385}) of DeviceClas - - - + + + Power The name of the ParamType (DeviceClass: wallbox, ActionType: power, ID: {83ed0774-2a91-434d-b03c-d920d02f2981}) ---------- @@ -352,19 +291,19 @@ The name of the StateType ({83ed0774-2a91-434d-b03c-d920d02f2981}) of DeviceClas - + Plug State changed The name of the EventType ({3b4d29f3-3101-47ad-90fd-269b6348783b}) of DeviceClass wallbox - + Current changed The name of the EventType ({a29c1748-fe97-4830-a56e-e1cc4e618385}) of DeviceClass wallbox - + Power changed The name of the EventType ({83ed0774-2a91-434d-b03c-d920d02f2981}) of DeviceClass wallbox