parent
e3fb32f0c4
commit
ce123f9352
@ -370,6 +370,7 @@ DeviceManager::DeviceError DeviceManager::setPluginConfig(const PluginId &plugin
|
||||
}
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
emit pluginConfigChanged(plugin->pluginId(), pluginConfig);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -148,6 +148,7 @@ public:
|
||||
signals:
|
||||
void loaded();
|
||||
void languageUpdated();
|
||||
void pluginConfigChanged(const PluginId &id, const ParamList &config);
|
||||
void eventTriggered(const Event &event);
|
||||
void deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value);
|
||||
void deviceRemoved(const DeviceId &deviceId);
|
||||
|
||||
@ -479,6 +479,7 @@ GuhCore::GuhCore(QObject *parent) :
|
||||
|
||||
connect(m_configuration, &GuhConfiguration::localeChanged, this, &GuhCore::onLocaleChanged);
|
||||
|
||||
connect(m_deviceManager, &DeviceManager::pluginConfigChanged, this, &GuhCore::pluginConfigChanged);
|
||||
connect(m_deviceManager, &DeviceManager::eventTriggered, this, &GuhCore::gotEvent);
|
||||
connect(m_deviceManager, &DeviceManager::deviceStateChanged, this, &GuhCore::deviceStateChanged);
|
||||
connect(m_deviceManager, &DeviceManager::deviceAdded, this, &GuhCore::deviceAdded);
|
||||
|
||||
@ -98,6 +98,7 @@ public:
|
||||
#endif
|
||||
|
||||
signals:
|
||||
void pluginConfigChanged(const PluginId &id, const ParamList &config);
|
||||
void eventTriggered(const Event &event);
|
||||
void deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value);
|
||||
void deviceRemoved(const DeviceId &deviceId);
|
||||
|
||||
@ -292,6 +292,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
params.insert("device", JsonTypes::deviceRef());
|
||||
setParams("DeviceChanged", params);
|
||||
|
||||
connect(GuhCore::instance(), &GuhCore::pluginConfigChanged, this, &DeviceHandler::pluginConfigChanged);
|
||||
connect(GuhCore::instance(), &GuhCore::deviceStateChanged, this, &DeviceHandler::deviceStateChanged);
|
||||
connect(GuhCore::instance(), &GuhCore::deviceRemoved, this, &DeviceHandler::deviceRemovedNotification);
|
||||
connect(GuhCore::instance(), &GuhCore::deviceAdded, this, &DeviceHandler::deviceAddedNotification);
|
||||
@ -620,6 +621,18 @@ JsonReply *DeviceHandler::GetStateValues(const QVariantMap ¶ms) const
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
void DeviceHandler::pluginConfigChanged(const PluginId &id, const ParamList &config)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("pluginId", id);
|
||||
QVariantMap configMap;
|
||||
foreach (const Param ¶m, config) {
|
||||
configMap.insert(param.paramTypeId().toString(), param.value());
|
||||
}
|
||||
params.insert("configuration", configMap);
|
||||
emit PluginConfigurationChanged(params);
|
||||
}
|
||||
|
||||
void DeviceHandler::deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value)
|
||||
{
|
||||
QVariantMap params;
|
||||
|
||||
@ -57,12 +57,15 @@ public:
|
||||
Q_INVOKABLE JsonReply *GetStateValues(const QVariantMap ¶ms) const;
|
||||
|
||||
signals:
|
||||
void PluginConfigurationChanged(const QVariantMap ¶ms);
|
||||
void StateChanged(const QVariantMap ¶ms);
|
||||
void DeviceRemoved(const QVariantMap ¶ms);
|
||||
void DeviceAdded(const QVariantMap ¶ms);
|
||||
void DeviceChanged(const QVariantMap ¶ms);
|
||||
|
||||
private slots:
|
||||
void pluginConfigChanged(const PluginId &id, const ParamList &config);
|
||||
|
||||
void deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value);
|
||||
|
||||
void deviceRemovedNotification(const QUuid &deviceId);
|
||||
|
||||
@ -59,6 +59,8 @@ private slots:
|
||||
|
||||
void stateChangeEmitsNotifications();
|
||||
|
||||
void pluginConfigChangeEmitsNotification();
|
||||
|
||||
private:
|
||||
QStringList extractRefs(const QVariant &variant);
|
||||
|
||||
@ -364,9 +366,9 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
qDebug() << "setting mock int state to 20";
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateId.toString()).arg(20)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
reply->deleteLater();
|
||||
connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
|
||||
|
||||
clientSpy.wait();
|
||||
spy.wait();
|
||||
notificationVariant = checkNotification(clientSpy, "Rules.RuleActiveChanged");
|
||||
verifyRuleError(response);
|
||||
|
||||
@ -381,7 +383,8 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
QNetworkReply *reply2 = nam.get(request2);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
reply2->deleteLater();
|
||||
connect(reply2, SIGNAL(finished()), reply2, SLOT(deleteLater()));
|
||||
|
||||
|
||||
clientSpy.wait();
|
||||
notificationVariant = checkNotification(clientSpy, "Rules.RuleActiveChanged");
|
||||
@ -502,7 +505,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
QUuid stateTypeId("80baec19-54de-4948-ac46-31eabfaceb83");
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(stateTypeId.toString()).arg(QString::number(newVal))));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
reply->deleteLater();
|
||||
connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
|
||||
|
||||
qDebug() << "Waiting for notifications";
|
||||
|
||||
@ -569,7 +572,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
newVal = 42;
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(stateTypeId.toString()).arg(newVal)));
|
||||
reply = nam.get(request);
|
||||
reply->deleteLater();
|
||||
connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
|
||||
|
||||
// Lets wait a max of 500ms for notifications
|
||||
clientSpy.wait(500);
|
||||
@ -585,6 +588,33 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toInt(), newVal);
|
||||
}
|
||||
|
||||
void TestJSONRPC::pluginConfigChangeEmitsNotification()
|
||||
{
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("enabled", true);
|
||||
QVariant response = injectAndWait("JSONRPC.SetNotificationStatus", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("enabled").toBool(), true);
|
||||
|
||||
params.clear();
|
||||
params.insert("pluginId", mockPluginId);
|
||||
QVariantList pluginParams;
|
||||
QVariantMap param1;
|
||||
param1.insert("paramTypeId", configParamIntParamTypeId);
|
||||
param1.insert("value", 42);
|
||||
pluginParams.append(param1);
|
||||
params.insert("configuration", pluginParams);
|
||||
|
||||
response = injectAndWait("Devices.SetPluginConfiguration", params);
|
||||
|
||||
qDebug() << "Waiting for notifications";
|
||||
QVERIFY(clientSpy.wait());
|
||||
|
||||
QVariantList notificationData = checkNotifications(clientSpy, "Devices.PluginConfigurationChanged");
|
||||
QCOMPARE(notificationData.first().toMap().value("notification").toString() == "Devices.PluginConfigurationChanged", true);
|
||||
}
|
||||
|
||||
#include "testjsonrpc.moc"
|
||||
|
||||
QTEST_MAIN(TestJSONRPC)
|
||||
|
||||
Reference in New Issue
Block a user