diff --git a/debian/control b/debian/control index ab8e6238..b406ce15 100644 --- a/debian/control +++ b/debian/control @@ -396,6 +396,15 @@ Description: nymea integration plugin for myStrom devices This package will add support for myStrom devices to nymea. +Package: nymea-plugin-nanoleaf +Architecture: any +Depends: ${shlibs:Depends}, + ${misc:Depends}, +Conflicts: nymea-plugins-translations (< 1.0.1) +Description: nymea integration plugin for nanoleaf + This package contains the nymea integration plugin for nanoleaf devices. + + Package: nymea-plugin-neatobotvac Architecture: any Depends: ${shlibs:Depends}, @@ -417,15 +426,6 @@ Description: nymea integration plugin for netatmo This package contains the nymea integration plugin for the netatmo weather station. -Package: nymea-plugin-nanoleaf -Architecture: any -Depends: ${shlibs:Depends}, - ${misc:Depends}, -Conflicts: nymea-plugins-translations (< 1.0.1) -Description: nymea integration plugin for nanoleaf - This package contains the nymea integration plugin for nanoleaf devices. - - Package: nymea-plugin-networkdetector Architecture: any Depends: ${shlibs:Depends}, @@ -436,6 +436,14 @@ Description: nymea integration plugin for networkdetector network devices via basic networking mechanisms (ARP, ICMP..). +Package: nymea-plugin-notifyevents +Architecture: any +Depends: ${shlibs:Depends}, + ${misc:Depends}, +Description: nymea integration plugin for Notify.Events + This package contains the nymea integration plugin for Notify.Events. + + Package: nymea-plugin-nuki Architecture: any Depends: ${shlibs:Depends}, diff --git a/debian/nymea-plugin-notifyevents.install.in b/debian/nymea-plugin-notifyevents.install.in new file mode 100644 index 00000000..699baf1b --- /dev/null +++ b/debian/nymea-plugin-notifyevents.install.in @@ -0,0 +1,2 @@ +usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/libnymea_integrationpluginnotifyevents.so +notifyevents/translations/*qm usr/share/nymea/translations/ diff --git a/notifyevents/README.md b/notifyevents/README.md new file mode 100644 index 00000000..2ed38efc --- /dev/null +++ b/notifyevents/README.md @@ -0,0 +1,14 @@ +# Notify.Events + +This plugin allows to send messages to the Notify.Events service which in turn allows to distribute +the messages to various receivers, such as instant messengers, email, push notifications and more. + +## Requirements + +First go to Notify.Events and sign up. Create a new channel. In the channel, add a new message source and +select nymea. Copy the token. +Set up a new Notify.Events thing in nymea, providing the token for the channel. Multiple things may be set +up to send messages to different channels. + +At this point nymea can send messages to Notify.Events which will be redistributed to all receivers configured +on Notify.Events for this channel. diff --git a/notifyevents/integrationpluginnotifyevents.cpp b/notifyevents/integrationpluginnotifyevents.cpp new file mode 100644 index 00000000..312de450 --- /dev/null +++ b/notifyevents/integrationpluginnotifyevents.cpp @@ -0,0 +1,107 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2023, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "integrationpluginnotifyevents.h" +#include "plugininfo.h" + +#include + +#include +#include + +IntegrationPluginNotfyEvents::IntegrationPluginNotfyEvents(QObject* parent): IntegrationPlugin (parent) +{ +} + +IntegrationPluginNotfyEvents::~IntegrationPluginNotfyEvents() +{ + +} + +void IntegrationPluginNotfyEvents::setupThing(ThingSetupInfo *info) +{ + info->finish(Thing::ThingErrorNoError); +} + +void IntegrationPluginNotfyEvents::executeAction(ThingActionInfo *info) +{ + Thing *thing = info->thing(); + Action action = info->action(); + + qCDebug(dcNotifyEvents()) << "Executing action" << action.actionTypeId() << "for" << thing->name() << thing->id().toString(); + + QString token = thing->paramValue(notifyEventsThingTokenParamTypeId).toString(); + QString title = action.param(notifyEventsNotifyActionTitleParamTypeId).value().toString(); + QString body = action.param(notifyEventsNotifyActionBodyParamTypeId).value().toString(); + + QUrlQuery query; + query.addQueryItem("title", title); + query.addQueryItem("content", body); + query.addQueryItem("level", "info"); + query.addQueryItem("priority", "normal"); + + QString url = QString("https://notify.events/api/v1/channel/source/%1/execute").arg(token); + QNetworkRequest request((QUrl(url))); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + + qCDebug(dcNotifyEvents()) << "Sending notification" << request.url().toString() << query.toString(); + foreach (const QByteArray &headerName, request.rawHeaderList()) { + qCDebug(dcNotifyEvents()) << "Header:" << headerName << request.rawHeader(headerName); + } +// QNetworkReply *reply = hardwareManager()->networkManager()->post(request, QJsonDocument::fromVariant(data).toJson(QJsonDocument::Compact)); + QNetworkReply *reply = hardwareManager()->networkManager()->post(request, query.toString().toUtf8()); + connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); + connect(reply, &QNetworkReply::finished, info, [reply, info]{ + if (reply->error() != QNetworkReply::NoError) { + qCWarning(dcNotifyEvents()) << "Notify.Events message sending failed for" << info->thing()->name() << info->thing()->id() << reply->errorString() << reply->error(); + emit info->finish(Thing::ThingErrorHardwareNotAvailable); + return; + } + + QByteArray data = reply->readAll(); + + QJsonParseError error; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error); + if (error.error != QJsonParseError::NoError) { + qCWarning(dcNotifyEvents()) << "Error reading reply from server for" << info->thing()->name() << info->thing()->id().toString() << error.errorString(); + qCWarning(dcNotifyEvents()) << qUtf8Printable(data); + info->finish(Thing::ThingErrorHardwareFailure); + return; + } + + QVariantMap replyMap = jsonDoc.toVariant().toMap(); + qDebug(dcNotifyEvents()) << qUtf8Printable(jsonDoc.toJson()); + + + qCDebug(dcNotifyEvents()) << "Message sent successfully"; + info->finish(Thing::ThingErrorNoError); + }); +} + diff --git a/notifyevents/integrationpluginnotifyevents.h b/notifyevents/integrationpluginnotifyevents.h new file mode 100644 index 00000000..e7ca7154 --- /dev/null +++ b/notifyevents/integrationpluginnotifyevents.h @@ -0,0 +1,53 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2023, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef INTEGRATIONPLUGINNOTIFYEVENTS_H +#define INTEGRATIONPLUGINNOTIFYEVENTS_H + +#include + +#include "extern-plugininfo.h" + +class IntegrationPluginNotfyEvents: public IntegrationPlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "io.nymea.IntegrationPlugin" FILE "integrationpluginnotifyevents.json") + Q_INTERFACES(IntegrationPlugin) + +public: + explicit IntegrationPluginNotfyEvents(QObject *parent = nullptr); + ~IntegrationPluginNotfyEvents() override; + + void setupThing(ThingSetupInfo *info) override; + void executeAction(ThingActionInfo *info) override; +}; + +#endif diff --git a/notifyevents/integrationpluginnotifyevents.json b/notifyevents/integrationpluginnotifyevents.json new file mode 100644 index 00000000..bf9cd14a --- /dev/null +++ b/notifyevents/integrationpluginnotifyevents.json @@ -0,0 +1,70 @@ +{ + "displayName": "Notify.Events", + "name": "notifyEvents", + "id": "9f3eb18a-eb59-433f-9d03-cc974756fd21", + "vendors": [ + { + "displayName": "Notify.Events", + "name": "notifyEvents", + "id": "6089baa5-e61a-41f0-abe1-a283c6dce316", + "thingClasses": [ + { + "id": "e9276f0b-4194-4c4f-b0c1-b696fa15e6ff", + "name": "notifyEvents", + "displayName": "Notify.Events", + "createMethods": ["user"], + "interfaces": ["notifications"], + "paramTypes": [ + { + "id": "643a76de-d5ad-43f3-a40d-7c215eea845b", + "name": "token", + "displayName": "token", + "type": "QString" + } + ], + "actionTypes": [ + { + "id": "aa3ec7aa-4490-49e0-91aa-0b0891beb316", + "name": "notify", + "displayName": "Send notification", + "paramTypes": [ + { + "id": "98135099-2236-4456-99ce-81b106381430", + "name": "title", + "displayName": "Title", + "type": "QString", + "inputType": "TextLine", + "defaultValue": "" + }, + { + "id": "394c75d3-9a9a-4da3-8729-e93be0a86813", + "name": "body", + "displayName": "Body", + "type": "QString", + "inputType": "TextArea", + "defaultValue": "" + }, + { + "id": "2b08b93a-95b7-418e-b9df-e446c3de65ae", + "name": "level", + "displayName": "Level", + "type": "QString", + "allowedValues": ["verbose", "info", "notice", "warning", "error", "success"], + "defaultValue": "info" + }, + { + "id": "5e0568bf-f9f4-4289-a69f-52153c655b25", + "name": "priority", + "displayName": "Priority", + "type": "QString", + "allowedValues": ["lowest", "low", "normal", "high", "highest"], + "defaultValue": "normal" + } + ] + } + ] + } + ] + } + ] +} diff --git a/notifyevents/meta.json b/notifyevents/meta.json new file mode 100644 index 00000000..50f2d0e3 --- /dev/null +++ b/notifyevents/meta.json @@ -0,0 +1,14 @@ +{ + "title": "Notfiy.Events", + "tagline": "Send notifictions via Notify.Events.", + "icon": "notifyevents.png", + "stability": "consumer", + "offline": false, + "technologies": [ + "cloud" + ], + "categories": [ + "online-service", + "notification" + ] +} diff --git a/notifyevents/notifyevents.png b/notifyevents/notifyevents.png new file mode 100644 index 00000000..daf682f6 Binary files /dev/null and b/notifyevents/notifyevents.png differ diff --git a/notifyevents/notifyevents.pro b/notifyevents/notifyevents.pro new file mode 100644 index 00000000..4978109a --- /dev/null +++ b/notifyevents/notifyevents.pro @@ -0,0 +1,11 @@ +include(../plugins.pri) + +QT+= network + +SOURCES += \ + integrationpluginnotifyevents.cpp + +HEADERS += \ + integrationpluginnotifyevents.h + + diff --git a/notifyevents/translations/9f3eb18a-eb59-433f-9d03-cc974756fd21-en_US.ts b/notifyevents/translations/9f3eb18a-eb59-433f-9d03-cc974756fd21-en_US.ts new file mode 100644 index 00000000..c3ddc9fd --- /dev/null +++ b/notifyevents/translations/9f3eb18a-eb59-433f-9d03-cc974756fd21-en_US.ts @@ -0,0 +1,55 @@ + + + + + notifyEvents + + + Body + The name of the ParamType (ThingClass: notifyEvents, ActionType: notify, ID: {394c75d3-9a9a-4da3-8729-e93be0a86813}) + + + + + Level + The name of the ParamType (ThingClass: notifyEvents, ActionType: notify, ID: {2b08b93a-95b7-418e-b9df-e446c3de65ae}) + + + + + + + Notify.Events + The name of the ThingClass ({e9276f0b-4194-4c4f-b0c1-b696fa15e6ff}) +---------- +The name of the vendor ({6089baa5-e61a-41f0-abe1-a283c6dce316}) +---------- +The name of the plugin notifyEvents ({9f3eb18a-eb59-433f-9d03-cc974756fd21}) + + + + + Priority + The name of the ParamType (ThingClass: notifyEvents, ActionType: notify, ID: {5e0568bf-f9f4-4289-a69f-52153c655b25}) + + + + + Send notification + The name of the ActionType ({aa3ec7aa-4490-49e0-91aa-0b0891beb316}) of ThingClass notifyEvents + + + + + Title + The name of the ParamType (ThingClass: notifyEvents, ActionType: notify, ID: {98135099-2236-4456-99ce-81b106381430}) + + + + + token + The name of the ParamType (ThingClass: notifyEvents, Type: thing, ID: {643a76de-d5ad-43f3-a40d-7c215eea845b}) + + + + diff --git a/nymea-plugins.pro b/nymea-plugins.pro index b2b754f8..94ca9d1e 100644 --- a/nymea-plugins.pro +++ b/nymea-plugins.pro @@ -45,6 +45,7 @@ PLUGIN_DIRS = \ nanoleaf \ netatmo \ networkdetector \ + notifyevents \ nuki \ mcp3008 \ onewire \