diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index 1dded900..7bf10680 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -165,6 +165,7 @@ QList DevicePlugin::supportedDevices() const { QList deviceClasses; foreach (const QJsonValue &vendorJson, m_metaData.value("vendors").toArray()) { + bool broken = false; VendorId vendorId = vendorJson.toObject().value("id").toString(); foreach (const QJsonValue &deviceClassJson, vendorJson.toObject().value("deviceClasses").toArray()) { QJsonObject jo = deviceClassJson.toObject(); @@ -200,6 +201,13 @@ QList DevicePlugin::supportedDevices() const QList stateTypes; foreach (const QJsonValue &stateTypesJson, jo.value("stateTypes").toArray()) { QJsonObject st = stateTypesJson.toObject(); + QStringList missingFields = verifyFields(QStringList() << "type" << "id" << "name", st); + if (!missingFields.isEmpty()) { + qWarning() << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in stateTypes" << stateTypesJson.toVariant(); + broken = true; + break; + } + QVariant::Type t = QVariant::nameToType(st.value("type").toString().toLatin1().data()); StateType stateType(st.value("id").toString()); stateType.setName(st.value("name").toString()); @@ -212,6 +220,13 @@ QList DevicePlugin::supportedDevices() const QList actionTypes; foreach (const QJsonValue &actionTypesJson, jo.value("actionTypes").toArray()) { QJsonObject at = actionTypesJson.toObject(); + QStringList missingFields = verifyFields(QStringList() << "id" << "name", at); + if (!missingFields.isEmpty()) { + qWarning() << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in actionTypes"; + broken = true; + break; + } + ActionType actionType(at.value("id").toString()); actionType.setName(at.value("name").toString()); actionType.setParamTypes(parseParamTypes(at.value("paramTypes").toArray())); @@ -222,6 +237,13 @@ QList DevicePlugin::supportedDevices() const QList eventTypes; foreach (const QJsonValue &eventTypesJson, jo.value("eventTypes").toArray()) { QJsonObject et = eventTypesJson.toObject(); + QStringList missingFields = verifyFields(QStringList() << "id" << "name", et); + if (!missingFields.isEmpty()) { + qWarning() << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in eventTypes"; + broken = true; + break; + } + EventType eventType(et.value("id").toString()); eventType.setName(et.value("name").toString()); eventType.setParamTypes(parseParamTypes(et.value("paramTypes").toArray())); @@ -229,7 +251,9 @@ QList DevicePlugin::supportedDevices() const } deviceClass.setEventTypes(eventTypes); - deviceClasses.append(deviceClass); + if (!broken) { + deviceClasses.append(deviceClass); + } } } return deviceClasses; @@ -482,3 +506,14 @@ bool DevicePlugin::transmitData(int delay, QList rawData) } return false; } + +QStringList DevicePlugin::verifyFields(const QStringList &fields, const QJsonObject &value) const +{ + QStringList ret; + foreach (const QString &field, fields) { + if (!value.contains(field)) { + ret << field; + } + } + return ret; +} diff --git a/libguh/plugin/deviceplugin.h b/libguh/plugin/deviceplugin.h index a50a168a..86495033 100644 --- a/libguh/plugin/deviceplugin.h +++ b/libguh/plugin/deviceplugin.h @@ -96,6 +96,8 @@ private: QList parseParamTypes(const QJsonArray &array) const; + QStringList verifyFields(const QStringList &fields, const QJsonObject &value) const; + DeviceManager *m_deviceManager; ParamList m_config; diff --git a/plugins/deviceplugins/mock/devicepluginmock.json b/plugins/deviceplugins/mock/devicepluginmock.json index b5180b0e..2495256c 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.json +++ b/plugins/deviceplugins/mock/devicepluginmock.json @@ -39,12 +39,14 @@ { "id": "80baec19-54de-4948-ac46-31eabfaceb83", "name": "Dummy int state", - "defaultValue": 10 + "defaultValue": 10, + "type": "int" }, { "id": "9dd6a97c-dfd1-43dc-acbd-367932742310", - "name:": "Dummy boo state", - "defaultValue": "false" + "name": "Dummy bool state", + "defaultValue": false, + "type": "bool" } ], "eventTypes": [ @@ -125,12 +127,14 @@ { "id": "80baec19-54de-4948-ac46-31eabfaceb83", "name": "Dummy int state", - "defaultValue": 10 + "defaultValue": 10, + "type": "int" }, { "id": "9dd6a97c-dfd1-43dc-acbd-367932742310", - "name:": "Dummy bool state", - "defaultValue": "false" + "name": "Dummy bool state", + "defaultValue": false, + "type": "bool" } ], "eventTypes": [