allow passing params if QVariant can convert them
This commit is contained in:
parent
23316942ce
commit
11d56d1020
@ -617,7 +617,7 @@ void NymeaCore::gotEvent(const Event &event)
|
|||||||
// something like a EventParamDescriptor
|
// something like a EventParamDescriptor
|
||||||
|
|
||||||
ruleActionParam.setValue(eventValue);
|
ruleActionParam.setValue(eventValue);
|
||||||
qCDebug(dcRuleEngine) << "take over event param value" << ruleActionParam.value();
|
qCDebug(dcRuleEngine) << "Using param value from event:" << ruleActionParam.value();
|
||||||
}
|
}
|
||||||
newParams.append(ruleActionParam);
|
newParams.append(ruleActionParam);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -595,8 +595,9 @@ RuleEngine::RuleError RuleEngine::addRule(const Rule &rule, bool fromEdit)
|
|||||||
|
|
||||||
// check if the param type of the event and the action match
|
// check if the param type of the event and the action match
|
||||||
QVariant::Type eventParamType = getEventParamType(ruleActionParam.eventTypeId(), ruleActionParam.eventParamTypeId());
|
QVariant::Type eventParamType = getEventParamType(ruleActionParam.eventTypeId(), ruleActionParam.eventParamTypeId());
|
||||||
|
QVariant v(eventParamType);
|
||||||
QVariant::Type actionParamType = getActionParamType(action.actionTypeId(), ruleActionParam.paramTypeId());
|
QVariant::Type actionParamType = getActionParamType(action.actionTypeId(), ruleActionParam.paramTypeId());
|
||||||
if (eventParamType != actionParamType) {
|
if (eventParamType != actionParamType && !v.canConvert(actionParamType)) {
|
||||||
qCWarning(dcRuleEngine) << "Cannot create rule. RuleActionParam" << ruleActionParam.paramTypeId().toString() << " and given event param " << ruleActionParam.eventParamTypeId().toString() << "have not the same type:";
|
qCWarning(dcRuleEngine) << "Cannot create rule. RuleActionParam" << ruleActionParam.paramTypeId().toString() << " and given event param " << ruleActionParam.eventParamTypeId().toString() << "have not the same type:";
|
||||||
qCWarning(dcRuleEngine) << " -> actionParamType:" << actionParamType;
|
qCWarning(dcRuleEngine) << " -> actionParamType:" << actionParamType;
|
||||||
qCWarning(dcRuleEngine) << " -> eventParamType:" << eventParamType;
|
qCWarning(dcRuleEngine) << " -> eventParamType:" << eventParamType;
|
||||||
|
|||||||
@ -104,6 +104,9 @@ private slots:
|
|||||||
void testRuleActionParams_data();
|
void testRuleActionParams_data();
|
||||||
void testRuleActionParams();
|
void testRuleActionParams();
|
||||||
|
|
||||||
|
void testRuleActionPAramsFromEventParameter_data();
|
||||||
|
void testRuleActionPAramsFromEventParameter();
|
||||||
|
|
||||||
void testInterfaceBasedRule();
|
void testInterfaceBasedRule();
|
||||||
|
|
||||||
void testHousekeeping_data();
|
void testHousekeeping_data();
|
||||||
@ -2175,6 +2178,66 @@ void TestRules::testRuleActionParams()
|
|||||||
verifyRuleError(response, error);
|
verifyRuleError(response, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestRules::testRuleActionPAramsFromEventParameter_data() {
|
||||||
|
QTest::addColumn<QVariantMap>("event");
|
||||||
|
QTest::addColumn<QVariantMap>("action");
|
||||||
|
QTest::addColumn<RuleEngine::RuleError>("error");
|
||||||
|
|
||||||
|
QVariantMap intEvent;
|
||||||
|
intEvent.insert("eventTypeId", mockIntStateId);
|
||||||
|
intEvent.insert("deviceId", m_mockDeviceId);
|
||||||
|
|
||||||
|
QVariantMap intAction;
|
||||||
|
intAction.insert("actionTypeId", mockActionIdWithParams);
|
||||||
|
intAction.insert("deviceId", m_mockDeviceId);
|
||||||
|
QVariantList ruleActionParams;
|
||||||
|
QVariantMap intParam;
|
||||||
|
intParam.insert("paramTypeId", mockActionParam1ParamTypeId);
|
||||||
|
intParam.insert("eventTypeId", mockIntStateId);
|
||||||
|
intParam.insert("eventParamTypeId", mockIntStateId);
|
||||||
|
ruleActionParams.append(intParam);
|
||||||
|
QVariantMap boolParam;
|
||||||
|
boolParam.insert("paramTypeId", mockActionParam2ParamTypeId);
|
||||||
|
boolParam.insert("value", true);
|
||||||
|
ruleActionParams.append(boolParam);
|
||||||
|
intAction.insert("ruleActionParams", ruleActionParams);
|
||||||
|
|
||||||
|
QVariantMap boolAction;
|
||||||
|
boolAction.insert("actionTypeId", mockActionIdWithParams);
|
||||||
|
boolAction.insert("deviceId", m_mockDeviceId);
|
||||||
|
ruleActionParams.clear();
|
||||||
|
intParam.clear();
|
||||||
|
intParam.insert("paramTypeId", mockActionParam1ParamTypeId);
|
||||||
|
intParam.insert("value", 5);
|
||||||
|
ruleActionParams.append(intParam);
|
||||||
|
boolParam.clear();
|
||||||
|
boolParam.insert("paramTypeId", mockActionParam2ParamTypeId);
|
||||||
|
boolParam.insert("eventTypeId", mockIntStateId);
|
||||||
|
boolParam.insert("eventParamTypeId", mockIntStateId);
|
||||||
|
ruleActionParams.append(boolParam);
|
||||||
|
boolAction.insert("ruleActionParams", ruleActionParams);
|
||||||
|
|
||||||
|
QTest::newRow("int -> int") << intEvent << intAction << RuleEngine::RuleErrorNoError;
|
||||||
|
QTest::newRow("int -> bool") << intEvent << boolAction << RuleEngine::RuleErrorNoError;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestRules::testRuleActionPAramsFromEventParameter()
|
||||||
|
{
|
||||||
|
QFETCH(QVariantMap, event);
|
||||||
|
QFETCH(QVariantMap, action);
|
||||||
|
QFETCH(RuleEngine::RuleError, error);
|
||||||
|
|
||||||
|
QVariantMap addRuleParams;
|
||||||
|
addRuleParams.insert("name", "TestRule");
|
||||||
|
addRuleParams.insert("enabled", true);
|
||||||
|
|
||||||
|
addRuleParams.insert("eventDescriptors", QVariantList() << event);
|
||||||
|
addRuleParams.insert("actions", QVariantList() << action);
|
||||||
|
|
||||||
|
QVariant response = injectAndWait("Rules.AddRule", addRuleParams);
|
||||||
|
verifyRuleError(response, error);
|
||||||
|
}
|
||||||
|
|
||||||
void TestRules::testInterfaceBasedRule()
|
void TestRules::testInterfaceBasedRule()
|
||||||
{
|
{
|
||||||
QVariantMap powerAction;
|
QVariantMap powerAction;
|
||||||
|
|||||||
Reference in New Issue
Block a user