diff --git a/guh_0.1.8_amd64.deb b/guh_0.1.8_amd64.deb new file mode 100644 index 00000000..4df38cee Binary files /dev/null and b/guh_0.1.8_amd64.deb differ diff --git a/libguh/types/statedescriptor.cpp b/libguh/types/statedescriptor.cpp index 8ffaa8fe..6e6bc3c5 100644 --- a/libguh/types/statedescriptor.cpp +++ b/libguh/types/statedescriptor.cpp @@ -87,3 +87,8 @@ bool StateDescriptor::operator !=(const State &state) const { return !(operator==(state)); } + +bool StateDescriptor::isValid() const +{ + return !m_deviceId.isNull() && !m_stateTypeId.isNull() && m_stateValue.isValid(); +} diff --git a/libguh/types/statedescriptor.h b/libguh/types/statedescriptor.h index 05246daf..44d6455e 100644 --- a/libguh/types/statedescriptor.h +++ b/libguh/types/statedescriptor.h @@ -38,6 +38,8 @@ public: QVariant stateValue() const; Types::ValueOperator operatorType() const; + bool isValid() const; + bool operator ==(const StateDescriptor &other) const; bool operator ==(const State &state) const; diff --git a/libguh1_0.1.8_amd64.deb b/libguh1_0.1.8_amd64.deb new file mode 100644 index 00000000..8448eeb1 Binary files /dev/null and b/libguh1_0.1.8_amd64.deb differ diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp index 0aa90ef8..d195857c 100644 --- a/server/jsonrpc/jsontypes.cpp +++ b/server/jsonrpc/jsontypes.cpp @@ -313,13 +313,17 @@ QVariantMap JsonTypes::packStateDescriptor(const StateDescriptor &stateDescripto QVariantMap JsonTypes::packStateEvaluator(const StateEvaluator &stateEvaluator) { QVariantMap variantMap; - variantMap.insert("stateDescriptor", packStateDescriptor(stateEvaluator.stateDescriptor())); + if (stateEvaluator.stateDescriptor().isValid()) { + variantMap.insert("stateDescriptor", packStateDescriptor(stateEvaluator.stateDescriptor())); + } QVariantList childEvaluators; foreach (const StateEvaluator &childEvaluator, stateEvaluator.childEvaluators()) { childEvaluators.append(packStateEvaluator(childEvaluator)); } - variantMap.insert("childEvaluators", childEvaluators); variantMap.insert("operator", stateOperator().at(stateEvaluator.operatorType())); + if (childEvaluators.count() > 0) { + variantMap.insert("childEvaluators", childEvaluators); + } return variantMap; } diff --git a/tests/auto/api.json.new b/tests/auto/api.json.new new file mode 100644 index 00000000..ca9f3bbc --- /dev/null +++ b/tests/auto/api.json.new @@ -0,0 +1,512 @@ +6 +{ + "methods": { + "Actions.ExecuteAction": { + "description": "Execute a single action.", + "params": { + "actionTypeId": "Uuid", + "deviceId": "Uuid", + "o:params": [ + "$ref:Param" + ] + }, + "returns": { + "deviceError": "$ref:DeviceError" + } + }, + "Actions.GetActionType": { + "description": "Get the ActionType for the given ActionTypeId", + "params": { + "actionTypeId": "Uuid" + }, + "returns": { + "deviceError": "$ref:DeviceError", + "o:actionType": { + "id": "Uuid", + "name": "Uuid", + "paramTypes": [ + "$ref:ParamType" + ] + } + } + }, + "Devices.AddConfiguredDevice": { + "description": "Add a configured device with a setupMethod of SetupMethodJustAdd. For devices with a setupMethod different than SetupMethodJustAdd, use PairDevice. Use deviceDescriptorId or deviceParams, depending on the createMethod of the device class. CreateMethodJustAdd takes the parameters you want to have with that device. CreateMethodDiscovery requires the use of a deviceDescriptorId.", + "params": { + "deviceClassId": "Uuid", + "o:deviceDescriptorId": "Uuid", + "o:deviceParams": [ + "$ref:Param" + ] + }, + "returns": { + "deviceError": "$ref:DeviceError", + "o:deviceId": "Uuid" + } + }, + "Devices.ConfirmPairing": { + "description": "Confirm an ongoing pairing. In case of SetupMethodEnterPin also provide the pin in the params.", + "params": { + "o:secret": "String", + "pairingTransactionId": "Uuid" + }, + "returns": { + "deviceError": "$ref:DeviceError", + "o:deviceId": "Uuid" + } + }, + "Devices.GetActionTypes": { + "description": "Get action types for a specified deviceClassId.", + "params": { + "deviceClassId": "Uuid" + }, + "returns": { + "actionTypes": [ + "$ref:ActionType" + ] + } + }, + "Devices.GetConfiguredDevices": { + "description": "Returns a list of configured devices.", + "params": { + }, + "returns": { + "devices": [ + "$ref:Device" + ] + } + }, + "Devices.GetDiscoveredDevices": { + "description": "Performs a device discovery and returns the results. This function may take a while to return.", + "params": { + "deviceClassId": "Uuid", + "o:discoveryParams": [ + "$ref:Param" + ] + }, + "returns": { + "deviceError": "$ref:DeviceError", + "o:deviceDescriptors": [ + "$ref:DeviceDescriptor" + ] + } + }, + "Devices.GetEventTypes": { + "description": "Get event types for a specified deviceClassId.", + "params": { + "deviceClassId": "Uuid" + }, + "returns": { + "eventTypes": [ + "$ref:EventType" + ] + } + }, + "Devices.GetPluginConfiguration": { + "description": "Get a plugin's params.", + "params": { + "pluginId": "Uuid" + }, + "returns": { + "deviceError": "$ref:DeviceError", + "o:configuration": [ + "$ref:Param" + ] + } + }, + "Devices.GetPlugins": { + "description": "Returns a list of loaded plugins.", + "params": { + }, + "returns": { + "plugins": [ + "$ref:Plugin" + ] + } + }, + "Devices.GetStateTypes": { + "description": "Get state types for a specified deviceClassId.", + "params": { + "deviceClassId": "Uuid" + }, + "returns": { + "stateTypes": [ + "$ref:StateType" + ] + } + }, + "Devices.GetStateValue": { + "description": "Get the value of the given device and the given stateType", + "params": { + "deviceId": "Uuid", + "stateTypeId": "Uuid" + }, + "returns": { + "deviceError": "$ref:DeviceError", + "o:value": "Variant" + } + }, + "Devices.GetSupportedDevices": { + "description": "Returns a list of supported Device classes, optionally filtered by vendorId.", + "params": { + "o:vendorId": "Uuid" + }, + "returns": { + "deviceClasses": [ + "$ref:DeviceClass" + ] + } + }, + "Devices.GetSupportedVendors": { + "description": "Returns a list of supported Vendors.", + "params": { + }, + "returns": { + "vendors": [ + "$ref:Vendor" + ] + } + }, + "Devices.PairDevice": { + "description": "Pair a device. Use this for DeviceClasses with a setupMethod different than SetupMethodJustAdd.Use deviceDescriptorId or deviceParams, depending on the createMethod of the device class. CreateMethodJustAdd takes the parameters you want to have with that device. CreateMethodDiscovery requires the use of a deviceDescriptorId. If success is true, the return values will contain a pairingTransactionId, a displayMessage and the setupMethod. Depending on the setupMethod you should either proceed with AddConfiguredDevice or PairDevice.", + "params": { + "deviceClassId": "Uuid", + "o:deviceDescriptorId": "Uuid", + "o:deviceParams": [ + "$ref:Param" + ] + }, + "returns": { + "deviceError": "$ref:DeviceError", + "o:displayMessage": "String", + "o:pairingTransactionId": "Uuid", + "o:setupMethod": "$ref:SetupMethod" + } + }, + "Devices.RemoveConfiguredDevice": { + "description": "Remove a device from the system.", + "params": { + "deviceId": "Uuid", + "o:removePolicyList": [ + { + "policy": "$ref:RemovePolicy", + "ruleId": "Uuid" + } + ] + }, + "returns": { + "deviceError": "$ref:DeviceError" + } + }, + "Devices.SetPluginConfiguration": { + "description": "Set a plugin's params.", + "params": { + "configuration": [ + "$ref:Param" + ], + "pluginId": "Uuid" + }, + "returns": { + "deviceError": "$ref:DeviceError" + } + }, + "JSONRPC.Introspect": { + "description": "Introspect this API.", + "params": { + }, + "returns": { + "methods": "Object", + "types": "Object" + } + }, + "JSONRPC.SetNotificationStatus": { + "description": "Enable/Disable notifications for this connections.", + "params": { + "enabled": "Bool" + }, + "returns": { + "enabled": "Bool" + } + }, + "JSONRPC.Version": { + "description": "Version of this Guh/JSONRPC interface.", + "params": { + }, + "returns": { + "protocol version": "String", + "version": "String" + } + }, + "Rules.AddRule": { + "description": "Add a rule. You can describe rules by one or many EventDesciptors and a StateEvaluator. Note that onlyone of either eventDescriptor or eventDescriptorList may be passed at a time.", + "params": { + "actions": [ + "$ref:Action" + ], + "o:eventDescriptor": "$ref:EventDescriptor", + "o:eventDescriptorList": [ + "$ref:EventDescriptor" + ], + "o:stateEvaluator": "$ref:StateEvaluator" + }, + "returns": { + "o:ruleId": "Uuid", + "ruleError": "$ref:RuleError" + } + }, + "Rules.FindRules": { + "description": "Find a list of rules containing any of the given parameters.", + "params": { + "deviceId": "Uuid" + }, + "returns": { + "ruleIds": [ + "Uuid" + ] + } + }, + "Rules.GetRuleDetails": { + "description": "Get details for the rule identified by ruleId", + "params": { + "ruleId": "Uuid" + }, + "returns": { + "rule": "$ref:Rule" + } + }, + "Rules.GetRules": { + "description": "Get all configured rules", + "params": { + }, + "returns": { + "ruleIds": [ + "Uuid" + ] + } + }, + "Rules.RemoveRule": { + "description": "Remove a rule", + "params": { + "ruleId": "Uuid" + }, + "returns": { + "ruleError": "$ref:RuleError" + } + } + }, + "notifications": { + "Devices.StateChanged": { + "description": "Emitted whenever a State of a device changes.", + "params": { + "deviceId": "Uuid", + "stateTypeId": "Uuid", + "value": "Variant" + } + }, + "Events.EventTriggered": { + "description": "Emitted whenever an Event is triggered.", + "params": { + "event": "$ref:Event" + } + } + }, + "types": { + "Action": { + "actionTypeId": "Uuid", + "deviceId": "Uuid", + "o:params": [ + "$ref:Param" + ] + }, + "ActionType": { + "id": "Uuid", + "name": "Uuid", + "paramTypes": [ + "$ref:ParamType" + ] + }, + "BasicType": [ + ], + "CreateMethod": [ + "CreateMethodUser", + "CreateMethodAuto", + "CreateMethodDiscovery" + ], + "Device": { + "deviceClassId": "Uuid", + "id": "Uuid", + "name": "String", + "params": [ + "$ref:Param" + ], + "setupComplete": "Bool" + }, + "DeviceClass": { + "actionTypes": [ + "$ref:ActionType" + ], + "createMethods": [ + "$ref:CreateMethod" + ], + "discoveryParamTypes": [ + "$ref:ParamType" + ], + "eventTypes": [ + "$ref:EventType" + ], + "id": "Uuid", + "name": "String", + "paramTypes": [ + "$ref:ParamType" + ], + "setupMethod": "$ref:SetupMethod", + "stateTypes": [ + "$ref:StateType" + ], + "vendorId": "Uuid" + }, + "DeviceDescriptor": { + "description": "String", + "id": "Uuid", + "title": "String" + }, + "DeviceError": [ + "DeviceErrorNoError", + "DeviceErrorPluginNotFound", + "DeviceErrorDeviceNotFound", + "DeviceErrorDeviceClassNotFound", + "DeviceErrorActionTypeNotFound", + "DeviceErrorStateTypeNotFound", + "DeviceErrorEventTypeNotFound", + "DeviceErrorDeviceDescriptorNotFound", + "DeviceErrorMissingParameter", + "DeviceErrorInvalidParameter", + "DeviceErrorSetupFailed", + "DeviceErrorDuplicateUuid", + "DeviceErrorCreationMethodNotSupported", + "DeviceErrorSetupMethodNotSupported", + "DeviceErrorHardwareNotAvailable", + "DeviceErrorHardwareFailure", + "DeviceErrorAsync", + "DeviceErrorDeviceInUse", + "DeviceErrorPairingTransactionIdNotFound" + ], + "Event": { + "deviceId": "Uuid", + "eventTypeId": "Uuid", + "o:params": [ + "$ref:Param" + ] + }, + "EventDescriptor": { + "deviceId": "Uuid", + "eventTypeId": "Uuid", + "o:paramDescriptors": [ + "$ref:ParamDescriptor" + ] + }, + "EventType": { + "id": "Uuid", + "name": "String", + "paramTypes": [ + "$ref:ParamType" + ] + }, + "Param": { + "name": "String", + "value": "$ref:BasicType" + }, + "ParamDescriptor": { + "name": "String", + "operator": "$ref:ValueOperator", + "value": "$ref:BasicType" + }, + "ParamType": { + "name": "String", + "o:allowedValues": [ + "Variant" + ], + "o:defaultValue": "Variant", + "o:maxValue": "Variant", + "o:minValue": "Variant", + "type": "$ref:BasicType" + }, + "Plugin": { + "id": "Uuid", + "name": "String", + "params": [ + "$ref:Param" + ] + }, + "RemovePolicy": [ + "RemovePolicyCascade", + "RemovePolicyUpdate" + ], + "Rule": { + "actions": [ + "$ref:Action" + ], + "eventDescriptors": [ + "$ref:EventDescriptor" + ], + "id": "Uuid", + "stateEvaluator": "$ref:StateEvaluator" + }, + "RuleError": [ + "RuleErrorNoError", + "RuleErrorInvalidRuleId", + "RuleErrorRuleNotFound", + "RuleErrorDeviceNotFound", + "RuleErrorEventTypeNotFound", + "RuleErrorActionTypeNotFound", + "RuleErrorInvalidParameter", + "RuleErrorMissingParameter" + ], + "SetupMethod": [ + "SetupMethodJustAdd", + "SetupMethodDisplayPin", + "SetupMethodEnterPin", + "SetupMethodPushButton" + ], + "State": { + "deviceId": "Uuid", + "stateTypeId": "Uuid", + "value": "Variant" + }, + "StateDescriptor": { + "deviceId": "Uuid", + "operator": "$ref:ValueOperator", + "stateTypeId": "Uuid", + "value": "Variant" + }, + "StateEvaluator": { + "o:childEvaluators": [ + "$ref:StateEvaluator" + ], + "o:operator": "$ref:StateOperator", + "o:stateDescriptor": "$ref:StateDescriptor" + }, + "StateOperator": [ + "StateOperatorAnd", + "StateOperatorOr" + ], + "StateType": { + "defaultValue": "Variant", + "id": "Uuid", + "name": "String", + "type": "$ref:BasicType" + }, + "ValueOperator": [ + "ValueOperatorEquals", + "ValueOperatorNotEquals", + "ValueOperatorLess", + "ValueOperatorGreater", + "ValueOperatorLessOrEqual", + "ValueOperatorGreaterOrEqual" + ], + "Vendor": { + "id": "Uuid", + "name": "String" + } + } +} diff --git a/tests/scripts/0001-fix-cmdmgr.patch b/tests/scripts/0001-fix-cmdmgr.patch new file mode 100644 index 00000000..2a1bed4f --- /dev/null +++ b/tests/scripts/0001-fix-cmdmgr.patch @@ -0,0 +1,34 @@ +From af93f794e40ebfd342d2bb0b1b050c7b2a6224f5 Mon Sep 17 00:00:00 2001 +From: Michael Zanetti +Date: Fri, 10 Oct 2014 00:19:56 +0200 +Subject: [PATCH] fix cmdmgr + +--- + tests/scripts/cmdmgr.py | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/tests/scripts/cmdmgr.py b/tests/scripts/cmdmgr.py +index da3d430..6930e06 100755 +--- a/tests/scripts/cmdmgr.py ++++ b/tests/scripts/cmdmgr.py +@@ -262,13 +262,13 @@ def add_device(): + print "Empty deviceClass. Can't continue" + return + deviceClass = get_deviceClass(deviceClassId) +- print "createmethod is", deviceClass['createMethod'] +- if deviceClass['createMethod'] == "CreateMethodUser": ++ print "createmethods are", deviceClass['createMethods'] ++ if "CreateMethodUser" in deviceClass['createMethods']: + add_configured_device(deviceClassId) +- elif deviceClass['createMethod'] == "CreateMethodDiscovery": ++ elif "CreateMethodDiscovery" in deviceClass['createMethods']: + deviceDescriptorId = discover_device(deviceClassId) + add_discovered_device(deviceClassId, deviceDescriptorId) +- elif deviceClass['createMethod'] == "CreateMethodAuto": ++ elif "CreateMethodAuto" in deviceClass['createMethods']: + print "Can't create this device manually. It'll be created automatically when hardware is discovered." + + def select_device(): +-- +2.1.0 + diff --git a/tests/scripts/0001-fix-some-plugin-s-json.patch b/tests/scripts/0001-fix-some-plugin-s-json.patch new file mode 100644 index 00000000..22fbd5ad --- /dev/null +++ b/tests/scripts/0001-fix-some-plugin-s-json.patch @@ -0,0 +1,94 @@ +From 83d98f475710868cb5c626af43415d94520964f3 Mon Sep 17 00:00:00 2001 +From: Michael Zanetti +Date: Fri, 10 Oct 2014 01:14:39 +0200 +Subject: [PATCH] fix some plugin's json + +--- + libguh/plugin/deviceplugin.cpp | 6 ++++++ + plugins/deviceplugins/lircd/devicepluginlircd.json | 2 +- + .../deviceplugins/openweathermap/devicepluginopenweathermap.json | 8 ++++---- + server/jsonrpc/jsontypes.cpp | 1 + + 4 files changed, 12 insertions(+), 5 deletions(-) + +diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp +index a88fd7e..d90ea31 100644 +--- a/libguh/plugin/deviceplugin.cpp ++++ b/libguh/plugin/deviceplugin.cpp +@@ -163,6 +163,7 @@ QList DevicePlugin::supportedDevices() const + deviceClass.setCreateMethods(createMethods); + + deviceClass.setDiscoveryParamTypes(parseParamTypes(jo.value("discoveryParamTypes").toArray())); ++ qDebug() << "loaded deviceClass" << deviceClass.discoveryParamTypes(); + + QString setupMethod = jo.value("setupMethod").toString(); + if (setupMethod == "pushButton") { +@@ -293,6 +294,11 @@ QList DevicePlugin::parseParamTypes(const QJsonArray &array) const + foreach (const QJsonValue ¶mTypesJson, array) { + QJsonObject pt = paramTypesJson.toObject(); + QVariant::Type t = QVariant::nameToType(pt.value("type").toString().toLatin1().data()); ++ Q_ASSERT_X(t != QVariant::Invalid, ++ pluginName().toLatin1().data(), ++ QString("Invalid type %1 for param %2 in json file.") ++ .arg(pt.value("type").toString()) ++ .arg(pt.value("name").toString()).toLatin1().data()); + ParamType paramType(pt.value("name").toString(), t, pt.value("defaultValue").toVariant()); + QVariantList allowedValues; + foreach (const QJsonValue &allowedTypesJson, pt.value("allowedValues").toArray()) { +diff --git a/plugins/deviceplugins/lircd/devicepluginlircd.json b/plugins/deviceplugins/lircd/devicepluginlircd.json +index 0f75dc9..976ab3a 100644 +--- a/plugins/deviceplugins/lircd/devicepluginlircd.json ++++ b/plugins/deviceplugins/lircd/devicepluginlircd.json +@@ -23,7 +23,7 @@ + "paramTypes": [ + { + "name": "button", +- "type": "string" ++ "type": "QString" + }, + { + "name": "repeat", +diff --git a/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.json b/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.json +index aac6f81..cdc8e1e 100644 +--- a/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.json ++++ b/plugins/deviceplugins/openweathermap/devicepluginopenweathermap.json +@@ -13,21 +13,21 @@ + "discoveryParamTypes": [ + { + "name": "location", +- "type": "string" ++ "type": "QString" + } + ], + "paramTypes": [ + { + "name": "location", +- "type": "string" ++ "type": "QString" + }, + { + "name": "country", +- "type": "string" ++ "type": "QString" + }, + { + "name": "id", +- "type": "string" ++ "type": "QString" + } + ], + "actionTypes": [ +diff --git a/server/jsonrpc/jsontypes.cpp b/server/jsonrpc/jsontypes.cpp +index dc96635..cece93f 100644 +--- a/server/jsonrpc/jsontypes.cpp ++++ b/server/jsonrpc/jsontypes.cpp +@@ -371,6 +371,7 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass) + } + QVariantList discoveryParamTypes; + foreach (const ParamType ¶mType, deviceClass.discoveryParamTypes()) { ++ qDebug() << "packing discoverparam" << packParamType(paramType); + discoveryParamTypes.append(packParamType(paramType)); + } + +-- +2.1.0 +