fix mock device states

pull/135/head
Michael Zanetti 2014-12-30 03:03:15 +01:00 committed by Michael Zanetti
parent baf0884a59
commit 2cb547f307
3 changed files with 48 additions and 7 deletions

View File

@ -165,6 +165,7 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
{
QList<DeviceClass> 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<DeviceClass> DevicePlugin::supportedDevices() const
QList<StateType> 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<DeviceClass> DevicePlugin::supportedDevices() const
QList<ActionType> 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<DeviceClass> DevicePlugin::supportedDevices() const
QList<EventType> 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<DeviceClass> 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<int> 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;
}

View File

@ -96,6 +96,8 @@ private:
QList<ParamType> parseParamTypes(const QJsonArray &array) const;
QStringList verifyFields(const QStringList &fields, const QJsonObject &value) const;
DeviceManager *m_deviceManager;
ParamList m_config;

View File

@ -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": [