devices to things
This commit is contained in:
parent
ff477cd2c7
commit
e503c9bc8a
@ -2,12 +2,12 @@ include(../plugins.pri)
|
|||||||
|
|
||||||
QT += network
|
QT += network
|
||||||
|
|
||||||
TARGET = $$qtLibraryTarget(nymea_deviceplugindynatrace)
|
TARGET = $$qtLibraryTarget(nymea_integrationplugindynatrace)
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
deviceplugindynatrace.cpp \
|
integrationplugindynatrace.cpp \
|
||||||
ufo.cpp
|
ufo.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
deviceplugindynatrace.h \
|
integrationplugindynatrace.h \
|
||||||
ufo.h
|
ufo.h
|
||||||
|
|||||||
@ -26,8 +26,7 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "deviceplugindynatrace.h"
|
#include "integrationplugindynatrace.h"
|
||||||
#include "devices/device.h"
|
|
||||||
#include "plugininfo.h"
|
#include "plugininfo.h"
|
||||||
#include "network/networkaccessmanager.h"
|
#include "network/networkaccessmanager.h"
|
||||||
|
|
||||||
@ -36,16 +35,16 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
|
|
||||||
DevicePluginDynatrace::DevicePluginDynatrace()
|
IntegrationPluginDynatrace::IntegrationPluginDynatrace()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDynatrace::discoverDevices(DeviceDiscoveryInfo *info)
|
void IntegrationPluginDynatrace::discoverThings(ThingDiscoveryInfo *info)
|
||||||
{
|
{
|
||||||
if (info->deviceClassId() == ufoDeviceClassId) {
|
if (info->thingClassId() == ufoThingClassId) {
|
||||||
|
|
||||||
QHostInfo::lookupHost("ufo.home", this, [info, this](const QHostInfo &host){
|
QHostInfo::lookupHost("ufo.home", this, [info](const QHostInfo &host){
|
||||||
if (host.error() != QHostInfo::NoError) {
|
if (host.error() != QHostInfo::NoError) {
|
||||||
qCDebug(dcDynatrace()) << "Lookup failed:" << host.errorString();
|
qCDebug(dcDynatrace()) << "Lookup failed:" << host.errorString();
|
||||||
}
|
}
|
||||||
@ -53,30 +52,30 @@ void DevicePluginDynatrace::discoverDevices(DeviceDiscoveryInfo *info)
|
|||||||
foreach (QHostAddress address, host.addresses()) {
|
foreach (QHostAddress address, host.addresses()) {
|
||||||
qCDebug(dcDynatrace()) << "Found IP address" << address.toString();
|
qCDebug(dcDynatrace()) << "Found IP address" << address.toString();
|
||||||
|
|
||||||
DeviceDescriptor descriptor(ufoDeviceClassId, "Ufo", address.toString());
|
ThingDescriptor descriptor(ufoThingClassId, "Ufo", address.toString());
|
||||||
ParamList params;
|
ParamList params;
|
||||||
|
|
||||||
/*Device *existingDevice = myDevices().findByParams(ParamList() << Param(ufoDeviceIdParamTypeId, ""));
|
/*Thing *existingThing = myThings().findByParams(ParamList() << Param(ufoThingIdParamTypeId, ""));
|
||||||
if (existingDevice) {
|
if (existingThing) {
|
||||||
//For device re-discovery
|
//For Thing re-discovery
|
||||||
descriptor.setDeviceId(existingDevice->id());
|
descriptor.setThingId(existingthing->id());
|
||||||
}*/
|
}*/
|
||||||
params << Param(ufoDeviceHostParamTypeId, address.toString());
|
params << Param(ufoThingHostParamTypeId, address.toString());
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
info->addDeviceDescriptor(descriptor);
|
info->addThingDescriptor(descriptor);
|
||||||
}
|
}
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDynatrace::setupDevice(DeviceSetupInfo *info)
|
void IntegrationPluginDynatrace::setupThing(ThingSetupInfo *info)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (info->device()->deviceClassId() == ufoDeviceClassId) {
|
if (info->thing()->thingClassId() == ufoThingClassId) {
|
||||||
QHostAddress address = QHostAddress(info->device()->paramValue(ufoDeviceHostParamTypeId).toString());
|
QHostAddress address = QHostAddress(info->thing()->paramValue(ufoThingHostParamTypeId).toString());
|
||||||
QString id = info->device()->paramValue(ufoDeviceIdParamTypeId).toString();
|
QString id = info->thing()->paramValue(ufoThingIdParamTypeId).toString();
|
||||||
if(id.isEmpty()) { //Probably a manual device setup
|
if(id.isEmpty()) { //Probably a manual Thing setup
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("http");
|
url.setScheme("http");
|
||||||
url.setHost(address.toString());
|
url.setHost(address.toString());
|
||||||
@ -84,37 +83,37 @@ void DevicePluginDynatrace::setupDevice(DeviceSetupInfo *info)
|
|||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
||||||
connect(reply, &QNetworkReply::finished, this, [info, reply, this] {
|
connect(reply, &QNetworkReply::finished, this, [info, reply] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
info->finish(Device::DeviceErrorSetupFailed, error.errorString());
|
info->finish(Thing::ThingErrorSetupFailed, error.errorString());
|
||||||
}
|
}
|
||||||
QString id = data.toVariant().toMap().value("ufoid").toString();
|
QString id = data.toVariant().toMap().value("ufoid").toString();
|
||||||
info->device()->setParamValue(ufoDeviceIdParamTypeId, id);
|
info->thing()->setParamValue(ufoThingIdParamTypeId, id);
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Discovery device setup or devices setup caused by nymea restart
|
// Discovery Thing setup or Things setup caused by nymea restart
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDynatrace::postSetupDevice(Device *device)
|
void IntegrationPluginDynatrace::postSetupThing(Thing *thing)
|
||||||
{
|
{
|
||||||
if (device->deviceClassId() == ufoDeviceClassId) {
|
if (thing->thingClassId() == ufoThingClassId) {
|
||||||
device->setStateValue(ufoConnectedStateTypeId, true); //FIXME
|
thing->setStateValue(ufoConnectedStateTypeId, true); //FIXME
|
||||||
device->setStateValue(ufoPowerStateTypeId, false);
|
thing->setStateValue(ufoPowerStateTypeId, false);
|
||||||
device->setStateValue(ufoLogoStateTypeId, false);
|
thing->setStateValue(ufoLogoStateTypeId, false);
|
||||||
device->setStateValue(ufoEffectTopStateTypeId, "None");
|
thing->setStateValue(ufoEffectTopStateTypeId, "None");
|
||||||
device->setStateValue(ufoEffectBottomStateTypeId, "None");
|
thing->setStateValue(ufoEffectBottomStateTypeId, "None");
|
||||||
|
|
||||||
QHostAddress address = QHostAddress(device->paramValue(ufoDeviceHostParamTypeId).toString());
|
QHostAddress address = QHostAddress(thing->paramValue(ufoThingHostParamTypeId).toString());
|
||||||
Ufo *ufo = new Ufo(hardwareManager()->networkManager(), address, this);
|
Ufo *ufo = new Ufo(hardwareManager()->networkManager(), address, this);
|
||||||
m_ufoConnections.insert(device->id(), ufo);
|
m_ufoConnections.insert(thing->id(), ufo);
|
||||||
// Set all off
|
// Set all off
|
||||||
ufo->setLogo(QColor(Qt::black), QColor(Qt::black), QColor(Qt::black), QColor(Qt::black));
|
ufo->setLogo(QColor(Qt::black), QColor(Qt::black), QColor(Qt::black), QColor(Qt::black));
|
||||||
ufo->setBackgroundColor(true, true, true, true, QColor(Qt::black));
|
ufo->setBackgroundColor(true, true, true, true, QColor(Qt::black));
|
||||||
@ -123,101 +122,101 @@ void DevicePluginDynatrace::postSetupDevice(Device *device)
|
|||||||
if(!m_pluginTimer) {
|
if(!m_pluginTimer) {
|
||||||
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(60);
|
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(60);
|
||||||
connect(m_pluginTimer, &PluginTimer::timeout, this, [this]() {
|
connect(m_pluginTimer, &PluginTimer::timeout, this, [this]() {
|
||||||
//TODO check if device is reachable
|
//TODO check if Thing is reachable
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDynatrace::executeAction(DeviceActionInfo *info)
|
void IntegrationPluginDynatrace::executeAction(ThingActionInfo *info)
|
||||||
{
|
{
|
||||||
Device *device = info->device();
|
Thing *thing = info->thing();
|
||||||
Action action = info->action();
|
Action action = info->action();
|
||||||
|
|
||||||
if (device->deviceClassId() == ufoDeviceClassId) {
|
if (thing->thingClassId() == ufoThingClassId) {
|
||||||
Ufo *ufo = m_ufoConnections.value(device->id());
|
Ufo *ufo = m_ufoConnections.value(thing->id());
|
||||||
if (!ufo)
|
if (!ufo)
|
||||||
return;
|
return;
|
||||||
if (action.actionTypeId() == ufoLogoActionTypeId) {
|
if (action.actionTypeId() == ufoLogoActionTypeId) {
|
||||||
bool power = action.param(ufoLogoActionLogoParamTypeId).value().toBool();
|
bool power = action.param(ufoLogoActionLogoParamTypeId).value().toBool();
|
||||||
device->setStateValue(ufoLogoStateTypeId, power);
|
thing->setStateValue(ufoLogoStateTypeId, power);
|
||||||
if (power) {
|
if (power) {
|
||||||
int brightness = device->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
int brightness = thing->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
||||||
QColor color = QColor(device->stateValue(ufoLogoColorStateTypeId).toString());
|
QColor color = QColor(thing->stateValue(ufoLogoColorStateTypeId).toString());
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
ufo->setLogo(color, color, color, color);
|
ufo->setLogo(color, color, color, color);
|
||||||
} else {
|
} else {
|
||||||
ufo->setLogo(QColor(Qt::black), QColor(Qt::black), QColor(Qt::black), QColor(Qt::black));
|
ufo->setLogo(QColor(Qt::black), QColor(Qt::black), QColor(Qt::black), QColor(Qt::black));
|
||||||
}
|
}
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
||||||
} else if (action.actionTypeId() == ufoPowerActionTypeId) {
|
} else if (action.actionTypeId() == ufoPowerActionTypeId) {
|
||||||
bool power = action.param(ufoPowerActionPowerParamTypeId).value().toBool();
|
bool power = action.param(ufoPowerActionPowerParamTypeId).value().toBool();
|
||||||
device->setStateValue(ufoPowerStateTypeId, power);
|
thing->setStateValue(ufoPowerStateTypeId, power);
|
||||||
if (power) {
|
if (power) {
|
||||||
int brightness = device->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
int brightness = thing->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
||||||
QColor color = QColor(device->stateValue(ufoColorStateTypeId).toString());
|
QColor color = QColor(thing->stateValue(ufoColorStateTypeId).toString());
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
device->setStateValue(ufoLogoStateTypeId, true);
|
thing->setStateValue(ufoLogoStateTypeId, true);
|
||||||
ufo->setLogo(color, color, color, color);
|
ufo->setLogo(color, color, color, color);
|
||||||
ufo->setBackgroundColor(true, true, true, true, color);
|
ufo->setBackgroundColor(true, true, true, true, color);
|
||||||
device->setStateValue(ufoEffectTopStateTypeId, "None");
|
thing->setStateValue(ufoEffectTopStateTypeId, "None");
|
||||||
device->setStateValue(ufoEffectBottomStateTypeId, "None");
|
thing->setStateValue(ufoEffectBottomStateTypeId, "None");
|
||||||
device->setStateValue(ufoLogoColorStateTypeId, color);
|
thing->setStateValue(ufoLogoColorStateTypeId, color);
|
||||||
device->setStateValue(ufoTopColorStateTypeId, color);
|
thing->setStateValue(ufoTopColorStateTypeId, color);
|
||||||
device->setStateValue(ufoBottomColorStateTypeId, color);
|
thing->setStateValue(ufoBottomColorStateTypeId, color);
|
||||||
} else {
|
} else {
|
||||||
ufo->setLogo(QColor(Qt::black), QColor(Qt::black), QColor(Qt::black), QColor(Qt::black));
|
ufo->setLogo(QColor(Qt::black), QColor(Qt::black), QColor(Qt::black), QColor(Qt::black));
|
||||||
device->setStateValue(ufoLogoStateTypeId, false);
|
thing->setStateValue(ufoLogoStateTypeId, false);
|
||||||
ufo->setBackgroundColor(true, true, true, true, QColor(Qt::black));
|
ufo->setBackgroundColor(true, true, true, true, QColor(Qt::black));
|
||||||
device->setStateValue(ufoEffectTopStateTypeId, "None");
|
thing->setStateValue(ufoEffectTopStateTypeId, "None");
|
||||||
device->setStateValue(ufoEffectBottomStateTypeId, "None");
|
thing->setStateValue(ufoEffectBottomStateTypeId, "None");
|
||||||
}
|
}
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
||||||
} else if (action.actionTypeId() == ufoBrightnessActionTypeId) {
|
} else if (action.actionTypeId() == ufoBrightnessActionTypeId) {
|
||||||
int brightness = action.param(ufoBrightnessActionBrightnessParamTypeId).value().toInt();
|
int brightness = action.param(ufoBrightnessActionBrightnessParamTypeId).value().toInt();
|
||||||
device->setStateValue(ufoBrightnessStateTypeId, brightness);
|
thing->setStateValue(ufoBrightnessStateTypeId, brightness);
|
||||||
QColor color = QColor(device->stateValue(ufoColorStateTypeId).toString());
|
QColor color = QColor(thing->stateValue(ufoColorStateTypeId).toString());
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
if (device->stateValue(ufoLogoStateTypeId).toBool()) {
|
if (thing->stateValue(ufoLogoStateTypeId).toBool()) {
|
||||||
ufo->setLogo(color, color, color, color);
|
ufo->setLogo(color, color, color, color);
|
||||||
}
|
}
|
||||||
ufo->setBackgroundColor(true, false, true, false, color);
|
ufo->setBackgroundColor(true, false, true, false, color);
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
} else if (action.actionTypeId() == ufoColorActionTypeId) {
|
} else if (action.actionTypeId() == ufoColorActionTypeId) {
|
||||||
QColor color = QColor(action.param(ufoColorActionColorParamTypeId).value().toString());
|
QColor color = QColor(action.param(ufoColorActionColorParamTypeId).value().toString());
|
||||||
int brightness = device->stateValue(ufoBrightnessStateTypeId).toInt();
|
int brightness = thing->stateValue(ufoBrightnessStateTypeId).toInt();
|
||||||
device->setStateValue(ufoColorStateTypeId, color);
|
thing->setStateValue(ufoColorStateTypeId, color);
|
||||||
device->setStateValue(ufoLogoColorStateTypeId, color);
|
thing->setStateValue(ufoLogoColorStateTypeId, color);
|
||||||
device->setStateValue(ufoTopColorStateTypeId, color);
|
thing->setStateValue(ufoTopColorStateTypeId, color);
|
||||||
device->setStateValue(ufoBottomColorStateTypeId, color);
|
thing->setStateValue(ufoBottomColorStateTypeId, color);
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
if (device->stateValue(ufoLogoStateTypeId).toBool()) {
|
if (thing->stateValue(ufoLogoStateTypeId).toBool()) {
|
||||||
ufo->setLogo(color, color, color, color);
|
ufo->setLogo(color, color, color, color);
|
||||||
}
|
}
|
||||||
ufo->setBackgroundColor(true, false, true, false, color);
|
ufo->setBackgroundColor(true, false, true, false, color);
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
} else if (action.actionTypeId() == ufoColorTemperatureActionTypeId) {
|
} else if (action.actionTypeId() == ufoColorTemperatureActionTypeId) {
|
||||||
int mired= device->stateValue(ufoColorTemperatureActionColorTemperatureParamTypeId).toInt();
|
int mired= thing->stateValue(ufoColorTemperatureActionColorTemperatureParamTypeId).toInt();
|
||||||
device->setStateValue(ufoColorTemperatureStateTypeId, mired);
|
thing->setStateValue(ufoColorTemperatureStateTypeId, mired);
|
||||||
int brightness = device->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
int brightness = thing->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
||||||
QColor color(Qt::white);
|
QColor color(Qt::white);
|
||||||
color.setBlue(static_cast<int>((mired-153)*0.73));
|
color.setBlue(static_cast<int>((mired-153)*0.73));
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
if (device->stateValue(ufoLogoStateTypeId).toBool()) {
|
if (thing->stateValue(ufoLogoStateTypeId).toBool()) {
|
||||||
ufo->setLogo(color, color, color, color);
|
ufo->setLogo(color, color, color, color);
|
||||||
}
|
}
|
||||||
device->setStateValue(ufoColorStateTypeId, color);
|
thing->setStateValue(ufoColorStateTypeId, color);
|
||||||
device->setStateValue(ufoLogoColorStateTypeId, color);
|
thing->setStateValue(ufoLogoColorStateTypeId, color);
|
||||||
device->setStateValue(ufoTopColorStateTypeId, color);
|
thing->setStateValue(ufoTopColorStateTypeId, color);
|
||||||
device->setStateValue(ufoBottomColorStateTypeId, color);
|
thing->setStateValue(ufoBottomColorStateTypeId, color);
|
||||||
ufo->setBackgroundColor(true, false, true, false, color);
|
ufo->setBackgroundColor(true, false, true, false, color);
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
||||||
} else if (action.actionTypeId() == ufoEffectTopActionTypeId) {
|
} else if (action.actionTypeId() == ufoEffectTopActionTypeId) {
|
||||||
QString effect = action.param(ufoEffectTopActionEffectTopParamTypeId).value().toString();
|
QString effect = action.param(ufoEffectTopActionEffectTopParamTypeId).value().toString();
|
||||||
int brightness = device->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
int brightness = thing->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
||||||
QColor color = QColor(device->stateValue(ufoColorStateTypeId).toString());
|
QColor color = QColor(thing->stateValue(ufoColorStateTypeId).toString());
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
if (effect == "None") {
|
if (effect == "None") {
|
||||||
ufo->setBackgroundColor(true, true, false, false, color);
|
ufo->setBackgroundColor(true, true, false, false, color);
|
||||||
@ -226,11 +225,11 @@ void DevicePluginDynatrace::executeAction(DeviceActionInfo *info)
|
|||||||
} else if (effect == "Morph") {
|
} else if (effect == "Morph") {
|
||||||
ufo->startMorph(true, false, color, 250, 8);
|
ufo->startMorph(true, false, color, 250, 8);
|
||||||
}
|
}
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
} else if (action.actionTypeId() == ufoEffectBottomActionTypeId) {
|
} else if (action.actionTypeId() == ufoEffectBottomActionTypeId) {
|
||||||
QString effect = action.param(ufoEffectBottomActionEffectBottomParamTypeId).value().toString();
|
QString effect = action.param(ufoEffectBottomActionEffectBottomParamTypeId).value().toString();
|
||||||
int brightness = device->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
int brightness = thing->stateValue(ufoBrightnessActionBrightnessParamTypeId).toInt();
|
||||||
QColor color = QColor(device->stateValue(ufoColorStateTypeId).toString());
|
QColor color = QColor(thing->stateValue(ufoColorStateTypeId).toString());
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
if (effect == "None") {
|
if (effect == "None") {
|
||||||
ufo->setBackgroundColor(false, false, true, true, color);
|
ufo->setBackgroundColor(false, false, true, true, color);
|
||||||
@ -239,57 +238,57 @@ void DevicePluginDynatrace::executeAction(DeviceActionInfo *info)
|
|||||||
} else if (effect == "Morph") {
|
} else if (effect == "Morph") {
|
||||||
ufo->startMorph(false, true, color, 250, 8);
|
ufo->startMorph(false, true, color, 250, 8);
|
||||||
}
|
}
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
} else if (action.actionTypeId() == ufoLogoColorActionTypeId) {
|
} else if (action.actionTypeId() == ufoLogoColorActionTypeId) {
|
||||||
QColor color = QColor(action.param(ufoLogoColorActionLogoColorParamTypeId).value().toString());
|
QColor color = QColor(action.param(ufoLogoColorActionLogoColorParamTypeId).value().toString());
|
||||||
int brightness = device->stateValue(ufoBrightnessStateTypeId).toInt();
|
int brightness = thing->stateValue(ufoBrightnessStateTypeId).toInt();
|
||||||
device->setStateValue(ufoLogoColorStateTypeId, color);
|
thing->setStateValue(ufoLogoColorStateTypeId, color);
|
||||||
device->setStateValue(ufoLogoStateTypeId, true);
|
thing->setStateValue(ufoLogoStateTypeId, true);
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
ufo->setLogo(color, color, color, color);
|
ufo->setLogo(color, color, color, color);
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
} else if (action.actionTypeId() == ufoTopColorActionTypeId) {
|
} else if (action.actionTypeId() == ufoTopColorActionTypeId) {
|
||||||
QColor color = QColor(action.param(ufoTopColorActionTopColorParamTypeId).value().toString());
|
QColor color = QColor(action.param(ufoTopColorActionTopColorParamTypeId).value().toString());
|
||||||
int brightness = device->stateValue(ufoBrightnessStateTypeId).toInt();
|
int brightness = thing->stateValue(ufoBrightnessStateTypeId).toInt();
|
||||||
device->setStateValue(ufoTopColorStateTypeId, color);
|
thing->setStateValue(ufoTopColorStateTypeId, color);
|
||||||
device->setStateValue(ufoPowerStateTypeId, true);
|
thing->setStateValue(ufoPowerStateTypeId, true);
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
ufo->setBackgroundColor(true, false, false, false, color);
|
ufo->setBackgroundColor(true, false, false, false, color);
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
} else if (action.actionTypeId() == ufoBottomColorActionTypeId) {
|
} else if (action.actionTypeId() == ufoBottomColorActionTypeId) {
|
||||||
QColor color = QColor(action.param(ufoBottomColorActionBottomColorParamTypeId).value().toString());
|
QColor color = QColor(action.param(ufoBottomColorActionBottomColorParamTypeId).value().toString());
|
||||||
int brightness = device->stateValue(ufoBrightnessStateTypeId).toInt();
|
int brightness = thing->stateValue(ufoBrightnessStateTypeId).toInt();
|
||||||
device->setStateValue(ufoBottomColorStateTypeId, color);
|
thing->setStateValue(ufoBottomColorStateTypeId, color);
|
||||||
device->setStateValue(ufoPowerStateTypeId, true);
|
thing->setStateValue(ufoPowerStateTypeId, true);
|
||||||
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
color.setHsv(color.hue(), color.saturation(), brightness*2.55);
|
||||||
ufo->setBackgroundColor(false, false, true, false, color);
|
ufo->setBackgroundColor(false, false, true, false, color);
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcDynatrace()) << "Execute action: Unhandled actionTypeId";
|
qCWarning(dcDynatrace()) << "Execute action: Unhandled actionTypeId";
|
||||||
info->finish(Device::DeviceErrorHardwareFailure);
|
info->finish(Thing::ThingErrorHardwareFailure);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcDynatrace()) << "Execute action: Unhandled deviceClass";
|
qCWarning(dcDynatrace()) << "Execute action: Unhandled ThingClass";
|
||||||
info->finish(Device::DeviceErrorHardwareFailure);
|
info->finish(Thing::ThingErrorHardwareFailure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDynatrace::deviceRemoved(Device *device)
|
void IntegrationPluginDynatrace::thingRemoved(Thing *thing)
|
||||||
{
|
{
|
||||||
if (device->deviceClassId() == ufoDeviceClassId) {
|
if (thing->thingClassId() == ufoThingClassId) {
|
||||||
if (m_ufoConnections.contains(device->id())){
|
if (m_ufoConnections.contains(thing->id())){
|
||||||
Ufo *ufo = m_ufoConnections.take(device->id());
|
Ufo *ufo = m_ufoConnections.take(thing->id());
|
||||||
ufo->deleteLater();
|
ufo->deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myDevices().isEmpty() && m_pluginTimer) {
|
if (myThings().isEmpty() && m_pluginTimer) {
|
||||||
m_pluginTimer->deleteLater();
|
m_pluginTimer->deleteLater();
|
||||||
m_pluginTimer = nullptr;
|
m_pluginTimer = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDynatrace::getId(const QHostAddress &address)
|
void IntegrationPluginDynatrace::getId(const QHostAddress &address)
|
||||||
{
|
{
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("http");
|
url.setScheme("http");
|
||||||
@ -308,13 +307,13 @@ void DevicePluginDynatrace::getId(const QHostAddress &address)
|
|||||||
|
|
||||||
QString id = data.toVariant().toMap().value("ufoid").toString();
|
QString id = data.toVariant().toMap().value("ufoid").toString();
|
||||||
if (m_asyncSetup.contains(reply->url().host())) {
|
if (m_asyncSetup.contains(reply->url().host())) {
|
||||||
DeviceSetupInfo *info = m_asyncSetup.value(reply->url().host());
|
ThingSetupInfo *info = m_asyncSetup.value(reply->url().host());
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDynatrace::onConnectionChanged(bool connected)
|
void IntegrationPluginDynatrace::onConnectionChanged(bool connected)
|
||||||
{
|
{
|
||||||
Q_UNUSED(connected)
|
Q_UNUSED(connected)
|
||||||
}
|
}
|
||||||
@ -26,36 +26,36 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef DEVICEPLUGINDYNATRACE_H
|
#ifndef INTEGRATIONPLUGINDYNATRACE_H
|
||||||
#define DEVICEPLUGINDYNATRACE_H
|
#define INTEGRATIONPLUGINDYNATRACE_H
|
||||||
|
|
||||||
#include "plugintimer.h"
|
#include "plugintimer.h"
|
||||||
#include "devices/deviceplugin.h"
|
#include "integrations/integrationplugin.h"
|
||||||
#include "network/oauth2.h"
|
#include "network/oauth2.h"
|
||||||
#include "ufo.h"
|
#include "ufo.h"
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
class DevicePluginDynatrace : public DevicePlugin
|
class IntegrationPluginDynatrace : public IntegrationPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID "io.nymea.DevicePlugin" FILE "deviceplugindynatrace.json")
|
Q_PLUGIN_METADATA(IID "io.nymea.IntegrationPlugin" FILE "integrationplugindynatrace.json")
|
||||||
Q_INTERFACES(DevicePlugin)
|
Q_INTERFACES(IntegrationPlugin)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DevicePluginDynatrace();
|
explicit IntegrationPluginDynatrace();
|
||||||
void discoverDevices(DeviceDiscoveryInfo *info) override;
|
void discoverThings(ThingDiscoveryInfo *info) override;
|
||||||
void setupDevice(DeviceSetupInfo *info) override;
|
void setupThing(ThingSetupInfo *info) override;
|
||||||
void postSetupDevice(Device *device) override;
|
void postSetupThing(Thing *thing) override;
|
||||||
void executeAction(DeviceActionInfo *info) override;
|
void executeAction(ThingActionInfo *info) override;
|
||||||
void deviceRemoved(Device *device) override;
|
void thingRemoved(Thing *thing) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PluginTimer *m_pluginTimer = nullptr;
|
PluginTimer *m_pluginTimer = nullptr;
|
||||||
QHash<DeviceId, Ufo *> m_ufoConnections;
|
QHash<ThingId, Ufo *> m_ufoConnections;
|
||||||
QHash<QUuid, DeviceActionInfo *> m_asyncActions;
|
QHash<QUuid, ThingActionInfo *> m_asyncActions;
|
||||||
QHash<QString, DeviceSetupInfo *> m_asyncSetup;
|
QHash<QString, ThingSetupInfo *> m_asyncSetup;
|
||||||
|
|
||||||
void getId(const QHostAddress &address);
|
void getId(const QHostAddress &address);
|
||||||
|
|
||||||
@ -63,4 +63,4 @@ private slots:
|
|||||||
void onConnectionChanged(bool connected);
|
void onConnectionChanged(bool connected);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEPLUGINDYNATRACE_H
|
#endif // INTEGRATIONPLUGINDYNATRACE_H
|
||||||
@ -7,7 +7,7 @@
|
|||||||
"name": "Dynatrace",
|
"name": "Dynatrace",
|
||||||
"displayName": "Dynatrace",
|
"displayName": "Dynatrace",
|
||||||
"id": "31b402be-1562-4335-aa83-d1c1166db570",
|
"id": "31b402be-1562-4335-aa83-d1c1166db570",
|
||||||
"deviceClasses": [
|
"thingClasses": [
|
||||||
{
|
{
|
||||||
"id": "6271f010-0b0a-4f29-b894-0611bb5f3dcc",
|
"id": "6271f010-0b0a-4f29-b894-0611bb5f3dcc",
|
||||||
"name": "ufo",
|
"name": "ufo",
|
||||||
@ -30,7 +30,7 @@
|
|||||||
#define DYNATRACE_UFO_H
|
#define DYNATRACE_UFO_H
|
||||||
|
|
||||||
#include "network/networkaccessmanager.h"
|
#include "network/networkaccessmanager.h"
|
||||||
#include "devices/device.h"
|
#include "integrations/integrationplugin.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user