Support params
This commit is contained in:
parent
7a8f868c54
commit
9ecb2d0af4
@ -84,27 +84,39 @@ void ScriptAction::setActionName(const QString &actionName)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptAction::execute(const QVariantList ¶ms)
|
||||
void ScriptAction::execute(const QVariantMap ¶ms)
|
||||
{
|
||||
Device *device = m_deviceManager->configuredDevices().findById(DeviceId(m_deviceId));
|
||||
if (!device) {
|
||||
qCWarning(dcScriptEngine) << "No device with id" << m_deviceId;
|
||||
return;
|
||||
}
|
||||
ActionTypeId actionTypeId = ActionTypeId(m_actionTypeId);
|
||||
if (actionTypeId.isNull()) {
|
||||
actionTypeId = device->deviceClass().actionTypes().findByName(m_actionName).id();
|
||||
ActionType actionType;
|
||||
if (!ActionTypeId(m_actionTypeId).isNull()) {
|
||||
actionType = device->deviceClass().actionTypes().findById(ActionTypeId(m_actionTypeId));
|
||||
} else {
|
||||
actionType = device->deviceClass().actionTypes().findByName(m_actionName);
|
||||
}
|
||||
if (actionTypeId.isNull()) {
|
||||
if (actionType.id().isNull()) {
|
||||
qCWarning(dcScriptEngine()) << "Either a valid actionTypeId or actionName is required";
|
||||
return;
|
||||
}
|
||||
Action action;
|
||||
action.setActionTypeId(actionTypeId);
|
||||
action.setActionTypeId(actionType.id());
|
||||
action.setDeviceId(DeviceId(m_deviceId));
|
||||
ParamList paramList;
|
||||
foreach (const QVariant &p, params) {
|
||||
paramList << Param(ParamTypeId(p.toMap().value("paramTypeId").toUuid()), p.toMap().value("value"));
|
||||
foreach (const QString ¶mNameOrId, params.keys()) {
|
||||
ParamType paramType;
|
||||
if (!ParamTypeId(paramNameOrId).isNull()) {
|
||||
paramType = actionType.paramTypes().findById(ParamTypeId(paramNameOrId));
|
||||
} else {
|
||||
paramType = actionType.paramTypes().findByName(paramNameOrId);
|
||||
}
|
||||
if (paramType.id().isNull()) {
|
||||
qCWarning(dcScriptEngine()) << "Invalid param id or name";
|
||||
continue;
|
||||
}
|
||||
paramList << Param(paramType.id(), params.value(paramNameOrId));
|
||||
}
|
||||
action.setParams(paramList);
|
||||
m_deviceManager->executeAction(action);
|
||||
|
||||
@ -49,7 +49,7 @@ public:
|
||||
void setActionName(const QString &actionName);
|
||||
|
||||
public slots:
|
||||
void execute(const QVariantList ¶ms);
|
||||
void execute(const QVariantMap ¶ms);
|
||||
|
||||
signals:
|
||||
void deviceIdChanged();
|
||||
|
||||
@ -94,7 +94,16 @@ void ScriptEvent::onEventTriggered(const Event &event)
|
||||
return;
|
||||
}
|
||||
|
||||
emit triggered();
|
||||
// ScriptParams *params = new ScriptParams(event.params());
|
||||
// qmlEngine(this)->setObjectOwnership(params, QQmlEngine::JavaScriptOwnership);
|
||||
QVariantMap params;
|
||||
foreach (const Param ¶m, event.params()) {
|
||||
params.insert(param.paramTypeId().toString().remove(QRegExp("[{}]")), param.value());
|
||||
QString paramName = device->deviceClass().eventTypes().findById(event.eventTypeId()).paramTypes().findById(param.paramTypeId()).name();
|
||||
params.insert(paramName, param.value());
|
||||
}
|
||||
|
||||
emit triggered(params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -30,6 +30,8 @@
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class ScriptParams;
|
||||
|
||||
class ScriptEvent: public QObject, public QQmlParserStatus
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -59,7 +61,8 @@ signals:
|
||||
void eventTypeIdChanged();
|
||||
void eventNameChanged();
|
||||
|
||||
void triggered();
|
||||
// void triggered(ScriptParams *params);
|
||||
void triggered(const QVariantMap ¶ms);
|
||||
|
||||
private:
|
||||
DeviceManager *m_deviceManager = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user