mirror of https://github.com/nymea/nymea.git
Merge PR #306: Vaguely inform the plugin about the origin of actions.
commit
3aac5df9f9
|
|
@ -444,7 +444,7 @@ void NymeaCore::executeRuleActions(const QList<RuleAction> ruleActions)
|
|||
qCWarning(dcRuleEngine()) << "Not executing rule action";
|
||||
continue;
|
||||
}
|
||||
Action action(actionTypeId, thing->id());
|
||||
Action action(actionTypeId, thing->id(), Action::TriggeredByRule);
|
||||
action.setParams(params);
|
||||
actions.append(action);
|
||||
} else if (ruleAction.type() == RuleAction::TypeBrowser) {
|
||||
|
|
@ -497,7 +497,7 @@ void NymeaCore::executeRuleActions(const QList<RuleAction> ruleActions)
|
|||
continue;
|
||||
}
|
||||
|
||||
Action action = Action(actionType.id(), thing->id());
|
||||
Action action = Action(actionType.id(), thing->id(), Action::TriggeredByRule);
|
||||
action.setParams(params);
|
||||
actions.append(action);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ bool RuleAction::isStateBased() const
|
|||
|
||||
Action RuleAction::toAction() const
|
||||
{
|
||||
Action action(m_actionTypeId, m_thingId);
|
||||
Action action(m_actionTypeId, m_thingId, Action::TriggeredByRule);
|
||||
ParamList params;
|
||||
foreach (const RuleActionParam &ruleActionParam, m_ruleActionParams) {
|
||||
params.append(Param(ruleActionParam.paramTypeId(), ruleActionParam.value()));
|
||||
|
|
|
|||
|
|
@ -111,9 +111,7 @@ void ScriptAction::execute(const QVariantMap ¶ms)
|
|||
qCWarning(dcScriptEngine()) << "Either a valid actionTypeId or actionName is required";
|
||||
return;
|
||||
}
|
||||
Action action;
|
||||
action.setActionTypeId(actionType.id());
|
||||
action.setThingId(ThingId(m_thingId));
|
||||
Action action(actionType.id(), ThingId(m_thingId), Action::TriggeredByScript);
|
||||
ParamList paramList;
|
||||
foreach (const QString ¶mNameOrId, params.keys()) {
|
||||
ParamType paramType;
|
||||
|
|
|
|||
|
|
@ -168,9 +168,7 @@ void ScriptState::setValue(const QVariant &value)
|
|||
return;
|
||||
}
|
||||
|
||||
Action action;
|
||||
action.setThingId(ThingId(m_thingId));
|
||||
action.setActionTypeId(ActionTypeId(actionTypeId));
|
||||
Action action(ActionTypeId(actionTypeId), ThingId(m_thingId), Action::TriggeredByScript);
|
||||
ParamList params = ParamList() << Param(ParamTypeId(actionTypeId), value);
|
||||
action.setParams(params);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,9 +46,10 @@
|
|||
#include "action.h"
|
||||
|
||||
/*! Construct an Action with the given \a deviceId and \a actionTypeId. */
|
||||
Action::Action(const ActionTypeId &actionTypeId, const ThingId &thingId) :
|
||||
Action::Action(const ActionTypeId &actionTypeId, const ThingId &thingId, TriggeredBy triggeredBy) :
|
||||
m_actionTypeId(actionTypeId),
|
||||
m_thingId(thingId)
|
||||
m_thingId(thingId),
|
||||
m_triggeredBy(triggeredBy)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -112,6 +113,24 @@ Param Action::param(const ParamTypeId ¶mTypeId) const
|
|||
return Param(ParamTypeId(), QString());
|
||||
}
|
||||
|
||||
/*! Gives an indication of the origin of this action.
|
||||
Normally a plugin should treat all actions the same. There might be
|
||||
rare exceptions tho:
|
||||
|
||||
- This might be important to know for some devices, e.g. garage doors which are required to
|
||||
not close in some circumstances. I.e. if a garage door does not have a light sensor bar, it
|
||||
must never close automatically by a rule to prevent damage and fulfill legal requirements.
|
||||
|
||||
- Other use cases might be to prioritize a single request by a user over a queue of automated
|
||||
ones. I.e. if a script animation animates a color light, the plugin might build up a queue of
|
||||
pending commands. To still react timely to a user interaction (e.g. power off), this
|
||||
information might be of use to a plugin.
|
||||
*/
|
||||
Action::TriggeredBy Action::triggeredBy() const
|
||||
{
|
||||
return m_triggeredBy;
|
||||
}
|
||||
|
||||
/*! Copy the data to an \l{Action} from an \a other action. */
|
||||
void Action::operator =(const Action &other)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,7 +46,12 @@ class LIBNYMEA_EXPORT Action
|
|||
Q_PROPERTY(ParamList params READ params WRITE setParams USER true)
|
||||
|
||||
public:
|
||||
explicit Action(const ActionTypeId &actionTypeId = ActionTypeId(), const ThingId &thingId = ThingId());
|
||||
enum TriggeredBy {
|
||||
TriggeredByUser,
|
||||
TriggeredByRule,
|
||||
TriggeredByScript
|
||||
};
|
||||
explicit Action(const ActionTypeId &actionTypeId = ActionTypeId(), const ThingId &thingId = ThingId(), TriggeredBy triggeredBy = TriggeredByUser);
|
||||
Action(const Action &other);
|
||||
|
||||
bool isValid() const;
|
||||
|
|
@ -60,11 +65,14 @@ public:
|
|||
void setParams(const ParamList ¶ms);
|
||||
Param param(const ParamTypeId ¶mTypeId) const;
|
||||
|
||||
TriggeredBy triggeredBy() const;
|
||||
|
||||
void operator=(const Action &other);
|
||||
private:
|
||||
ActionTypeId m_actionTypeId;
|
||||
ThingId m_thingId;
|
||||
ParamList m_params;
|
||||
TriggeredBy m_triggeredBy = TriggeredByUser;
|
||||
};
|
||||
|
||||
#endif // ACTION_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue