mirror of https://github.com/nymea/nymea.git
parent
8c4332cbab
commit
874f4b54d1
|
|
@ -37,6 +37,15 @@ ActionHandler::ActionHandler(QObject *parent) :
|
|||
returns.insert("errorMessage", "string");
|
||||
setReturns("ExecuteAction", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("GetActionType", "Get the ActionType for the given ActionTypeId");
|
||||
params.insert("actionTypeId", "uuid");
|
||||
setParams("GetActionType", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("o:actionType", JsonTypes::actionTypeDescription());
|
||||
setReturns("GetActionType", returns);
|
||||
|
||||
connect(GuhCore::instance()->deviceManager(), &DeviceManager::actionExecutionFinished, this, &ActionHandler::actionExecuted);
|
||||
}
|
||||
|
||||
|
|
@ -69,6 +78,26 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap ¶ms)
|
|||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply *ActionHandler::GetActionType(const QVariantMap ¶ms) const
|
||||
{
|
||||
ActionTypeId actionTypeId(params.value("actionTypeId").toString());
|
||||
foreach (const DeviceClass &deviceClass, GuhCore::instance()->deviceManager()->supportedDevices()) {
|
||||
foreach (const ActionType &actionType, deviceClass.actions()) {
|
||||
if (actionType.id() == actionTypeId) {
|
||||
QVariantMap data;
|
||||
data.insert("success", true);
|
||||
data.insert("errorMessage", QString());
|
||||
data.insert("actionType", JsonTypes::packActionType(actionType));
|
||||
return createReply(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
QVariantMap data;
|
||||
data.insert("success", false);
|
||||
data.insert("errorMessage", QString("No ActionType with id %1.").arg(actionTypeId.toString()));
|
||||
return createReply(data);
|
||||
}
|
||||
|
||||
void ActionHandler::actionExecuted(const ActionId &id, DeviceManager::DeviceError status, const QString &errorMessage)
|
||||
{
|
||||
if (!m_asyncActionExecutions.contains(id)) {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ public:
|
|||
|
||||
Q_INVOKABLE JsonReply* ExecuteAction(const QVariantMap ¶ms);
|
||||
|
||||
Q_INVOKABLE JsonReply* GetActionType(const QVariantMap ¶ms) const;
|
||||
|
||||
private slots:
|
||||
void actionExecuted(const ActionId &id, DeviceManager::DeviceError status, const QString &errorMessage);
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ private slots:
|
|||
void executeAction_data();
|
||||
void executeAction();
|
||||
|
||||
void getActionTypes_data();
|
||||
void getActionTypes();
|
||||
|
||||
};
|
||||
|
||||
void TestActions::executeAction_data()
|
||||
|
|
@ -115,6 +118,31 @@ void TestActions::executeAction()
|
|||
|
||||
}
|
||||
|
||||
void TestActions::getActionTypes_data()
|
||||
{
|
||||
QTest::addColumn<ActionTypeId>("actionTypeId");
|
||||
QTest::addColumn<bool>("success");
|
||||
|
||||
QTest::newRow("valid actiontypeid") << mockActionIdWithParams << true;
|
||||
QTest::newRow("invalid actiontypeid") << ActionTypeId::createActionTypeId() << false;
|
||||
}
|
||||
|
||||
void TestActions::getActionTypes()
|
||||
{
|
||||
QFETCH(ActionTypeId, actionTypeId);
|
||||
QFETCH(bool, success);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("actionTypeId", actionTypeId.toString());
|
||||
QVariant response = injectAndWait("Actions.GetActionType", params);
|
||||
|
||||
verifySuccess(response, success);
|
||||
|
||||
if (success) {
|
||||
QVERIFY2(ActionTypeId(response.toMap().value("params").toMap().value("actionType").toMap().value("id").toString()) == actionTypeId, "Didnt get reply for same actionTypeId as requested.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include "testactions.moc"
|
||||
QTEST_MAIN(TestActions)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -z $2 ]; then
|
||||
echo "usage: $0 host actionTypeId"
|
||||
else
|
||||
(echo '{"id":1, "method":"Actions.GetActionType", "params":{"actionTypeId":"'$2'"}}'; sleep 1) | nc $1 1234
|
||||
fi
|
||||
Loading…
Reference in New Issue