make writable states more clear in plugin json

pull/135/head
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);
// create ActionType if this StateType is writable
if (st.value("writable").toBool()) {
if (st.contains("writable")) {
ActionType actionType(st.value("id").toString());
actionType.setName("set " + st.value("name").toString());
// Note: fields already checked in StateType
ParamType paramType(st.value("name").toString(), t, st.value("defaultValue").toVariant());
if (st.contains("allowedValues")) {
if (st.value("writable").toObject().contains("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());
}
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.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);
actionTypes.append(actionType);
}
@ -401,26 +402,7 @@ QList<ParamType> DevicePlugin::parseParamTypes(const QJsonArray &array) const
}
// set the input type if there is any
if (pt.contains("inputType")) {
QString inputTypeString = 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);
}
paramType.setInputType(inputTypeStringToInputType(pt.value("inputType").toString()));
}
// set the unit if there is any
@ -736,3 +718,27 @@ Types::Unit DevicePlugin::unitStringToUnit(const QString &unitString) const
}
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;
Types::Unit unitStringToUnit(const QString &unitString) const;
Types::InputType inputTypeStringToInputType(const QString &inputType) const;
DeviceManager *m_deviceManager;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,99 +9,98 @@ outputfile = open(sys.argv[2], "w")
variableNames = []
try:
pluginMap = json.loads(inputFile.read())
pluginMap = json.loads(inputFile.read())
except ValueError as e:
print " --> Error loading input file \"%s\"" % (sys.argv[1])
print " %s" % (e)
exit -1
print " --> Error loading input file \"%s\"" % (sys.argv[1])
print " %s" % (e)
exit -1
def out(line):
outputfile.write("%s\n" % line)
outputfile.write("%s\n" % line)
def extractVendors(pluginMap):
for vendor in pluginMap['vendors']:
try:
out("VendorId %sVendorId = VendorId(\"%s\");" % pluginMap["idName"], pluginMap["id"])
except:
pass
extractDeviceClasses(vendor)
for vendor in pluginMap['vendors']:
try:
out("VendorId %sVendorId = VendorId(\"%s\");" % pluginMap["idName"], pluginMap["id"])
except:
pass
extractDeviceClasses(vendor)
def extractDeviceClasses(vendorMap):
for deviceClass in vendorMap["deviceClasses"]:
print("have deviceclass %s" % deviceClass["deviceClassId"])
try:
variableName = "%sDeviceClassId" % (deviceClass["idName"])
if not variableName in variableNames:
variableNames.append(variableName)
out("DeviceClassId %s = DeviceClassId(\"%s\");" % (variableName, deviceClass["deviceClassId"]))
else:
print("duplicated variable name \"%s\" for DeviceClassId %s -> skipping") % (variableName, deviceClass["deviceClassId"])
except:
pass
extractActionTypes(deviceClass)
extractStateTypes(deviceClass)
extractEventTypes(deviceClass)
for deviceClass in vendorMap["deviceClasses"]:
print("have deviceclass %s" % deviceClass["deviceClassId"])
try:
variableName = "%sDeviceClassId" % (deviceClass["idName"])
if not variableName in variableNames:
variableNames.append(variableName)
out("DeviceClassId %s = DeviceClassId(\"%s\");" % (variableName, deviceClass["deviceClassId"]))
else:
print("duplicated variable name \"%s\" for DeviceClassId %s -> skipping") % (variableName, deviceClass["deviceClassId"])
except:
pass
extractActionTypes(deviceClass)
extractStateTypes(deviceClass)
extractEventTypes(deviceClass)
def extractStateTypes(deviceClassMap):
try:
for stateType in deviceClassMap["stateTypes"]:
try:
variableName = "%sStateTypeId" % (stateType["idName"])
if not variableName in variableNames:
variableNames.append(variableName)
out("StateTypeId %s = StateTypeId(\"%s\");" % (variableName, stateType["id"]))
else:
print("duplicated variable name \"%s\" for StateTypeId %s -> skipping") % (variableName, stateType["id"])
# create ActionTypeId if the state is writable
if 'writable' in stateType:
if stateType['writable'] == True:
print("create ActionTypeId for StateType %s" % stateType["id"])
vName = "%sActionTypeId" % (stateType["idName"])
if not vName in variableNames:
variableNames.append(vName)
out("ActionTypeId %s = ActionTypeId(\"%s\");" % (vName, stateType["id"]))
else:
print("duplicated variable name \"%s\" for ActionTypeId %s -> skipping") % (variableName, stateType["id"])
except:
pass
except:
pass
try:
for stateType in deviceClassMap["stateTypes"]:
try:
variableName = "%sStateTypeId" % (stateType["idName"])
if not variableName in variableNames:
variableNames.append(variableName)
out("StateTypeId %s = StateTypeId(\"%s\");" % (variableName, stateType["id"]))
else:
print("duplicated variable name \"%s\" for StateTypeId %s -> skipping") % (variableName, stateType["id"])
# create ActionTypeId if the state is writable
if 'writable' in stateType:
print("create ActionTypeId for StateType %s" % stateType["id"])
vName = "%sActionTypeId" % (stateType["idName"])
if not vName in variableNames:
variableNames.append(vName)
out("ActionTypeId %s = ActionTypeId(\"%s\");" % (vName, stateType["id"]))
else:
print("duplicated variable name \"%s\" for ActionTypeId %s -> skipping") % (variableName, stateType["id"])
except:
pass
except:
pass
def extractActionTypes(deviceClassMap):
try:
for actionType in deviceClassMap["actionTypes"]:
try:
variableName = "%sActionTypeId" % (actionType["idName"])
if not variableName in variableNames:
variableNames.append(variableName)
out("ActionTypeId %s = ActionTypeId(\"%s\");" % (variableName, actionType["id"]))
else:
print("duplicated variable name \"%s\" for ActionTypeId %s -> skipping") % (variableName, actionType["id"])
except:
pass
except:
pass
try:
for actionType in deviceClassMap["actionTypes"]:
try:
variableName = "%sActionTypeId" % (actionType["idName"])
if not variableName in variableNames:
variableNames.append(variableName)
out("ActionTypeId %s = ActionTypeId(\"%s\");" % (variableName, actionType["id"]))
else:
print("duplicated variable name \"%s\" for ActionTypeId %s -> skipping") % (variableName, actionType["id"])
except:
pass
except:
pass
def extractEventTypes(deviceClassMap):
try:
for eventType in deviceClassMap["eventTypes"]:
try:
variableName = "%sEventTypeId" % (eventType["idName"])
if not variableName in variableNames:
variableNames.append(variableName)
out("EventTypeId %s = EventTypeId(\"%s\");" % (variableName, eventType["id"]))
else:
print("duplicated variable name \"%s\" for EventTypeId %s -> skipping") % (variableName, eventType["id"])
except:
pass
except:
pass
try:
for eventType in deviceClassMap["eventTypes"]:
try:
variableName = "%sEventTypeId" % (eventType["idName"])
if not variableName in variableNames:
variableNames.append(variableName)
out("EventTypeId %s = EventTypeId(\"%s\");" % (variableName, eventType["id"]))
else:
print("duplicated variable name \"%s\" for EventTypeId %s -> skipping") % (variableName, eventType["id"])
except:
pass
except:
pass
print " --> generate plugininfo.h"