From 6c92a398ae882d28e76c86525485dcf7a0f32a25 Mon Sep 17 00:00:00 2001 From: Bernhard Trinnes Date: Mon, 16 Oct 2017 16:51:39 +0200 Subject: [PATCH 1/8] added http commander --- httpcommander/devicepluginhttpcommander.cpp | 143 +++++++++++++++++++ httpcommander/devicepluginhttpcommander.h | 50 +++++++ httpcommander/devicepluginhttpcommander.json | 116 +++++++++++++++ httpcommander/httpcommander.pro | 15 ++ nymea-plugins.pro | 1 + 5 files changed, 325 insertions(+) create mode 100644 httpcommander/devicepluginhttpcommander.cpp create mode 100644 httpcommander/devicepluginhttpcommander.h create mode 100644 httpcommander/devicepluginhttpcommander.json create mode 100644 httpcommander/httpcommander.pro diff --git a/httpcommander/devicepluginhttpcommander.cpp b/httpcommander/devicepluginhttpcommander.cpp new file mode 100644 index 00000000..b968ec29 --- /dev/null +++ b/httpcommander/devicepluginhttpcommander.cpp @@ -0,0 +1,143 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Bernhard Trinnes * + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "devicepluginhttpcommander.h" +#include "plugininfo.h" + + +DevicePluginHttpCommander::DevicePluginHttpCommander() +{ +} + +DeviceManager::HardwareResources DevicePluginHttpCommander::requiredHardware() const +{ + return DeviceManager::HardwareResourceNetworkManager | DeviceManager::HardwareResourceTimer; +} + + +DeviceManager::DeviceSetupStatus DevicePluginHttpCommander::setupDevice(Device *device) +{ + if (device->deviceClassId() == httpGetDeviceClassId) { + return DeviceManager::DeviceSetupStatusSuccess; + } + + if (device->deviceClassId() == httpPostDeviceClassId) { + return DeviceManager::DeviceSetupStatusSuccess; + } + return DeviceManager::DeviceSetupStatusFailure; +} + + +void DevicePluginHttpCommander::postSetupDevice(Device *device) +{ + if (device->deviceClassId() == httpGetDeviceClassId) { + QUrl url = device->paramValue(urlParamTypeId).toUrl(); + url.setPort(device->paramValue(portParamTypeId).toInt()); + QNetworkRequest request; + request.setUrl(url); + request.setRawHeader("User-Agent", "guhIO 1.0"); + QNetworkReply *reply = networkManagerGet(request);; + m_httpRequests.insert(reply, device); + } +} + + +DeviceManager::DeviceError DevicePluginHttpCommander::executeAction(Device *device, const Action &action) +{ + if (device->deviceClassId() == httpPostDeviceClassId) { + + // check if this is the "press" action + if (action.actionTypeId() == postActionTypeId) { + + QUrl url = device->paramValue(urlParamTypeId).toUrl(); + url.setPort(device->paramValue(portParamTypeId).toInt()); + QByteArray payload = action.param(postDataParamTypeId).value().toByteArray(); + QNetworkReply *reply = networkManagerPost(QNetworkRequest(url), payload); + m_httpRequests.insert(reply, device); + + return DeviceManager::DeviceErrorNoError; + } + return DeviceManager::DeviceErrorActionTypeNotFound; + + } + return DeviceManager::DeviceErrorDeviceClassNotFound; +} + + +void DevicePluginHttpCommander::deviceRemoved(Device *device) +{ + Q_UNUSED(device); +} + + +void DevicePluginHttpCommander::guhTimer() +{ + + foreach (Device *device, myDevices()) { + + if (device->deviceClassId() == httpGetDeviceClassId) { + QUrl url = device->paramValue(urlParamTypeId).toUrl(); + url.setPort(device->paramValue(portParamTypeId).toInt()); + QNetworkRequest request; + request.setUrl(url); + request.setRawHeader("User-Agent", "guhIO 1.0"); + QNetworkReply *reply = networkManagerGet(request);; + m_httpRequests.insert(reply, device); + } + } + +} + + +void DevicePluginHttpCommander::networkManagerReplyReady(QNetworkReply *reply) +{ + QByteArray data = reply->readAll(); + qDebug(dcHttpCommander()) << "Reply received"; + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (m_httpRequests.contains(reply)) { + Device *device = m_httpRequests.take(reply); + + if (device->deviceClassId() == httpGetDeviceClassId) { + device->setStateValue(httpResponseStateTypeId, data); + //device->setStateValue(statusStateTypeId, reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString()); + // check HTTP status code + if (status != 200 || reply->error() != QNetworkReply::NoError) { + qCWarning(dcHttpCommander()) << "Request error:" << status << reply->errorString(); + device->setStateValue(reachableStateTypeId, false); + reply->deleteLater(); + return; + } + device->setStateValue(reachableStateTypeId, true); + } else if (device->deviceClassId() == httpPostDeviceClassId) { + + // check HTTP status code + if (status != 200 || reply->error() != QNetworkReply::NoError) { + qCWarning(dcHttpCommander()) << "Request error:" << status << reply->errorString(); + device->setStateValue(reachableStateTypeId, false); + reply->deleteLater(); + return; + } + device->setStateValue(reachableStateTypeId, true); + } + } + reply->deleteLater(); +} + diff --git a/httpcommander/devicepluginhttpcommander.h b/httpcommander/devicepluginhttpcommander.h new file mode 100644 index 00000000..1cec6299 --- /dev/null +++ b/httpcommander/devicepluginhttpcommander.h @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Bernhard Trinnes * + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICEPLUGINDHTTPCOMMANDER_H +#define DEVICEPLUGINDHTTPCOMMANDER_H + +#include "plugin/deviceplugin.h" +#include "devicemanager.h" + +class DevicePluginHttpCommander : public DevicePlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "guru.guh.DevicePlugin" FILE "devicepluginhttpcommander.json") + Q_INTERFACES(DevicePlugin) + +public: + explicit DevicePluginHttpCommander(); + + DeviceManager::HardwareResources requiredHardware() const override; + DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; + void postSetupDevice(Device *device) override; + void deviceRemoved(Device *device) override; + void networkManagerReplyReady(QNetworkReply *reply) override; + void guhTimer() override; + + DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; + +private: + QHash m_httpRequests; +}; + +#endif // DEVICEPLUGINHTTPCOMMANDER_H diff --git a/httpcommander/devicepluginhttpcommander.json b/httpcommander/devicepluginhttpcommander.json new file mode 100644 index 00000000..e929820e --- /dev/null +++ b/httpcommander/devicepluginhttpcommander.json @@ -0,0 +1,116 @@ +{ + "name": "http commander", + "idName": "HttpCommander", + "id": "4e62670c-6268-4487-8dff-cccca498731a", + "vendors": [ + { + "name": "http commander", + "idName": "httpCommander", + "id": "45d7c941-7690-43c9-92fc-fab36e1cebd0", + "deviceClasses": [ + { + "id": "b101abdf-86fd-4d2e-a657-ee76044235bd", + "idName": "httpPost", + "name": "http post", + "deviceIcon": "Network", + "createMethods": ["user"], + "basicTags": [ + "Service" + ], + "primaryStateTypeId": "137ec5fc-22f5-4201-8921-2896deda0fe6", + "paramTypes": [ + { + "id": "1a3fcb23-931b-4ba1-b134-c49b656c76f7", + "idName": "url", + "name": "url or ipv4 address", + "type": "QString", + "inputType": "None", + "defaultValue": "http://nymea.io" + }, + { + "id": "bee8b151-815a-4159-9d8a-42b76e99b42c", + "idName": "port", + "name": "port", + "type": "int", + "defaultValue": "80" + } + ], + "stateTypes": [ + { + "id": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", + "idName": "reachable", + "name": "reachable", + "type": "bool", + "defaultValue": false, + "eventTypeName": "reachable status changed" + } + ], + "actionTypes": [ + { + "id": "5a97ca56-b334-411b-adba-116496ffe83d", + "idName": "post", + "name": "post", + "paramTypes": [ + { + "id": "363119a3-c02c-4ed5-a915-11706198f3eb", + "idName": "postData", + "name": "post data", + "type": "QString", + "defaultValue": "", + "eventTypeName": "post data sent" + } + ] + } + ] + }, + { + "id": "8f3f6dde-9db3-4237-800b-bb7f804098c9", + "idName": "httpGet", + "name": "http get", + "deviceIcon": "Network", + "createMethods": ["user"], + "basicTags": [ + "Service" + ], + "primaryStateTypeId": "137ec5fc-22f5-4201-8921-2896deda0fe6", + "paramTypes": [ + { + "id": "1a3fcb23-931b-4ba1-b134-c49b656c76f7", + "idName": "url", + "name": "Url or IPv4 Address", + "type": "QString", + "inputType": "None", + "defaultValue": "http://nymea.io" + }, + { + "id": "bee8b151-815a-4159-9d8a-42b76e99b42c", + "idName": "port", + "name": "Port", + "type": "int", + "defaultValue": "80" + } + ], + "stateTypes":[ + { + "id": "137ec5fc-22f5-4201-8921-2896deda0fe6", + "idName": "status", + "name": "status", + "type": "QString", + "defaultValue": "Undefined", + "eventTypeName": "connection status changed" + }, + { + "id": "5a97ca56-b334-411b-adba-116496ffe83d", + "idName": "httpResponse", + "name": "response", + "type": "QString", + "defaultValue": "", + "eventTypeName": "response received" + } + ] + } + ] + } + ] +} + diff --git a/httpcommander/httpcommander.pro b/httpcommander/httpcommander.pro new file mode 100644 index 00000000..b1b2b360 --- /dev/null +++ b/httpcommander/httpcommander.pro @@ -0,0 +1,15 @@ +TRANSLATIONS = translations/en_US.ts \ + translations/de_DE.ts + +# Note: include after the TRANSLATIONS definition +include(../plugins.pri) + +TARGET = $$qtLibraryTarget(guh_devicepluginhttpcommander) + +SOURCES += \ + devicepluginhttpcommander.cpp \ + +HEADERS += \ + devicepluginhttpcommander.h \ + + diff --git a/nymea-plugins.pro b/nymea-plugins.pro index 3d3d7b16..28b76841 100644 --- a/nymea-plugins.pro +++ b/nymea-plugins.pro @@ -19,6 +19,7 @@ PLUGIN_DIRS = \ leynew \ udpcommander \ tcpcommander \ + httpcommander \ kodi \ elgato \ senic \ From 7d758a11b882eea619ad05a6e7dac68db373d6f2 Mon Sep 17 00:00:00 2001 From: Bernhard Trinnes Date: Tue, 17 Oct 2017 17:21:44 +0200 Subject: [PATCH 2/8] added http put device and fixed bugs in the post device --- httpcommander/devicepluginhttpcommander.cpp | 35 +++++-- httpcommander/devicepluginhttpcommander.json | 97 +++++++++++++++++--- 2 files changed, 111 insertions(+), 21 deletions(-) diff --git a/httpcommander/devicepluginhttpcommander.cpp b/httpcommander/devicepluginhttpcommander.cpp index b968ec29..9d52ff91 100644 --- a/httpcommander/devicepluginhttpcommander.cpp +++ b/httpcommander/devicepluginhttpcommander.cpp @@ -34,13 +34,15 @@ DeviceManager::HardwareResources DevicePluginHttpCommander::requiredHardware() c DeviceManager::DeviceSetupStatus DevicePluginHttpCommander::setupDevice(Device *device) { - if (device->deviceClassId() == httpGetDeviceClassId) { + if ((device->deviceClassId() == httpGetDeviceClassId) || (device->deviceClassId() == httpPostDeviceClassId) || (device->deviceClassId() == httpPutDeviceClassId)) { + QUrl url = device->paramValue(urlParamTypeId).toUrl(); + if (!url.isValid()) { + qDebug(dcHttpCommander()) << "Given URL is not valid"; + } + return DeviceManager::DeviceSetupStatusSuccess; } - if (device->deviceClassId() == httpPostDeviceClassId) { - return DeviceManager::DeviceSetupStatusSuccess; - } return DeviceManager::DeviceSetupStatusFailure; } @@ -56,6 +58,10 @@ void DevicePluginHttpCommander::postSetupDevice(Device *device) QNetworkReply *reply = networkManagerGet(request);; m_httpRequests.insert(reply, device); } + if ((device->deviceClassId() == httpPostDeviceClassId) || (device->deviceClassId() == httpPutDeviceClassId)) { + //TODO find a way to check it the URL is reachable + device->setStateValue(reachableStateTypeId, true); + } } @@ -77,6 +83,20 @@ DeviceManager::DeviceError DevicePluginHttpCommander::executeAction(Device *devi return DeviceManager::DeviceErrorActionTypeNotFound; } + if (device->deviceClassId() == httpPutDeviceClassId) { + + // check if this is the "press" action + if (action.actionTypeId() == putActionTypeId) { + + QUrl url = device->paramValue(urlParamTypeId).toUrl(); + url.setPort(device->paramValue(portParamTypeId).toInt()); + QByteArray payload = action.param(putDataParamTypeId).value().toByteArray(); + QNetworkReply *reply = networkManagerPut(QNetworkRequest(url), payload); + m_httpRequests.insert(reply, device); + + return DeviceManager::DeviceErrorNoError; + } + } return DeviceManager::DeviceErrorDeviceClassNotFound; } @@ -116,8 +136,7 @@ void DevicePluginHttpCommander::networkManagerReplyReady(QNetworkReply *reply) Device *device = m_httpRequests.take(reply); if (device->deviceClassId() == httpGetDeviceClassId) { - device->setStateValue(httpResponseStateTypeId, data); - //device->setStateValue(statusStateTypeId, reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString()); + device->setStateValue(getDataStateTypeId, data); // check HTTP status code if (status != 200 || reply->error() != QNetworkReply::NoError) { qCWarning(dcHttpCommander()) << "Request error:" << status << reply->errorString(); @@ -126,8 +145,8 @@ void DevicePluginHttpCommander::networkManagerReplyReady(QNetworkReply *reply) return; } device->setStateValue(reachableStateTypeId, true); - } else if (device->deviceClassId() == httpPostDeviceClassId) { - + } else if ((device->deviceClassId() == httpPostDeviceClassId) || (device->deviceClassId() == httpPutDeviceClassId) ) { + device->setStateValue(httpResponseStateTypeId, data); // check HTTP status code if (status != 200 || reply->error() != QNetworkReply::NoError) { qCWarning(dcHttpCommander()) << "Request error:" << status << reply->errorString(); diff --git a/httpcommander/devicepluginhttpcommander.json b/httpcommander/devicepluginhttpcommander.json index e929820e..0ad28dc6 100644 --- a/httpcommander/devicepluginhttpcommander.json +++ b/httpcommander/devicepluginhttpcommander.json @@ -17,7 +17,7 @@ "basicTags": [ "Service" ], - "primaryStateTypeId": "137ec5fc-22f5-4201-8921-2896deda0fe6", + "criticalStateTypeId": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", "paramTypes": [ { "id": "1a3fcb23-931b-4ba1-b134-c49b656c76f7", @@ -42,7 +42,15 @@ "name": "reachable", "type": "bool", "defaultValue": false, - "eventTypeName": "reachable status changed" + "eventTypeName": "reachability changed" + }, + { + "id": "69f32ec8-114d-43f4-9241-1f6a57261f32", + "idName": "httpResponse", + "name": "response", + "type": "QString", + "defaultValue": "", + "eventTypeName": "response received" } ], "actionTypes": [ @@ -63,6 +71,69 @@ } ] }, + { + "id": "05bf65f5-ff13-43e3-b6ae-77019e79d8a1", + "idName": "httpPut", + "name": "http put", + "deviceIcon": "Network", + "createMethods": ["user"], + "basicTags": [ + "Service" + ], + "criticalStateTypeId": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", + "paramTypes": [ + { + "id": "1a3fcb23-931b-4ba1-b134-c49b656c76f7", + "idName": "url", + "name": "url or ipv4 address", + "type": "QString", + "inputType": "None", + "defaultValue": "http://nymea.io" + }, + { + "id": "bee8b151-815a-4159-9d8a-42b76e99b42c", + "idName": "port", + "name": "port", + "type": "int", + "defaultValue": "80" + } + ], + "stateTypes": [ + { + "id": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", + "idName": "reachable", + "name": "reachable", + "type": "bool", + "defaultValue": false, + "eventTypeName": "reachability changed" + }, + { + "id": "69f32ec8-114d-43f4-9241-1f6a57261f32", + "idName": "httpResponse", + "name": "response", + "type": "QString", + "defaultValue": "", + "eventTypeName": "response received" + } + ], + "actionTypes": [ + { + "id": "a9f165dc-cdf1-48f0-b4b6-7c24373cb77c", + "idName": "put", + "name": "put", + "paramTypes": [ + { + "id": "7742d445-8fc1-4b20-87f2-1bb35929fce1", + "idName": "putData", + "name": "put data", + "type": "QString", + "defaultValue": "", + "eventTypeName": "post data sent" + } + ] + } + ] + }, { "id": "8f3f6dde-9db3-4237-800b-bb7f804098c9", "idName": "httpGet", @@ -72,7 +143,7 @@ "basicTags": [ "Service" ], - "primaryStateTypeId": "137ec5fc-22f5-4201-8921-2896deda0fe6", + "criticalStateTypeId": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", "paramTypes": [ { "id": "1a3fcb23-931b-4ba1-b134-c49b656c76f7", @@ -92,20 +163,20 @@ ], "stateTypes":[ { - "id": "137ec5fc-22f5-4201-8921-2896deda0fe6", - "idName": "status", - "name": "status", - "type": "QString", - "defaultValue": "Undefined", - "eventTypeName": "connection status changed" + "id": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", + "idName": "reachable", + "name": "reachable", + "type": "bool", + "defaultValue": false, + "eventTypeName": "reachability changed" }, { - "id": "5a97ca56-b334-411b-adba-116496ffe83d", - "idName": "httpResponse", - "name": "response", + "id": "d81f0644-b94e-48ed-ae48-1b8ff6cebc0c", + "idName": "getData", + "name": "data", "type": "QString", "defaultValue": "", - "eventTypeName": "response received" + "eventTypeName": "get data received" } ] } From b2b94480fc3476041f127f7a3a6447c8a962882f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 15 Nov 2017 21:38:05 +0100 Subject: [PATCH 3/8] Add debian package for http commander --- debian/control | 17 +++++++++++++++-- debian/guh-plugin-httpcommander.install.in | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 debian/guh-plugin-httpcommander.install.in diff --git a/debian/control b/debian/control index d181a514..9645c2d2 100644 --- a/debian/control +++ b/debian/control @@ -508,6 +508,20 @@ Description: nymea.io plugin for TCP commander . This package will install the nymea.io plugin for TCP commander +Package: guh-plugin-httpcommander +Architecture: any +Depends: ${shlibs:Depends}, + ${misc:Depends}, + guh-plugins-translations, +Description: guh.io plugin for HTTP commander + The guh daemon is a plugin based IoT (Internet of Things) server. The + server works like a translator for devices, things and services and + allows them to interact. + With the powerful rule engine you are able to connect any device available + in the system and create individual scenes and behaviors for your environment. + . + This package will install the guh.io plugin for HTTP commander + Package: nymea-plugin-simulation Architecture: any @@ -589,7 +603,6 @@ Description: nymea.io plugin for keba This package will install the nymea.io plugin for keba - Package: nymea-plugins-translations Section: misc Architecture: all @@ -605,7 +618,6 @@ Description: Translation files for nymea plugins - translations This package provides the translation files for all nymea plugins. - Package: nymea-plugins Section: libs Architecture: all @@ -644,6 +656,7 @@ Architecture: all Depends: nymea-plugin-commandlauncher, nymea-plugin-udpcommander, nymea-plugin-tcpcommander, + nymea-plugin-httpcommander, nymea-plugin-genericelements, nymea-plugin-avahimonitor, nymea-plugin-gpio, diff --git a/debian/guh-plugin-httpcommander.install.in b/debian/guh-plugin-httpcommander.install.in new file mode 100644 index 00000000..710316ae --- /dev/null +++ b/debian/guh-plugin-httpcommander.install.in @@ -0,0 +1 @@ +usr/lib/@DEB_HOST_MULTIARCH@/guh/plugins/libguh_devicepluginhttpcommander.so From 7cddf914636fbd2346d2298dc05a6aad2573fde6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 9 Feb 2018 20:09:53 +0100 Subject: [PATCH 4/8] Migrate to interfaces and hardwaremanager --- httpcommander/devicepluginhttpcommander.cpp | 231 +++++++++++++------ httpcommander/devicepluginhttpcommander.h | 20 +- httpcommander/devicepluginhttpcommander.json | 130 +++++------ httpcommander/httpcommander.pro | 4 - 4 files changed, 241 insertions(+), 144 deletions(-) diff --git a/httpcommander/devicepluginhttpcommander.cpp b/httpcommander/devicepluginhttpcommander.cpp index 9d52ff91..13d4c211 100644 --- a/httpcommander/devicepluginhttpcommander.cpp +++ b/httpcommander/devicepluginhttpcommander.cpp @@ -1,6 +1,7 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2017 Bernhard Trinnes * + * Copyright (C) 2018 Simon Stürz * * * * This file is part of guh. * * * @@ -19,6 +20,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "devicepluginhttpcommander.h" +#include "network/networkaccessmanager.h" #include "plugininfo.h" @@ -26,18 +28,49 @@ DevicePluginHttpCommander::DevicePluginHttpCommander() { } -DeviceManager::HardwareResources DevicePluginHttpCommander::requiredHardware() const +DevicePluginHttpCommander::~DevicePluginHttpCommander() { - return DeviceManager::HardwareResourceNetworkManager | DeviceManager::HardwareResourceTimer; + hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer); } +void DevicePluginHttpCommander::init() +{ + m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(10); + connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginHttpCommander::onPluginTimer); +} DeviceManager::DeviceSetupStatus DevicePluginHttpCommander::setupDevice(Device *device) { - if ((device->deviceClassId() == httpGetDeviceClassId) || (device->deviceClassId() == httpPostDeviceClassId) || (device->deviceClassId() == httpPutDeviceClassId)) { - QUrl url = device->paramValue(urlParamTypeId).toUrl(); + qDebug(dcHttpCommander()) << "Setup device" << device->name() << device->params(); + + // Get + if (device->deviceClassId() == httpGetCommanderDeviceClassId) { + QUrl url = device->paramValue(httpGetCommanderUrlParamTypeId).toUrl(); if (!url.isValid()) { qDebug(dcHttpCommander()) << "Given URL is not valid"; + return DeviceManager::DeviceSetupStatusFailure; + } + + return DeviceManager::DeviceSetupStatusSuccess; + } + + // Put + if (device->deviceClassId() == httpPutCommanderDeviceClassId) { + QUrl url = device->paramValue(httpPutCommanderUrlParamTypeId).toUrl(); + if (!url.isValid()) { + qDebug(dcHttpCommander()) << "Given URL is not valid"; + return DeviceManager::DeviceSetupStatusFailure; + } + + return DeviceManager::DeviceSetupStatusSuccess; + } + + // Post + if (device->deviceClassId() == httpPostCommanderDeviceClassId) { + QUrl url = device->paramValue(httpPostCommanderUrlParamTypeId).toUrl(); + if (!url.isValid()) { + qDebug(dcHttpCommander()) << "Given URL is not valid"; + return DeviceManager::DeviceSetupStatusFailure; } return DeviceManager::DeviceSetupStatusSuccess; @@ -49,33 +82,34 @@ DeviceManager::DeviceSetupStatus DevicePluginHttpCommander::setupDevice(Device * void DevicePluginHttpCommander::postSetupDevice(Device *device) { - if (device->deviceClassId() == httpGetDeviceClassId) { - QUrl url = device->paramValue(urlParamTypeId).toUrl(); - url.setPort(device->paramValue(portParamTypeId).toInt()); - QNetworkRequest request; - request.setUrl(url); - request.setRawHeader("User-Agent", "guhIO 1.0"); - QNetworkReply *reply = networkManagerGet(request);; - m_httpRequests.insert(reply, device); + if (device->deviceClassId() == httpGetCommanderDeviceClassId) { + makeGetCall(device); } - if ((device->deviceClassId() == httpPostDeviceClassId) || (device->deviceClassId() == httpPutDeviceClassId)) { + + if (device->deviceClassId() == httpPostCommanderDeviceClassId) { //TODO find a way to check it the URL is reachable - device->setStateValue(reachableStateTypeId, true); + device->setStateValue(httpPostCommanderConnectedStateTypeId, true); + } + + if (device->deviceClassId() == httpPutCommanderDeviceClassId) { + //TODO find a way to check it the URL is reachable + device->setStateValue(httpPutCommanderConnectedStateTypeId, true); } } DeviceManager::DeviceError DevicePluginHttpCommander::executeAction(Device *device, const Action &action) { - if (device->deviceClassId() == httpPostDeviceClassId) { + if (device->deviceClassId() == httpPostCommanderDeviceClassId) { - // check if this is the "press" action - if (action.actionTypeId() == postActionTypeId) { + if (action.actionTypeId() == httpPostCommanderPostActionTypeId) { + QUrl url = device->paramValue(httpPostCommanderUrlParamTypeId).toUrl(); + url.setPort(device->paramValue(httpPostCommanderPortParamTypeId).toInt()); + QByteArray payload = action.param(httpPostCommanderDataParamTypeId).value().toByteArray(); + + QNetworkReply *reply = hardwareManager()->networkManager()->post(QNetworkRequest(url), payload); + connect(reply, &QNetworkReply::finished, this, &DevicePluginHttpCommander::onPostRequestFinished); - QUrl url = device->paramValue(urlParamTypeId).toUrl(); - url.setPort(device->paramValue(portParamTypeId).toInt()); - QByteArray payload = action.param(postDataParamTypeId).value().toByteArray(); - QNetworkReply *reply = networkManagerPost(QNetworkRequest(url), payload); m_httpRequests.insert(reply, device); return DeviceManager::DeviceErrorNoError; @@ -83,15 +117,18 @@ DeviceManager::DeviceError DevicePluginHttpCommander::executeAction(Device *devi return DeviceManager::DeviceErrorActionTypeNotFound; } - if (device->deviceClassId() == httpPutDeviceClassId) { + + if (device->deviceClassId() == httpPutCommanderDeviceClassId) { // check if this is the "press" action - if (action.actionTypeId() == putActionTypeId) { + if (action.actionTypeId() == httpPutCommanderPutActionTypeId) { + + QUrl url = device->paramValue(httpPutCommanderUrlParamTypeId).toUrl(); + url.setPort(device->paramValue(httpPutCommanderPortParamTypeId).toInt()); + QByteArray payload = action.param(httpPutCommanderDataParamTypeId).value().toByteArray(); + QNetworkReply *reply = hardwareManager()->networkManager()->put(QNetworkRequest(url), payload); + connect(reply, &QNetworkReply::finished, this, &DevicePluginHttpCommander::onPutRequestFinished); - QUrl url = device->paramValue(urlParamTypeId).toUrl(); - url.setPort(device->paramValue(portParamTypeId).toInt()); - QByteArray payload = action.param(putDataParamTypeId).value().toByteArray(); - QNetworkReply *reply = networkManagerPut(QNetworkRequest(url), payload); m_httpRequests.insert(reply, device); return DeviceManager::DeviceErrorNoError; @@ -100,63 +137,117 @@ DeviceManager::DeviceError DevicePluginHttpCommander::executeAction(Device *devi return DeviceManager::DeviceErrorDeviceClassNotFound; } - -void DevicePluginHttpCommander::deviceRemoved(Device *device) +void DevicePluginHttpCommander::makeGetCall(Device *device) { - Q_UNUSED(device); + QUrl url = device->paramValue(httpGetCommanderUrlParamTypeId).toUrl(); + url.setPort(device->paramValue(httpGetCommanderPortParamTypeId).toInt()); + QNetworkRequest request; + request.setUrl(url); + request.setRawHeader("User-Agent", "guhIO 1.0"); + + QNetworkReply *reply = hardwareManager()->networkManager()->get(request); + connect(reply, &QNetworkReply::finished, this, &DevicePluginHttpCommander::onGetRequestFinished); + + m_httpRequests.insert(reply, device); } - -void DevicePluginHttpCommander::guhTimer() +void DevicePluginHttpCommander::onPluginTimer() { - foreach (Device *device, myDevices()) { - - if (device->deviceClassId() == httpGetDeviceClassId) { - QUrl url = device->paramValue(urlParamTypeId).toUrl(); - url.setPort(device->paramValue(portParamTypeId).toInt()); - QNetworkRequest request; - request.setUrl(url); - request.setRawHeader("User-Agent", "guhIO 1.0"); - QNetworkReply *reply = networkManagerGet(request);; - m_httpRequests.insert(reply, device); + if (device->deviceClassId() == httpGetCommanderDeviceClassId) { + makeGetCall(device); } } - } - -void DevicePluginHttpCommander::networkManagerReplyReady(QNetworkReply *reply) +void DevicePluginHttpCommander::onGetRequestFinished() { + QNetworkReply *reply = static_cast(sender()); + qDebug(dcHttpCommander()) << "GET reply finished"; QByteArray data = reply->readAll(); - qDebug(dcHttpCommander()) << "Reply received"; int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (m_httpRequests.contains(reply)) { - Device *device = m_httpRequests.take(reply); - - if (device->deviceClassId() == httpGetDeviceClassId) { - device->setStateValue(getDataStateTypeId, data); - // check HTTP status code - if (status != 200 || reply->error() != QNetworkReply::NoError) { - qCWarning(dcHttpCommander()) << "Request error:" << status << reply->errorString(); - device->setStateValue(reachableStateTypeId, false); - reply->deleteLater(); - return; - } - device->setStateValue(reachableStateTypeId, true); - } else if ((device->deviceClassId() == httpPostDeviceClassId) || (device->deviceClassId() == httpPutDeviceClassId) ) { - device->setStateValue(httpResponseStateTypeId, data); - // check HTTP status code - if (status != 200 || reply->error() != QNetworkReply::NoError) { - qCWarning(dcHttpCommander()) << "Request error:" << status << reply->errorString(); - device->setStateValue(reachableStateTypeId, false); - reply->deleteLater(); - return; - } - device->setStateValue(reachableStateTypeId, true); - } + if (!m_httpRequests.contains(reply)) { + reply->deleteLater(); + return; } + + Device *device = m_httpRequests.take(reply); + device->setStateValue(httpGetCommanderResponseStateTypeId, data); + + // Check HTTP status code + if (status != 200 || reply->error() != QNetworkReply::NoError) { + qCWarning(dcHttpCommander()) << "Request error:" << status << reply->errorString(); + device->setStateValue(httpGetCommanderConnectedStateTypeId, false); + reply->deleteLater(); + return; + } + + device->setStateValue(httpGetCommanderConnectedStateTypeId, true); reply->deleteLater(); } +void DevicePluginHttpCommander::onPostRequestFinished() +{ + QNetworkReply *reply = static_cast(sender()); + qDebug(dcHttpCommander()) << "POST reply finished"; + QByteArray data = reply->readAll(); + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (!m_httpRequests.contains(reply)) { + reply->deleteLater(); + return; + } + + Device *device = m_httpRequests.take(reply); + device->setStateValue(httpPostCommanderResponseStateTypeId, data); + + // Check HTTP status code + if (status != 200 || reply->error() != QNetworkReply::NoError) { + qCWarning(dcHttpCommander()) << "Request error:" << status << reply->errorString(); + device->setStateValue(httpPostCommanderConnectedStateTypeId, false); + reply->deleteLater(); + return; + } + + device->setStateValue(httpPostCommanderConnectedStateTypeId, true); + reply->deleteLater(); +} + +void DevicePluginHttpCommander::onPutRequestFinished() +{ + QNetworkReply *reply = static_cast(sender()); + qDebug(dcHttpCommander()) << "PUT reply finished"; + QByteArray data = reply->readAll(); + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (!m_httpRequests.contains(reply)) { + reply->deleteLater(); + return; + } + + Device *device = m_httpRequests.take(reply); + device->setStateValue(httpPutCommanderResponseStateTypeId, data); + + // Check HTTP status code + if (status != 200 || reply->error() != QNetworkReply::NoError) { + qCWarning(dcHttpCommander()) << "Request error:" << status << reply->errorString(); + device->setStateValue(httpPutCommanderConnectedStateTypeId, false); + reply->deleteLater(); + return; + } + + device->setStateValue(httpPutCommanderConnectedStateTypeId, true); + reply->deleteLater(); +} + + +void DevicePluginHttpCommander::deviceRemoved(Device *device) +{ + if (m_httpRequests.values().contains(device)) { + QNetworkReply *reply = m_httpRequests.key(device); + m_httpRequests.remove(reply); + // Note: will be deleted once finished + } +} + diff --git a/httpcommander/devicepluginhttpcommander.h b/httpcommander/devicepluginhttpcommander.h index 1cec6299..4bacfa95 100644 --- a/httpcommander/devicepluginhttpcommander.h +++ b/httpcommander/devicepluginhttpcommander.h @@ -1,6 +1,7 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2017 Bernhard Trinnes * + * Copyright (C) 2018 Simon Stürz * * * * This file is part of guh. * * * @@ -23,6 +24,9 @@ #include "plugin/deviceplugin.h" #include "devicemanager.h" +#include "plugintimer.h" + +#include class DevicePluginHttpCommander : public DevicePlugin { @@ -33,18 +37,26 @@ class DevicePluginHttpCommander : public DevicePlugin public: explicit DevicePluginHttpCommander(); + ~DevicePluginHttpCommander(); - DeviceManager::HardwareResources requiredHardware() const override; + void init() override; DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; void postSetupDevice(Device *device) override; void deviceRemoved(Device *device) override; - void networkManagerReplyReady(QNetworkReply *reply) override; - void guhTimer() override; - DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; private: + PluginTimer *m_pluginTimer = nullptr; QHash m_httpRequests; + + void makeGetCall(Device *device); + +private slots: + void onPluginTimer(); + + void onGetRequestFinished(); + void onPostRequestFinished(); + void onPutRequestFinished(); }; #endif // DEVICEPLUGINHTTPCOMMANDER_H diff --git a/httpcommander/devicepluginhttpcommander.json b/httpcommander/devicepluginhttpcommander.json index 0ad28dc6..e400bc87 100644 --- a/httpcommander/devicepluginhttpcommander.json +++ b/httpcommander/devicepluginhttpcommander.json @@ -1,71 +1,70 @@ { - "name": "http commander", - "idName": "HttpCommander", + "name": "HttpCommander", + "displayName": "Http Commander", "id": "4e62670c-6268-4487-8dff-cccca498731a", "vendors": [ { - "name": "http commander", - "idName": "httpCommander", + "name": "httpCommander", + "displayName": "HTTP commander", "id": "45d7c941-7690-43c9-92fc-fab36e1cebd0", "deviceClasses": [ { "id": "b101abdf-86fd-4d2e-a657-ee76044235bd", - "idName": "httpPost", - "name": "http post", + "name": "httpPostCommander", + "displayName": "HTTP post commander", "deviceIcon": "Network", "createMethods": ["user"], "basicTags": [ "Service" ], - "criticalStateTypeId": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", + "interfaces": ["connectable"], "paramTypes": [ { - "id": "1a3fcb23-931b-4ba1-b134-c49b656c76f7", - "idName": "url", - "name": "url or ipv4 address", + "id": "020f672e-cc9a-4b74-92dd-a92a93ab1d23", + "name": "url", + "displayName": "URL or IPv4 address", "type": "QString", "inputType": "None", - "defaultValue": "http://nymea.io" + "defaultValue": "https://nymea.io" }, { - "id": "bee8b151-815a-4159-9d8a-42b76e99b42c", - "idName": "port", + "id": "37830ea8-2249-46e6-aaca-12164928a81a", "name": "port", + "displayName": "port", "type": "int", - "defaultValue": "80" + "defaultValue": "443" } ], "stateTypes": [ { "id": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", - "idName": "reachable", - "name": "reachable", + "name": "connected", + "displayName": "Reachable", + "displayNameEvent": "Reachability changed", "type": "bool", - "defaultValue": false, - "eventTypeName": "reachability changed" + "defaultValue": false }, { "id": "69f32ec8-114d-43f4-9241-1f6a57261f32", - "idName": "httpResponse", "name": "response", + "displayName": "response", + "displayNameEvent": "Response received", "type": "QString", - "defaultValue": "", - "eventTypeName": "response received" + "defaultValue": "" } ], "actionTypes": [ { "id": "5a97ca56-b334-411b-adba-116496ffe83d", - "idName": "post", "name": "post", + "displayName": "Post data", "paramTypes": [ { "id": "363119a3-c02c-4ed5-a915-11706198f3eb", - "idName": "postData", - "name": "post data", + "name": "data", + "displayName": "Data", "type": "QString", - "defaultValue": "", - "eventTypeName": "post data sent" + "defaultValue": "" } ] } @@ -73,62 +72,61 @@ }, { "id": "05bf65f5-ff13-43e3-b6ae-77019e79d8a1", - "idName": "httpPut", - "name": "http put", + "name": "httpPutCommander", + "displayName": "HTTP put commander", "deviceIcon": "Network", "createMethods": ["user"], + "interfaces": ["connectable"], "basicTags": [ "Service" ], - "criticalStateTypeId": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", "paramTypes": [ { "id": "1a3fcb23-931b-4ba1-b134-c49b656c76f7", - "idName": "url", - "name": "url or ipv4 address", + "name": "url", + "displayName": "URL or IPv4 address", "type": "QString", "inputType": "None", - "defaultValue": "http://nymea.io" + "defaultValue": "https://nymea.io" }, { - "id": "bee8b151-815a-4159-9d8a-42b76e99b42c", - "idName": "port", + "id": "db994349-1105-4ce5-b6fe-6fd38fbc436a", "name": "port", + "displayName": "Port", "type": "int", - "defaultValue": "80" + "defaultValue": "443" } ], "stateTypes": [ { - "id": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", - "idName": "reachable", - "name": "reachable", + "id": "d102ff86-b773-48e3-a7a5-e138cb541f49", + "name": "connected", + "displayName": "Reachable", + "displayNameEvent": "Reachability changed", "type": "bool", - "defaultValue": false, - "eventTypeName": "reachability changed" + "defaultValue": false }, { "id": "69f32ec8-114d-43f4-9241-1f6a57261f32", - "idName": "httpResponse", "name": "response", + "displayName": "Response", + "displayNameEvent": "Response received", "type": "QString", - "defaultValue": "", - "eventTypeName": "response received" + "defaultValue": "" } ], "actionTypes": [ { "id": "a9f165dc-cdf1-48f0-b4b6-7c24373cb77c", - "idName": "put", "name": "put", + "displayName": "put", "paramTypes": [ { "id": "7742d445-8fc1-4b20-87f2-1bb35929fce1", - "idName": "putData", - "name": "put data", + "name": "data", + "displayName": "Data", "type": "QString", - "defaultValue": "", - "eventTypeName": "post data sent" + "defaultValue": "" } ] } @@ -136,47 +134,47 @@ }, { "id": "8f3f6dde-9db3-4237-800b-bb7f804098c9", - "idName": "httpGet", - "name": "http get", + "name": "httpGetCommander", + "displayName": "HTTP get", "deviceIcon": "Network", "createMethods": ["user"], "basicTags": [ "Service" ], - "criticalStateTypeId": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", + "interfaces": ["connectable"], "paramTypes": [ { - "id": "1a3fcb23-931b-4ba1-b134-c49b656c76f7", - "idName": "url", - "name": "Url or IPv4 Address", + "id": "477b544b-b631-4526-a4ef-c712ff5f955d", + "name": "url", + "displayName": "URL or IPv4 Address", "type": "QString", "inputType": "None", - "defaultValue": "http://nymea.io" + "defaultValue": "https://nymea.io" }, { "id": "bee8b151-815a-4159-9d8a-42b76e99b42c", - "idName": "port", - "name": "Port", + "name": "port", + "displayName": "Port", "type": "int", - "defaultValue": "80" + "defaultValue": "443" } ], "stateTypes":[ { - "id": "8daac0e7-4c2f-4cdf-b528-02cfe04c6b39", - "idName": "reachable", - "name": "reachable", + "id": "0d63f815-efd1-488a-9bfa-e9f6bda540d2", + "name": "connected", + "displayName": "Reachable", + "displayNameEvent": "Reachability changed", "type": "bool", - "defaultValue": false, - "eventTypeName": "reachability changed" + "defaultValue": false }, { "id": "d81f0644-b94e-48ed-ae48-1b8ff6cebc0c", - "idName": "getData", - "name": "data", + "name": "response", + "displayName": "Response", "type": "QString", "defaultValue": "", - "eventTypeName": "get data received" + "displayNameEvent": "Response data received" } ] } diff --git a/httpcommander/httpcommander.pro b/httpcommander/httpcommander.pro index b1b2b360..34f0ba80 100644 --- a/httpcommander/httpcommander.pro +++ b/httpcommander/httpcommander.pro @@ -1,7 +1,3 @@ -TRANSLATIONS = translations/en_US.ts \ - translations/de_DE.ts - -# Note: include after the TRANSLATIONS definition include(../plugins.pri) TARGET = $$qtLibraryTarget(guh_devicepluginhttpcommander) From cc135935d7d128543453b519ac0a80fe0105a38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 9 Feb 2018 20:15:05 +0100 Subject: [PATCH 5/8] Add translation files --- httpcommander/translations/de_DE.ts | 4 ++++ httpcommander/translations/en_US.ts | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 httpcommander/translations/de_DE.ts create mode 100644 httpcommander/translations/en_US.ts diff --git a/httpcommander/translations/de_DE.ts b/httpcommander/translations/de_DE.ts new file mode 100644 index 00000000..1552582e --- /dev/null +++ b/httpcommander/translations/de_DE.ts @@ -0,0 +1,4 @@ + + + + diff --git a/httpcommander/translations/en_US.ts b/httpcommander/translations/en_US.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/httpcommander/translations/en_US.ts @@ -0,0 +1,4 @@ + + + + From 56366694c3da7947186535eea98ac1ce4348060a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 13 Mar 2018 17:44:25 +0100 Subject: [PATCH 6/8] Rename to nymea --- httpcommander/devicepluginhttpcommander.h | 2 +- httpcommander/httpcommander.pro | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/httpcommander/devicepluginhttpcommander.h b/httpcommander/devicepluginhttpcommander.h index 4bacfa95..939d2363 100644 --- a/httpcommander/devicepluginhttpcommander.h +++ b/httpcommander/devicepluginhttpcommander.h @@ -32,7 +32,7 @@ class DevicePluginHttpCommander : public DevicePlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID "guru.guh.DevicePlugin" FILE "devicepluginhttpcommander.json") + Q_PLUGIN_METADATA(IID "io.nymea.DevicePlugin" FILE "devicepluginhttpcommander.json") Q_INTERFACES(DevicePlugin) public: diff --git a/httpcommander/httpcommander.pro b/httpcommander/httpcommander.pro index 34f0ba80..890aea91 100644 --- a/httpcommander/httpcommander.pro +++ b/httpcommander/httpcommander.pro @@ -1,6 +1,6 @@ include(../plugins.pri) -TARGET = $$qtLibraryTarget(guh_devicepluginhttpcommander) +TARGET = $$qtLibraryTarget(nymea_devicepluginhttpcommander) SOURCES += \ devicepluginhttpcommander.cpp \ From 61191c4a7481a770f6bff9c83ed399206cc60781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 13 Mar 2018 18:00:18 +0100 Subject: [PATCH 7/8] Update license header --- httpcommander/devicepluginhttpcommander.cpp | 20 +++++++++++--------- httpcommander/devicepluginhttpcommander.h | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/httpcommander/devicepluginhttpcommander.cpp b/httpcommander/devicepluginhttpcommander.cpp index 13d4c211..cd5327a9 100644 --- a/httpcommander/devicepluginhttpcommander.cpp +++ b/httpcommander/devicepluginhttpcommander.cpp @@ -3,19 +3,21 @@ * Copyright (C) 2017 Bernhard Trinnes * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh. * + * This file is part of nymea. * * * - * Guh is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, version 2 of the License. * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * * * - * Guh is distributed in the hope that it will be useful, * + * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * * * - * You should have received a copy of the GNU General Public License * - * along with guh. If not, see . * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; If not, see * + * . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ diff --git a/httpcommander/devicepluginhttpcommander.h b/httpcommander/devicepluginhttpcommander.h index 939d2363..d9453ae1 100644 --- a/httpcommander/devicepluginhttpcommander.h +++ b/httpcommander/devicepluginhttpcommander.h @@ -3,19 +3,21 @@ * Copyright (C) 2017 Bernhard Trinnes * * Copyright (C) 2018 Simon Stürz * * * - * This file is part of guh. * + * This file is part of nymea. * * * - * Guh is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, version 2 of the License. * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * * * - * Guh is distributed in the hope that it will be useful, * + * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * * * - * You should have received a copy of the GNU General Public License * - * along with guh. If not, see . * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; If not, see * + * . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ From db34680d981d8ad1d71f256f83c5178e3d0cdc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 15 Mar 2018 08:41:14 +0100 Subject: [PATCH 8/8] Fix debian packaging for nymea plugins --- debian/control | 12 ++++++------ debian/guh-plugin-httpcommander.install.in | 1 - debian/nymea-plugin-httpcommander.install.in | 1 + httpcommander/devicepluginhttpcommander.h | 4 ++-- httpcommander/devicepluginhttpcommander.json | 6 +++--- ...=> 4e62670c-6268-4487-8dff-cccca498731a-en_US.ts} | 2 +- httpcommander/translations/de_DE.ts | 4 ---- 7 files changed, 13 insertions(+), 17 deletions(-) delete mode 100644 debian/guh-plugin-httpcommander.install.in create mode 100644 debian/nymea-plugin-httpcommander.install.in rename httpcommander/translations/{en_US.ts => 4e62670c-6268-4487-8dff-cccca498731a-en_US.ts} (92%) delete mode 100644 httpcommander/translations/de_DE.ts diff --git a/debian/control b/debian/control index 9645c2d2..76c4b5a4 100644 --- a/debian/control +++ b/debian/control @@ -506,21 +506,21 @@ Description: nymea.io plugin for TCP commander With the powerful rule engine you are able to connect any device available in the system and create individual scenes and behaviors for your environment. . - This package will install the nymea.io plugin for TCP commander + This package will install the nymea.io plugin for the TCP commander -Package: guh-plugin-httpcommander +Package: nymea-plugin-httpcommander Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, - guh-plugins-translations, -Description: guh.io plugin for HTTP commander - The guh daemon is a plugin based IoT (Internet of Things) server. The + nymea-plugins-translations, +Description: nymea.io plugin for HTTP commander + The nymea daemon is a plugin based IoT (Internet of Things) server. The server works like a translator for devices, things and services and allows them to interact. With the powerful rule engine you are able to connect any device available in the system and create individual scenes and behaviors for your environment. . - This package will install the guh.io plugin for HTTP commander + This package will install the nymea.io plugin for the HTPP commander Package: nymea-plugin-simulation diff --git a/debian/guh-plugin-httpcommander.install.in b/debian/guh-plugin-httpcommander.install.in deleted file mode 100644 index 710316ae..00000000 --- a/debian/guh-plugin-httpcommander.install.in +++ /dev/null @@ -1 +0,0 @@ -usr/lib/@DEB_HOST_MULTIARCH@/guh/plugins/libguh_devicepluginhttpcommander.so diff --git a/debian/nymea-plugin-httpcommander.install.in b/debian/nymea-plugin-httpcommander.install.in new file mode 100644 index 00000000..74e4374a --- /dev/null +++ b/debian/nymea-plugin-httpcommander.install.in @@ -0,0 +1 @@ +usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/libnymea_devicepluginhttpcommander.so diff --git a/httpcommander/devicepluginhttpcommander.h b/httpcommander/devicepluginhttpcommander.h index d9453ae1..26023ed9 100644 --- a/httpcommander/devicepluginhttpcommander.h +++ b/httpcommander/devicepluginhttpcommander.h @@ -21,8 +21,8 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef DEVICEPLUGINDHTTPCOMMANDER_H -#define DEVICEPLUGINDHTTPCOMMANDER_H +#ifndef DEVICEPLUGINHTTPCOMMANDER_H +#define DEVICEPLUGINHTTPCOMMANDER_H #include "plugin/deviceplugin.h" #include "devicemanager.h" diff --git a/httpcommander/devicepluginhttpcommander.json b/httpcommander/devicepluginhttpcommander.json index e400bc87..121f70d3 100644 --- a/httpcommander/devicepluginhttpcommander.json +++ b/httpcommander/devicepluginhttpcommander.json @@ -22,7 +22,7 @@ { "id": "020f672e-cc9a-4b74-92dd-a92a93ab1d23", "name": "url", - "displayName": "URL or IPv4 address", + "displayName": "Address", "type": "QString", "inputType": "None", "defaultValue": "https://nymea.io" @@ -30,7 +30,7 @@ { "id": "37830ea8-2249-46e6-aaca-12164928a81a", "name": "port", - "displayName": "port", + "displayName": "Port", "type": "int", "defaultValue": "443" } @@ -84,7 +84,7 @@ { "id": "1a3fcb23-931b-4ba1-b134-c49b656c76f7", "name": "url", - "displayName": "URL or IPv4 address", + "displayName": "Address", "type": "QString", "inputType": "None", "defaultValue": "https://nymea.io" diff --git a/httpcommander/translations/en_US.ts b/httpcommander/translations/4e62670c-6268-4487-8dff-cccca498731a-en_US.ts similarity index 92% rename from httpcommander/translations/en_US.ts rename to httpcommander/translations/4e62670c-6268-4487-8dff-cccca498731a-en_US.ts index 6401616d..f7f66d85 100644 --- a/httpcommander/translations/en_US.ts +++ b/httpcommander/translations/4e62670c-6268-4487-8dff-cccca498731a-en_US.ts @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/httpcommander/translations/de_DE.ts b/httpcommander/translations/de_DE.ts deleted file mode 100644 index 1552582e..00000000 --- a/httpcommander/translations/de_DE.ts +++ /dev/null @@ -1,4 +0,0 @@ - - - -