nymea/tests/scripts/0001-fix-some-plugin-s-json...

95 lines
4.4 KiB
Diff

From 83d98f475710868cb5c626af43415d94520964f3 Mon Sep 17 00:00:00 2001
From: Michael Zanetti <mzanetti@kde.org>
Date: Fri, 10 Oct 2014 01:14:39 +0200
Subject: [PATCH] fix some plugin's json
---
libguh/plugin/deviceplugin.cpp | 6 ++++++
plugins/deviceplugins/lircd/devicepluginlircd.json | 2 +-
.../deviceplugins/openweathermap/devicepluginopenweathermap.json | 8 ++++----
server/jsonrpc/jsontypes.cpp | 1 +
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp
index a88fd7e..d90ea31 100644
--- a/libguh/plugin/deviceplugin.cpp
+++ b/libguh/plugin/deviceplugin.cpp
@@ -163,6 +163,7 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
deviceClass.setCreateMethods(createMethods);
deviceClass.setDiscoveryParamTypes(parseParamTypes(jo.value("discoveryParamTypes").toArray()));
+ qDebug() << "loaded deviceClass" << deviceClass.discoveryParamTypes();
QString setupMethod = jo.value("setupMethod").toString();
if (setupMethod == "pushButton") {
@@ -293,6 +294,11 @@ QList<ParamType> DevicePlugin::parseParamTypes(const QJsonArray &array) const
foreach (const QJsonValue &paramTypesJson, array) {
QJsonObject pt = paramTypesJson.toObject();
QVariant::Type t = QVariant::nameToType(pt.value("type").toString().toLatin1().data());
+ Q_ASSERT_X(t != QVariant::Invalid,
+ pluginName().toLatin1().data(),
+ QString("Invalid type %1 for param %2 in json file.")
+ .arg(pt.value("type").toString())
+ .arg(pt.value("name").toString()).toLatin1().data());
ParamType paramType(pt.value("name").toString(), t, pt.value("defaultValue").toVariant());
QVariantList allowedValues;
foreach (const QJsonValue &allowedTypesJson, pt.value("allowedValues").toArray()) {
diff --git a/plugins/deviceplugins/lircd/devicepluginlircd.json b/plugins/deviceplugins/lircd/devicepluginlircd.json
index 0f75dc9..976ab3a 100644
--- a/plugins/deviceplugins/lircd/devicepluginlircd.json
+++ b/plugins/deviceplugins/lircd/devicepluginlircd.json
@@ -23,7 +23,7 @@
"paramTypes": [
{
"name": "button",
- "type": "string"
+ "type": "QString"
},
{
"name": "repeat",
diff --git a/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.json b/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.json
index aac6f81..cdc8e1e 100644
--- a/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.json
+++ b/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.json
@@ -13,21 +13,21 @@
"discoveryParamTypes": [
{
"name": "location",
- "type": "string"
+ "type": "QString"
}
],
"paramTypes": [
{
"name": "location",
- "type": "string"
+ "type": "QString"
},
{
"name": "country",
- "type": "string"
+ "type": "QString"
},
{
"name": "id",
- "type": "string"
+ "type": "QString"
}
],
"actionTypes": [
diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp
index dc96635..cece93f 100644
--- a/server/jsonrpc/jsontypes.cpp
+++ b/server/jsonrpc/jsontypes.cpp
@@ -371,6 +371,7 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass)
}
QVariantList discoveryParamTypes;
foreach (const ParamType &paramType, deviceClass.discoveryParamTypes()) {
+ qDebug() << "packing discoverparam" << packParamType(paramType);
discoveryParamTypes.append(packParamType(paramType));
}
--
2.1.0