mirror of https://github.com/nymea/nymea.git
make rules actions a list
parent
c54b14e8ef
commit
f93b0c345f
|
|
@ -157,6 +157,10 @@ void JsonRPCServer::handleRulesMessage(int clientId, int commandId, const QStrin
|
|||
action.setParams(actionMap.value("params").toMap());
|
||||
actions.append(action);
|
||||
}
|
||||
if (actions.count() == 0) {
|
||||
sendErrorResponse(clientId, commandId, "Missing parameter: \"actions\".");
|
||||
return;
|
||||
}
|
||||
|
||||
switch(HiveCore::instance()->ruleEngine()->addRule(trigger, actions)) {
|
||||
case RuleEngine::RuleErrorNoError:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "rule.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Rule::Rule(const QUuid &id, const Trigger &trigger, const QList<State> states, const QList<Action> &actions):
|
||||
m_id(id),
|
||||
m_trigger(trigger),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ RuleEngine::RuleEngine(QObject *parent) :
|
|||
QObject(parent)
|
||||
{
|
||||
QSettings settings(rulesFileName);
|
||||
qDebug() << "loading rules from" << rulesFileName;
|
||||
foreach (const QString &idString, settings.childGroups()) {
|
||||
qDebug() << "found rule" << idString;
|
||||
|
||||
|
|
@ -44,6 +43,7 @@ RuleEngine::RuleEngine(QObject *parent) :
|
|||
action.setName(settings.value("name").toString());
|
||||
action.setParams(settings.value("params").toMap());
|
||||
settings.endGroup();
|
||||
actions.append(action);
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
|
|
@ -61,6 +61,7 @@ QList<Action> RuleEngine::evaluateTrigger(const Trigger &trigger)
|
|||
for (int i = 0; i < m_rules.count(); ++i) {
|
||||
if (m_rules.at(i).trigger() == trigger) {
|
||||
bool statesMatching = true;
|
||||
qDebug() << "checking states";
|
||||
foreach (const State &state, m_rules.at(i).states()) {
|
||||
Device *device = HiveCore::instance()->deviceManager()->findConfiguredDevice(state.deviceId());
|
||||
if (!device) {
|
||||
|
|
@ -73,11 +74,13 @@ QList<Action> RuleEngine::evaluateTrigger(const Trigger &trigger)
|
|||
}
|
||||
}
|
||||
|
||||
qDebug() << "states matching" << statesMatching;
|
||||
if (statesMatching) {
|
||||
actions.append(m_rules.at(i).actions());
|
||||
}
|
||||
}
|
||||
}
|
||||
qDebug() << "found" << actions.count() << "actions";
|
||||
return actions;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ elif [ -z $2 ]; then
|
|||
else
|
||||
if [ $2 == "elroremote" ]; then
|
||||
# Adds an ELRO remote control on channel 00000
|
||||
(echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{d85c1ef4-197c-4053-8e40-707aa671d302}","params":{"channel1":"false", "channel2":"false", "channel3":"false", "channel4": "false", "channel5":"false" }}}'; sleep 1) | nc $1 1234
|
||||
(echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{d85c1ef4-197c-4053-8e40-707aa671d302}","params":{"channel1":"true", "channel2":"false", "channel3":"false", "channel4": "false", "channel5":"false" }}}'; sleep 1) | nc $1 1234
|
||||
elif [ $2 == "elroswitch" ]; then
|
||||
# Adds a ELRO power switch on channel 00000 and group E
|
||||
(echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{308ae6e6-38b3-4b3a-a513-3199da2764f8}","params":{"channel1":"false","channel2":"false", "channel3":"false", "channel4": "false","channel5":"false","A":"false","B":"true","C":"false","D":"false","E":"false" }}}'; sleep 1) | nc $1 1234
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
if test -z $3; then
|
||||
echo "usage: $1 host triggerTypeId sourceDeviceId targetDeviceId"
|
||||
else
|
||||
(echo '{"id":1, "method":"Rules.AddRule", "params":{"trigger": {"triggerTypeId": "'$2'", "deviceId":"'$3'", "params":{"power":"true"}}, "action":{ "deviceId":"'$4'", "name":"rule 1", "params":{"power":"true"}}}}'; sleep 1) | nc $1 1234
|
||||
(echo '{"id":1, "method":"Rules.AddRule", "params":{"trigger": {"triggerTypeId": "'$2'", "deviceId":"'$3'", "params":{"power":"false"}}, "action":{ "deviceId":"'$4'", "name":"rule 1", "params":{"power":"false"}}}}'; sleep 1) | nc $1 1234
|
||||
(echo '{"id":1, "method":"Rules.AddRule", "params":{"trigger": {"triggerTypeId": "'$2'", "deviceId":"'$3'", "params":{"power":"true"}}, "actions": [ { "deviceId":"'$4'", "name":"rule 1", "params":{"power":"true"}}, { "deviceId":"'$5'", "name":"rule 1", "params":{"power":"true"}}]}}'; sleep 1) | nc $1 1234
|
||||
(echo '{"id":1, "method":"Rules.AddRule", "params":{"trigger": {"triggerTypeId": "'$2'", "deviceId":"'$3'", "params":{"power":"false"}}, "actions": [ { "deviceId":"'$4'", "name":"rule 1", "params":{"power":"false"}},{ "deviceId":"'$5'", "name":"rule 1", "params":{"power":"true"}}]}}'; sleep 1) | nc $1 1234
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in New Issue