make writable states more clear in plugin json
This commit is contained in:
parent
6d7984496e
commit
a6a02ba6fb
@ -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;
|
||||||
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
"name": "color",
|
"name": "color",
|
||||||
"type": "QColor",
|
"type": "QColor",
|
||||||
"defaultValue": "#000000",
|
"defaultValue": "#000000",
|
||||||
"writable": true
|
"writable": {}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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",
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
"name": "state",
|
"name": "state",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": false,
|
"defaultValue": false,
|
||||||
"writable": true
|
"writable": {}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -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,
|
||||||
"minValue": 154,
|
"writable": {
|
||||||
"maxValue": 500
|
"minValue": 154,
|
||||||
|
"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,22 +138,25 @@
|
|||||||
"name": "brightness",
|
"name": "brightness",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"unit": "Percentage",
|
"unit": "Percentage",
|
||||||
"writable": true,
|
"defaultValue": 0,
|
||||||
"minValue": 0,
|
"writable": {
|
||||||
"maxValue": 100,
|
"minValue": 0,
|
||||||
"defaultValue": 0
|
"maxValue": 100
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"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",
|
||||||
"allowedValues": [
|
"writable": {
|
||||||
"none",
|
"allowedValues": [
|
||||||
"color loop"
|
"none",
|
||||||
]
|
"color loop"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"actionTypes": [
|
"actionTypes": [
|
||||||
|
|||||||
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
"name": "power",
|
"name": "power",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": false,
|
"defaultValue": false,
|
||||||
"writable": true
|
"writable": {}
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,99 +9,98 @@ outputfile = open(sys.argv[2], "w")
|
|||||||
variableNames = []
|
variableNames = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pluginMap = json.loads(inputFile.read())
|
pluginMap = json.loads(inputFile.read())
|
||||||
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print " --> Error loading input file \"%s\"" % (sys.argv[1])
|
print " --> Error loading input file \"%s\"" % (sys.argv[1])
|
||||||
print " %s" % (e)
|
print " %s" % (e)
|
||||||
exit -1
|
exit -1
|
||||||
|
|
||||||
|
|
||||||
def out(line):
|
def out(line):
|
||||||
outputfile.write("%s\n" % line)
|
outputfile.write("%s\n" % line)
|
||||||
|
|
||||||
def extractVendors(pluginMap):
|
def extractVendors(pluginMap):
|
||||||
for vendor in pluginMap['vendors']:
|
for vendor in pluginMap['vendors']:
|
||||||
try:
|
try:
|
||||||
out("VendorId %sVendorId = VendorId(\"%s\");" % pluginMap["idName"], pluginMap["id"])
|
out("VendorId %sVendorId = VendorId(\"%s\");" % pluginMap["idName"], pluginMap["id"])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
extractDeviceClasses(vendor)
|
extractDeviceClasses(vendor)
|
||||||
|
|
||||||
|
|
||||||
def extractDeviceClasses(vendorMap):
|
def extractDeviceClasses(vendorMap):
|
||||||
for deviceClass in vendorMap["deviceClasses"]:
|
for deviceClass in vendorMap["deviceClasses"]:
|
||||||
print("have deviceclass %s" % deviceClass["deviceClassId"])
|
print("have deviceclass %s" % deviceClass["deviceClassId"])
|
||||||
try:
|
try:
|
||||||
variableName = "%sDeviceClassId" % (deviceClass["idName"])
|
variableName = "%sDeviceClassId" % (deviceClass["idName"])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
out("DeviceClassId %s = DeviceClassId(\"%s\");" % (variableName, deviceClass["deviceClassId"]))
|
out("DeviceClassId %s = DeviceClassId(\"%s\");" % (variableName, deviceClass["deviceClassId"]))
|
||||||
else:
|
else:
|
||||||
print("duplicated variable name \"%s\" for DeviceClassId %s -> skipping") % (variableName, deviceClass["deviceClassId"])
|
print("duplicated variable name \"%s\" for DeviceClassId %s -> skipping") % (variableName, deviceClass["deviceClassId"])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
extractActionTypes(deviceClass)
|
extractActionTypes(deviceClass)
|
||||||
extractStateTypes(deviceClass)
|
extractStateTypes(deviceClass)
|
||||||
extractEventTypes(deviceClass)
|
extractEventTypes(deviceClass)
|
||||||
|
|
||||||
|
|
||||||
def extractStateTypes(deviceClassMap):
|
def extractStateTypes(deviceClassMap):
|
||||||
try:
|
try:
|
||||||
for stateType in deviceClassMap["stateTypes"]:
|
for stateType in deviceClassMap["stateTypes"]:
|
||||||
try:
|
try:
|
||||||
variableName = "%sStateTypeId" % (stateType["idName"])
|
variableName = "%sStateTypeId" % (stateType["idName"])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
out("StateTypeId %s = StateTypeId(\"%s\");" % (variableName, stateType["id"]))
|
out("StateTypeId %s = StateTypeId(\"%s\");" % (variableName, stateType["id"]))
|
||||||
else:
|
else:
|
||||||
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:
|
variableNames.append(vName)
|
||||||
variableNames.append(vName)
|
out("ActionTypeId %s = ActionTypeId(\"%s\");" % (vName, stateType["id"]))
|
||||||
out("ActionTypeId %s = ActionTypeId(\"%s\");" % (vName, stateType["id"]))
|
else:
|
||||||
else:
|
print("duplicated variable name \"%s\" for ActionTypeId %s -> skipping") % (variableName, stateType["id"])
|
||||||
print("duplicated variable name \"%s\" for ActionTypeId %s -> skipping") % (variableName, stateType["id"])
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def extractActionTypes(deviceClassMap):
|
def extractActionTypes(deviceClassMap):
|
||||||
try:
|
try:
|
||||||
for actionType in deviceClassMap["actionTypes"]:
|
for actionType in deviceClassMap["actionTypes"]:
|
||||||
try:
|
try:
|
||||||
variableName = "%sActionTypeId" % (actionType["idName"])
|
variableName = "%sActionTypeId" % (actionType["idName"])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
out("ActionTypeId %s = ActionTypeId(\"%s\");" % (variableName, actionType["id"]))
|
out("ActionTypeId %s = ActionTypeId(\"%s\");" % (variableName, actionType["id"]))
|
||||||
else:
|
else:
|
||||||
print("duplicated variable name \"%s\" for ActionTypeId %s -> skipping") % (variableName, actionType["id"])
|
print("duplicated variable name \"%s\" for ActionTypeId %s -> skipping") % (variableName, actionType["id"])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def extractEventTypes(deviceClassMap):
|
def extractEventTypes(deviceClassMap):
|
||||||
try:
|
try:
|
||||||
for eventType in deviceClassMap["eventTypes"]:
|
for eventType in deviceClassMap["eventTypes"]:
|
||||||
try:
|
try:
|
||||||
variableName = "%sEventTypeId" % (eventType["idName"])
|
variableName = "%sEventTypeId" % (eventType["idName"])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
out("EventTypeId %s = EventTypeId(\"%s\");" % (variableName, eventType["id"]))
|
out("EventTypeId %s = EventTypeId(\"%s\");" % (variableName, eventType["id"]))
|
||||||
else:
|
else:
|
||||||
print("duplicated variable name \"%s\" for EventTypeId %s -> skipping") % (variableName, eventType["id"])
|
print("duplicated variable name \"%s\" for EventTypeId %s -> skipping") % (variableName, eventType["id"])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
print " --> generate plugininfo.h"
|
print " --> generate plugininfo.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user