Fixes #3
This commit is contained in:
parent
b593360f6b
commit
2e8f031d74
@ -408,12 +408,15 @@ void DeviceManager::loadConfiguredDevices()
|
||||
|
||||
QList<Param> 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();
|
||||
|
||||
@ -221,10 +221,13 @@ Device *DevicePlugin::findDeviceByParams(const QList<Param> ¶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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -35,6 +35,9 @@ class GuhCore : public QObject
|
||||
public:
|
||||
static GuhCore* instance();
|
||||
|
||||
// Used for testing
|
||||
void destroy();
|
||||
|
||||
DeviceManager* deviceManager() const;
|
||||
RuleEngine *ruleEngine() const;
|
||||
|
||||
|
||||
@ -410,7 +410,7 @@ QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, cons
|
||||
|
||||
QPair<bool, QString> 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<bool, QString> 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<bool, QString> result = validateVariant(entryTemplate, listEntry);
|
||||
if (!result.first) {
|
||||
qDebug() << "List entry not matching template";
|
||||
@ -457,14 +457,14 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
|
||||
if (templateVariant.toString().startsWith("$ref:")) {
|
||||
QString refName = templateVariant.toString();
|
||||
if (refName == actionRef()) {
|
||||
qDebug() << "validating action";
|
||||
// qDebug() << "validating action";
|
||||
QPair<bool, QString> 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<bool, QString> result = validateMap(eventDescription(), variant.toMap());
|
||||
if (!result.first) {
|
||||
qDebug() << "event not valid";
|
||||
|
||||
@ -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"
|
||||
|
||||
Reference in New Issue
Block a user