diff --git a/dynatrace/integrationplugindynatrace.cpp b/dynatrace/integrationplugindynatrace.cpp
index f4c95634..1dcf0d6a 100644
--- a/dynatrace/integrationplugindynatrace.cpp
+++ b/dynatrace/integrationplugindynatrace.cpp
@@ -1,30 +1,32 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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
+* 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
-* This project may also contain libraries licensed under the open source software license GNU GPL v.3.
-* 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.
+* 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 .
+* 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
+* 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 "integrationplugindynatrace.h"
#include "plugininfo.h"
@@ -54,7 +56,7 @@ void IntegrationPluginDynatrace::discoverThings(ThingDiscoveryInfo *info)
ThingDescriptor descriptor(ufoThingClassId, "Ufo", address.toString());
ParamList params;
-
+ //FIXME Rediscovery
/*Thing *existingThing = myThings().findByParams(ParamList() << Param(ufoThingIdParamTypeId, ""));
if (existingThing) {
//For Thing re-discovery
@@ -99,13 +101,16 @@ void IntegrationPluginDynatrace::setupThing(ThingSetupInfo *info)
// Discovery Thing setup or Things setup caused by nymea restart
info->finish(Thing::ThingErrorNoError);
}
+ } else {
+ qCWarning(dcDynatrace()) << "Setup thing: Unhandled ThingClassId" << info->thing()->thingClassId();
+ info->finish(Thing::ThingErrorSetupFailed);
}
}
void IntegrationPluginDynatrace::postSetupThing(Thing *thing)
{
if (thing->thingClassId() == ufoThingClassId) {
- thing->setStateValue(ufoConnectedStateTypeId, true); //FIXME
+ thing->setStateValue(ufoConnectedStateTypeId, true);
thing->setStateValue(ufoPowerStateTypeId, false);
thing->setStateValue(ufoLogoStateTypeId, false);
thing->setStateValue(ufoEffectTopStateTypeId, "None");
@@ -113,6 +118,7 @@ void IntegrationPluginDynatrace::postSetupThing(Thing *thing)
QHostAddress address = QHostAddress(thing->paramValue(ufoThingHostParamTypeId).toString());
Ufo *ufo = new Ufo(hardwareManager()->networkManager(), address, this);
+ connect(ufo, &Ufo::connectionChanged, this, &IntegrationPluginDynatrace::onConnectionChanged);
m_ufoConnections.insert(thing->id(), ufo);
// Set all off
ufo->setLogo(QColor(Qt::black), QColor(Qt::black), QColor(Qt::black), QColor(Qt::black));
@@ -122,7 +128,9 @@ void IntegrationPluginDynatrace::postSetupThing(Thing *thing)
if(!m_pluginTimer) {
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(60);
connect(m_pluginTimer, &PluginTimer::timeout, this, [this]() {
- //TODO check if Thing is reachable
+ foreach (Ufo *ufo, m_ufoConnections.values()) {
+ ufo->getId();
+ }
});
}
}
@@ -315,5 +323,9 @@ void IntegrationPluginDynatrace::getId(const QHostAddress &address)
void IntegrationPluginDynatrace::onConnectionChanged(bool connected)
{
- Q_UNUSED(connected)
+ Ufo *ufo = static_cast(sender());
+ Thing *thing = myThings().findById(m_ufoConnections.key(ufo));
+ if (!thing)
+ return;
+ thing->setStateValue(ufoConnectedStateTypeId, connected);
}
diff --git a/dynatrace/integrationplugindynatrace.h b/dynatrace/integrationplugindynatrace.h
index 98aba7b9..0b77d6e1 100644
--- a/dynatrace/integrationplugindynatrace.h
+++ b/dynatrace/integrationplugindynatrace.h
@@ -1,30 +1,32 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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
+* 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
-* This project may also contain libraries licensed under the open source software license GNU GPL v.3.
-* 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.
+* 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 .
+* 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
+* 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 INTEGRATIONPLUGINDYNATRACE_H
#define INTEGRATIONPLUGINDYNATRACE_H
diff --git a/dynatrace/ufo.cpp b/dynatrace/ufo.cpp
index b558d694..28727bca 100644
--- a/dynatrace/ufo.cpp
+++ b/dynatrace/ufo.cpp
@@ -1,34 +1,38 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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
+* 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
-* This project may also contain libraries licensed under the open source software license GNU GPL v.3.
-* 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.
+* 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 .
+* 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
+* 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 "ufo.h"
#include "extern-plugininfo.h"
+
#include
+#include
Ufo::Ufo(NetworkAccessManager *networkManager, const QHostAddress &address, QObject *parent) :
QObject(parent),
@@ -38,6 +42,37 @@ Ufo::Ufo(NetworkAccessManager *networkManager, const QHostAddress &address, QObj
}
+void Ufo::getId()
+{
+ QUrl url;
+ url.setScheme("http");
+ url.setHost(m_address.toString());
+ url.setPath("/info", QUrl::ParsingMode::TolerantMode);
+ QNetworkRequest request;
+ request.setUrl(url);
+ QNetworkReply *reply = m_networkManager->get(request);
+ connect(reply, &QNetworkReply::finished, this, [reply, this] {
+ reply->deleteLater();
+ int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ // Check HTTP status code
+ if (status != 200 || reply->error() != QNetworkReply::NoError) {
+ qCWarning(dcDynatrace()) << "Request error:" << status << reply->errorString();
+ emit connectionChanged(false);
+ return;
+ }
+ emit connectionChanged(true);
+ QJsonParseError error;
+ QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
+ if (error.error != QJsonParseError::NoError){
+ qCWarning(dcDynatrace()) << "JSON parsing error:" << error.errorString();
+ return;
+ }
+
+ QString id = data.toVariant().toMap().value("ufoid").toString();
+ emit idReceived(id);
+ });
+}
+
void Ufo::resetLogo()
{
QUrl url;
@@ -61,7 +96,6 @@ void Ufo::resetLogo()
}
emit connectionChanged(true);
});
-
}
void Ufo::setLogo(QColor led1, QColor led2, QColor led3, QColor led4)
diff --git a/dynatrace/ufo.h b/dynatrace/ufo.h
index 9f07310a..0d840ccc 100644
--- a/dynatrace/ufo.h
+++ b/dynatrace/ufo.h
@@ -1,30 +1,32 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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
+* 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
-* This project may also contain libraries licensed under the open source software license GNU GPL v.3.
-* 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.
+* 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 .
+* 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
+* 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 DYNATRACE_UFO_H
#define DYNATRACE_UFO_H
@@ -43,6 +45,7 @@ class Ufo : public QObject
public:
explicit Ufo(NetworkAccessManager *networkManager, const QHostAddress &address, QObject *parent = nullptr);
+ void getId();
void resetLogo();
void setLogo(QColor led1, QColor led2, QColor led3, QColor led4);
void initBackgroundColor(bool top, bool bottom);
@@ -53,13 +56,13 @@ public:
void startMorph(bool top, bool bottom, QColor color, int time, int speed); //time in ms, speed 0-10
void stopMorph(bool top, bool bottom);
-
private:
NetworkAccessManager *m_networkManager;
QHostAddress m_address;
signals:
void connectionChanged(bool reachable);
+ void idReceived(const QString &id);
};
#endif //DYNATRACE_UFO_H