make writable states more clear in plugin json

This commit is contained in:
Simon Stürz 2015-06-22 11:13:41 +02:00 committed by Michael Zanetti
parent 6d7984496e
commit a6a02ba6fb
9 changed files with 139 additions and 127 deletions

View File

@ -243,21 +243,22 @@ QList<DeviceClass> DevicePlugin::supportedDevices() const
stateTypes.append(stateType); stateTypes.append(stateType);
// create ActionType if this StateType is writable // create ActionType if this StateType is writable
if (st.value("writable").toBool()) { if (st.contains("writable")) {
ActionType actionType(st.value("id").toString()); ActionType actionType(st.value("id").toString());
actionType.setName("set " + st.value("name").toString()); actionType.setName("set " + st.value("name").toString());
// Note: fields already checked in StateType // Note: fields already checked in StateType
ParamType paramType(st.value("name").toString(), t, st.value("defaultValue").toVariant()); ParamType paramType(st.value("name").toString(), t, st.value("defaultValue").toVariant());
if (st.contains("allowedValues")) { if (st.value("writable").toObject().contains("allowedValues")) {
QVariantList allowedValues; QVariantList allowedValues;
foreach (const QJsonValue &allowedTypesJson, st.value("allowedValues").toArray()) { foreach (const QJsonValue &allowedTypesJson, st.value("writable").toObject().value("allowedValues").toArray()) {
allowedValues.append(allowedTypesJson.toVariant()); allowedValues.append(allowedTypesJson.toVariant());
} }
paramType.setAllowedValues(allowedValues); paramType.setAllowedValues(allowedValues);
} }
// states don't have input types paramType.setInputType(inputTypeStringToInputType(st.value("writable").toObject().value("inputType").toString()));
paramType.setUnit(unitStringToUnit(st.value("unit").toString())); paramType.setUnit(unitStringToUnit(st.value("unit").toString()));
paramType.setLimits(st.value("minValue").toVariant(), st.value("maxValue").toVariant()); paramType.setLimits(st.value("writable").toObject().value("minValue").toVariant(),
st.value("writable").toObject().value("maxValue").toVariant());
actionType.setParamTypes(QList<ParamType>() << paramType); actionType.setParamTypes(QList<ParamType>() << paramType);
actionTypes.append(actionType); actionTypes.append(actionType);
} }
@ -401,26 +402,7 @@ QList<ParamType> DevicePlugin::parseParamTypes(const QJsonArray &array) const
} }
// set the input type if there is any // set the input type if there is any
if (pt.contains("inputType")) { if (pt.contains("inputType")) {
QString inputTypeString = pt.value("inputType").toString(); paramType.setInputType(inputTypeStringToInputType(pt.value("inputType").toString()));
if (inputTypeString == "TextLine") {
paramType.setInputType(Types::InputTypeTextLine);
} else if (inputTypeString == "TextArea") {
paramType.setInputType(Types::InputTypeTextArea);
} else if (inputTypeString == "Password") {
paramType.setInputType(Types::InputTypePassword);
} else if (inputTypeString == "Search") {
paramType.setInputType(Types::InputTypeSearch);
} else if (inputTypeString == "Mail") {
paramType.setInputType(Types::InputTypeMail);
} else if (inputTypeString == "IPv4Address") {
paramType.setInputType(Types::InputTypeIPv4Address);
} else if (inputTypeString == "IPv6Address") {
paramType.setInputType(Types::InputTypeIPv6Address);
} else if (inputTypeString == "Url") {
paramType.setInputType(Types::InputTypeUrl);
} else if (inputTypeString == "MacAddress") {
paramType.setInputType(Types::InputTypeMacAddress);
}
} }
// set the unit if there is any // set the unit if there is any
@ -736,3 +718,27 @@ Types::Unit DevicePlugin::unitStringToUnit(const QString &unitString) const
} }
return Types::UnitNone; return Types::UnitNone;
} }
Types::InputType DevicePlugin::inputTypeStringToInputType(const QString &inputType) const
{
if (inputType == "TextLine") {
return Types::InputTypeTextLine;
} else if (inputType == "TextArea") {
return Types::InputTypeTextArea;
} else if (inputType == "Password") {
return Types::InputTypePassword;
} else if (inputType == "Search") {
return Types::InputTypeSearch;
} else if (inputType == "Mail") {
return Types::InputTypeMail;
} else if (inputType == "IPv4Address") {
return Types::InputTypeIPv4Address;
} else if (inputType == "IPv6Address") {
return Types::InputTypeIPv6Address;
} else if (inputType == "Url") {
return Types::InputTypeUrl;
} else if (inputType == "MacAddress") {
return Types::InputTypeMacAddress;
}
return Types::InputTypeNone;
}

View File

@ -113,6 +113,7 @@ private:
QStringList verifyFields(const QStringList &fields, const QJsonObject &value) const; QStringList verifyFields(const QStringList &fields, const QJsonObject &value) const;
Types::Unit unitStringToUnit(const QString &unitString) const; Types::Unit unitStringToUnit(const QString &unitString) const;
Types::InputType inputTypeStringToInputType(const QString &inputType) const;
DeviceManager *m_deviceManager; DeviceManager *m_deviceManager;

View File

@ -18,7 +18,7 @@
"name": "color", "name": "color",
"type": "QColor", "type": "QColor",
"defaultValue": "#000000", "defaultValue": "#000000",
"writable": true "writable": {}
} }
] ]
} }

View File

@ -210,7 +210,7 @@
"type": "double", "type": "double",
"unit": "DegreeCelsius", "unit": "DegreeCelsius",
"defaultValue": 0, "defaultValue": 0,
"writable": true "writable": {}
}, },
{ {
@ -373,7 +373,7 @@
"unit": "DegreeCelsius", "unit": "DegreeCelsius",
"type": "double", "type": "double",
"defaultValue": 0, "defaultValue": 0,
"writable": true "writable": {}
}, },
{ {
"id": "576da571-9a65-478f-96bf-19256c8b9ece", "id": "576da571-9a65-478f-96bf-19256c8b9ece",

View File

@ -25,7 +25,7 @@
"name": "state", "name": "state",
"type": "bool", "type": "bool",
"defaultValue": false, "defaultValue": false,
"writable": true "writable": {}
} }
] ]
}, },

View File

@ -109,7 +109,7 @@
"name": "power", "name": "power",
"type": "bool", "type": "bool",
"defaultValue": false, "defaultValue": false,
"writable": true "writable": {}
}, },
{ {
"id": "c0f4206f-f219-4f06-93c4-4ca515a56f79", "id": "c0f4206f-f219-4f06-93c4-4ca515a56f79",
@ -117,10 +117,11 @@
"name": "color temperature", "name": "color temperature",
"type": "int", "type": "int",
"unit": "Mired", "unit": "Mired",
"writable": true,
"defaultValue": 170, "defaultValue": 170,
"writable": {
"minValue": 154, "minValue": 154,
"maxValue": 500 "maxValue": 500
}
}, },
{ {
"id": "d25423e7-b924-4b20-80b6-77eecc65d089", "id": "d25423e7-b924-4b20-80b6-77eecc65d089",
@ -128,7 +129,7 @@
"name": "color", "name": "color",
"type": "QColor", "type": "QColor",
"defaultValue": "#000000", "defaultValue": "#000000",
"writable": true "writable": {}
}, },
{ {
@ -137,23 +138,26 @@
"name": "brightness", "name": "brightness",
"type": "int", "type": "int",
"unit": "Percentage", "unit": "Percentage",
"writable": true, "defaultValue": 0,
"writable": {
"minValue": 0, "minValue": 0,
"maxValue": 100, "maxValue": 100
"defaultValue": 0 }
}, },
{ {
"id": "0b7cdd8d-4db8-4183-abe2-f3c01d1c9afc", "id": "0b7cdd8d-4db8-4183-abe2-f3c01d1c9afc",
"idName": "hueEffect", "idName": "hueEffect",
"name": "effect", "name": "effect",
"type": "QString", "type": "QString",
"writable": true,
"defaultValue": "none", "defaultValue": "none",
"writable": {
"allowedValues": [ "allowedValues": [
"none", "none",
"color loop" "color loop"
] ]
} }
}
], ],
"actionTypes": [ "actionTypes": [
{ {

View File

@ -53,7 +53,7 @@
"name": "active", "name": "active",
"type": "bool", "type": "bool",
"defaultValue": false, "defaultValue": false,
"writable": true "writable": {}
}, },
{ {
"id": "cb8a89c2-dc12-4965-b047-57896058b421", "id": "cb8a89c2-dc12-4965-b047-57896058b421",
@ -61,10 +61,11 @@
"name": "value", "name": "value",
"type": "int", "type": "int",
"unit": "Percentage", "unit": "Percentage",
"minValue": 0,
"maxValue": 100,
"defaultValue": 0, "defaultValue": 0,
"writable": true "writable": {
"minValue": 0,
"maxValue": 100
}
} }
] ]
}, },
@ -121,7 +122,7 @@
"name": "power", "name": "power",
"type": "bool", "type": "bool",
"defaultValue": 0, "defaultValue": 0,
"writable": true "writable": {}
}, },
{ {
"id": "677cd9ec-c264-47ee-9d2e-d3662237792c", "id": "677cd9ec-c264-47ee-9d2e-d3662237792c",
@ -129,10 +130,11 @@
"name": "brightness", "name": "brightness",
"type": "int", "type": "int",
"unit": "Percentage", "unit": "Percentage",
"minValue": 0,
"maxValue": 100,
"defaultValue": 0, "defaultValue": 0,
"writable": true "writable": {
"minValue": 0,
"maxValue": 100
}
} }
] ]
} }

View File

@ -39,7 +39,7 @@
"name": "power", "name": "power",
"type": "bool", "type": "bool",
"defaultValue": false, "defaultValue": false,
"writable": true "writable": {}
}, },
{ {

View File

@ -58,7 +58,6 @@ def extractStateTypes(deviceClassMap):
print("duplicated variable name \"%s\" for StateTypeId %s -> skipping") % (variableName, stateType["id"]) print("duplicated variable name \"%s\" for StateTypeId %s -> skipping") % (variableName, stateType["id"])
# create ActionTypeId if the state is writable # create ActionTypeId if the state is writable
if 'writable' in stateType: if 'writable' in stateType:
if stateType['writable'] == True:
print("create ActionTypeId for StateType %s" % stateType["id"]) print("create ActionTypeId for StateType %s" % stateType["id"])
vName = "%sActionTypeId" % (stateType["idName"]) vName = "%sActionTypeId" % (stateType["idName"])
if not vName in variableNames: if not vName in variableNames: