fix mock device states
This commit is contained in:
parent
baf0884a59
commit
2cb547f307
@ -165,6 +165,7 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
|
|||||||
{
|
{
|
||||||
QList<DeviceClass> deviceClasses;
|
QList<DeviceClass> deviceClasses;
|
||||||
foreach (const QJsonValue &vendorJson, m_metaData.value("vendors").toArray()) {
|
foreach (const QJsonValue &vendorJson, m_metaData.value("vendors").toArray()) {
|
||||||
|
bool broken = false;
|
||||||
VendorId vendorId = vendorJson.toObject().value("id").toString();
|
VendorId vendorId = vendorJson.toObject().value("id").toString();
|
||||||
foreach (const QJsonValue &deviceClassJson, vendorJson.toObject().value("deviceClasses").toArray()) {
|
foreach (const QJsonValue &deviceClassJson, vendorJson.toObject().value("deviceClasses").toArray()) {
|
||||||
QJsonObject jo = deviceClassJson.toObject();
|
QJsonObject jo = deviceClassJson.toObject();
|
||||||
@ -200,6 +201,13 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
|
|||||||
QList<StateType> stateTypes;
|
QList<StateType> stateTypes;
|
||||||
foreach (const QJsonValue &stateTypesJson, jo.value("stateTypes").toArray()) {
|
foreach (const QJsonValue &stateTypesJson, jo.value("stateTypes").toArray()) {
|
||||||
QJsonObject st = stateTypesJson.toObject();
|
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());
|
QVariant::Type t = QVariant::nameToType(st.value("type").toString().toLatin1().data());
|
||||||
StateType stateType(st.value("id").toString());
|
StateType stateType(st.value("id").toString());
|
||||||
stateType.setName(st.value("name").toString());
|
stateType.setName(st.value("name").toString());
|
||||||
@ -212,6 +220,13 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
|
|||||||
QList<ActionType> actionTypes;
|
QList<ActionType> actionTypes;
|
||||||
foreach (const QJsonValue &actionTypesJson, jo.value("actionTypes").toArray()) {
|
foreach (const QJsonValue &actionTypesJson, jo.value("actionTypes").toArray()) {
|
||||||
QJsonObject at = actionTypesJson.toObject();
|
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 actionType(at.value("id").toString());
|
||||||
actionType.setName(at.value("name").toString());
|
actionType.setName(at.value("name").toString());
|
||||||
actionType.setParamTypes(parseParamTypes(at.value("paramTypes").toArray()));
|
actionType.setParamTypes(parseParamTypes(at.value("paramTypes").toArray()));
|
||||||
@ -222,6 +237,13 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
|
|||||||
QList<EventType> eventTypes;
|
QList<EventType> eventTypes;
|
||||||
foreach (const QJsonValue &eventTypesJson, jo.value("eventTypes").toArray()) {
|
foreach (const QJsonValue &eventTypesJson, jo.value("eventTypes").toArray()) {
|
||||||
QJsonObject et = eventTypesJson.toObject();
|
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 eventType(et.value("id").toString());
|
||||||
eventType.setName(et.value("name").toString());
|
eventType.setName(et.value("name").toString());
|
||||||
eventType.setParamTypes(parseParamTypes(et.value("paramTypes").toArray()));
|
eventType.setParamTypes(parseParamTypes(et.value("paramTypes").toArray()));
|
||||||
@ -229,7 +251,9 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
|
|||||||
}
|
}
|
||||||
deviceClass.setEventTypes(eventTypes);
|
deviceClass.setEventTypes(eventTypes);
|
||||||
|
|
||||||
deviceClasses.append(deviceClass);
|
if (!broken) {
|
||||||
|
deviceClasses.append(deviceClass);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deviceClasses;
|
return deviceClasses;
|
||||||
@ -482,3 +506,14 @@ bool DevicePlugin::transmitData(int delay, QList<int> rawData)
|
|||||||
}
|
}
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@ -96,6 +96,8 @@ private:
|
|||||||
|
|
||||||
QList<ParamType> parseParamTypes(const QJsonArray &array) const;
|
QList<ParamType> parseParamTypes(const QJsonArray &array) const;
|
||||||
|
|
||||||
|
QStringList verifyFields(const QStringList &fields, const QJsonObject &value) const;
|
||||||
|
|
||||||
DeviceManager *m_deviceManager;
|
DeviceManager *m_deviceManager;
|
||||||
|
|
||||||
ParamList m_config;
|
ParamList m_config;
|
||||||
|
|||||||
@ -39,12 +39,14 @@
|
|||||||
{
|
{
|
||||||
"id": "80baec19-54de-4948-ac46-31eabfaceb83",
|
"id": "80baec19-54de-4948-ac46-31eabfaceb83",
|
||||||
"name": "Dummy int state",
|
"name": "Dummy int state",
|
||||||
"defaultValue": 10
|
"defaultValue": 10,
|
||||||
|
"type": "int"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "9dd6a97c-dfd1-43dc-acbd-367932742310",
|
"id": "9dd6a97c-dfd1-43dc-acbd-367932742310",
|
||||||
"name:": "Dummy boo state",
|
"name": "Dummy bool state",
|
||||||
"defaultValue": "false"
|
"defaultValue": false,
|
||||||
|
"type": "bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"eventTypes": [
|
"eventTypes": [
|
||||||
@ -125,12 +127,14 @@
|
|||||||
{
|
{
|
||||||
"id": "80baec19-54de-4948-ac46-31eabfaceb83",
|
"id": "80baec19-54de-4948-ac46-31eabfaceb83",
|
||||||
"name": "Dummy int state",
|
"name": "Dummy int state",
|
||||||
"defaultValue": 10
|
"defaultValue": 10,
|
||||||
|
"type": "int"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "9dd6a97c-dfd1-43dc-acbd-367932742310",
|
"id": "9dd6a97c-dfd1-43dc-acbd-367932742310",
|
||||||
"name:": "Dummy bool state",
|
"name": "Dummy bool state",
|
||||||
"defaultValue": "false"
|
"defaultValue": false,
|
||||||
|
"type": "bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"eventTypes": [
|
"eventTypes": [
|
||||||
|
|||||||
Reference in New Issue
Block a user