diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp
index d9c90d0a..9062dba3 100644
--- a/libguh/devicemanager.cpp
+++ b/libguh/devicemanager.cpp
@@ -408,12 +408,15 @@ void DeviceManager::loadConfiguredDevices()
QList params;
foreach (QString paramNameString, settings.childGroups()) {
+ qDebug() << "got paramNameString" << paramNameString;
settings.beginGroup(paramNameString);
Param param(paramNameString.remove(QRegExp("Param-")));
param.setValue(settings.value("value"));
- // param.setOperand((Param::OperandType)settings.value("operand").toInt());
+ param.setOperand((Param::OperandType)settings.value("operand").toInt());
+ params.append(param);
settings.endGroup();
}
+ qDebug() << "loaded params from config" << params;
device->setParams(params);
settings.endGroup();
diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp
index b26083ea..424b662c 100644
--- a/libguh/plugin/deviceplugin.cpp
+++ b/libguh/plugin/deviceplugin.cpp
@@ -221,10 +221,13 @@ Device *DevicePlugin::findDeviceByParams(const QList ¶ms) const
foreach (Device *device, myDevices()) {
bool matching = true;
foreach (const Param ¶m, params) {
- if (device->paramValue(param.name()) == param.value()) {
- return device;
+ if (device->paramValue(param.name()) != param.value()) {
+ matching = false;
}
}
+ if (matching) {
+ return device;
+ }
}
return nullptr;
}
diff --git a/server/guhcore.cpp b/server/guhcore.cpp
index 14ca164e..0b39a049 100644
--- a/server/guhcore.cpp
+++ b/server/guhcore.cpp
@@ -47,6 +47,12 @@ GuhCore *GuhCore::instance()
return s_instance;
}
+void GuhCore::destroy()
+{
+ delete s_instance;
+ s_instance = 0;
+}
+
/*! Returns a pointer to the \l{DeviceManager} instance owned by GuhCore.*/
DeviceManager *GuhCore::deviceManager() const
{
diff --git a/server/guhcore.h b/server/guhcore.h
index e6aae63c..54d4aed2 100644
--- a/server/guhcore.h
+++ b/server/guhcore.h
@@ -35,6 +35,9 @@ class GuhCore : public QObject
public:
static GuhCore* instance();
+ // Used for testing
+ void destroy();
+
DeviceManager* deviceManager() const;
RuleEngine *ruleEngine() const;
diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp
index 9f74c840..6b41533f 100644
--- a/server/jsonrpc/jsontypes.cpp
+++ b/server/jsonrpc/jsontypes.cpp
@@ -410,7 +410,7 @@ QPair JsonTypes::validateMap(const QVariantMap &templateMap, cons
QPair JsonTypes::validateProperty(const QVariant &templateValue, const QVariant &value)
{
- qDebug() << "validating property. template:" << templateValue << "got:" << value;
+// qDebug() << "validating property. template:" << templateValue << "got:" << value;
QString strippedTemplateValue = templateValue.toString();
if (strippedTemplateValue == "variant") {
@@ -440,7 +440,7 @@ QPair JsonTypes::validateList(const QVariantList &templateList, c
for (int i = 0; i < list.count(); ++i) {
QVariant listEntry = list.at(i);
- qDebug() << "validating" << list << templateList;
+// qDebug() << "validating" << list << templateList;
QPair result = validateVariant(entryTemplate, listEntry);
if (!result.first) {
qDebug() << "List entry not matching template";
@@ -457,14 +457,14 @@ QPair JsonTypes::validateVariant(const QVariant &templateVariant,
if (templateVariant.toString().startsWith("$ref:")) {
QString refName = templateVariant.toString();
if (refName == actionRef()) {
- qDebug() << "validating action";
+// qDebug() << "validating action";
QPair result = validateMap(actionDescription(), variant.toMap());
if (!result.first) {
qDebug() << "Error validating action";
return result;
}
} else if (refName == eventRef()) {
- qDebug() << "validating event";
+// qDebug() << "validating event";
QPair result = validateMap(eventDescription(), variant.toMap());
if (!result.first) {
qDebug() << "event not valid";
diff --git a/tests/auto/testjsonrpc.cpp b/tests/auto/testjsonrpc.cpp
index f4b31f51..3d6cced4 100644
--- a/tests/auto/testjsonrpc.cpp
+++ b/tests/auto/testjsonrpc.cpp
@@ -79,6 +79,8 @@ private slots:
void removeDevice();
+ void storedDevices();
+
private:
QVariant injectAndWait(const QString &method, const QVariantMap ¶ms);
QStringList extractRefs(const QVariant &variant);
@@ -540,5 +542,39 @@ void TestJSONRPC::removeDevice()
QCOMPARE(settings.allKeys().count(), 0);
}
+void TestJSONRPC::storedDevices()
+{
+ QVariantMap params;
+ params.insert("deviceClassId", mockDeviceClassId);
+ QVariantMap deviceParams;
+ deviceParams.insert("httpport", 8888);
+ params.insert("deviceParams", deviceParams);
+ QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
+ QCOMPARE(response.toMap().value("params").toMap().value("success").toBool(), true);
+ DeviceId addedDeviceId = DeviceId(response.toMap().value("params").toMap().value("deviceId").toString());
+ QVERIFY(!addedDeviceId.isNull());
+
+ // Destroy and recreate the core instance to check if settings are loaded at startup
+ GuhCore::instance()->destroy();
+ QSignalSpy spy(GuhCore::instance()->deviceManager(), SIGNAL(loaded()));
+ spy.wait();
+ m_mockTcpServer = MockTcpServer::servers().first();
+
+
+ response = injectAndWait("Devices.GetConfiguredDevices", QVariantMap());
+
+ foreach (const QVariant device, response.toMap().value("params").toMap().value("devices").toList()) {
+ qDebug() << "found stored device" << device;
+ if (DeviceId(device.toMap().value("id").toString()) == addedDeviceId) {
+ qDebug() << "found added device" << device.toMap().value("params").toList().first();
+ QCOMPARE(device.toMap().value("params").toMap(), deviceParams);
+ }
+ }
+
+ params.clear();
+ params.insert("deviceId", addedDeviceId);
+ response = injectAndWait("Devices.RemoveConfiguredDevice", params);
+}
+
QTEST_MAIN(TestJSONRPC)
#include "testjsonrpc.moc"