drop triggers too
This commit is contained in:
parent
86ff25258e
commit
373eb6b332
@ -43,26 +43,6 @@ void Device::setName(const QString &name)
|
|||||||
m_name = name;
|
m_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Trigger> Device::triggers() const
|
|
||||||
{
|
|
||||||
return m_triggers;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Device::setTriggers(const QList<Trigger> triggers)
|
|
||||||
{
|
|
||||||
m_triggers = triggers;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<Action> Device::actions() const
|
|
||||||
{
|
|
||||||
return m_actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Device::setActions(const QList<Action> &actions)
|
|
||||||
{
|
|
||||||
m_actions = actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantMap Device::params() const
|
QVariantMap Device::params() const
|
||||||
{
|
{
|
||||||
return m_params;
|
return m_params;
|
||||||
|
|||||||
@ -22,12 +22,6 @@ public:
|
|||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|
||||||
QList<Trigger> triggers() const;
|
|
||||||
void setTriggers(const QList<Trigger> triggers);
|
|
||||||
|
|
||||||
QList<Action> actions() const;
|
|
||||||
void setActions(const QList<Action> &actions);
|
|
||||||
|
|
||||||
QVariantMap params() const;
|
QVariantMap params() const;
|
||||||
void setParams(const QVariantMap ¶ms);
|
void setParams(const QVariantMap ¶ms);
|
||||||
|
|
||||||
@ -40,8 +34,6 @@ private:
|
|||||||
QUuid m_deviceClassId;
|
QUuid m_deviceClassId;
|
||||||
QUuid m_pluginId;
|
QUuid m_pluginId;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QList<Trigger> m_triggers;
|
|
||||||
QList<Action> m_actions;
|
|
||||||
QVariantMap m_params;
|
QVariantMap m_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -54,14 +54,6 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const QUuid &devic
|
|||||||
Device *device = new Device(plugin->pluginId(), deviceClassId, this);
|
Device *device = new Device(plugin->pluginId(), deviceClassId, this);
|
||||||
device->setName(deviceClass.name());
|
device->setName(deviceClass.name());
|
||||||
device->setParams(params);
|
device->setParams(params);
|
||||||
QList<Trigger> triggers;
|
|
||||||
foreach (const TriggerType &triggerType, deviceClass.triggers()) {
|
|
||||||
Trigger trigger(QUuid::createUuid());
|
|
||||||
trigger.setName(triggerType.name());
|
|
||||||
trigger.setParams(triggerType.parameters());
|
|
||||||
triggers.append(trigger);
|
|
||||||
}
|
|
||||||
device->setTriggers(triggers);
|
|
||||||
m_configuredDevices.append(device);
|
m_configuredDevices.append(device);
|
||||||
|
|
||||||
storeConfiguredDevices();
|
storeConfiguredDevices();
|
||||||
@ -95,43 +87,6 @@ DeviceClass DeviceManager::findDeviceClass(const QUuid &deviceClassId)
|
|||||||
return DeviceClass(QUuid(), QUuid());
|
return DeviceClass(QUuid(), QUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
Trigger DeviceManager::findTrigger(const QUuid &triggerId)
|
|
||||||
{
|
|
||||||
foreach (Device *device, m_configuredDevices) {
|
|
||||||
foreach (const Trigger &trigger, device->triggers()) {
|
|
||||||
if (trigger.id() == triggerId) {
|
|
||||||
return trigger;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Trigger();
|
|
||||||
}
|
|
||||||
|
|
||||||
Action DeviceManager::findAction(const QUuid &actionId)
|
|
||||||
{
|
|
||||||
foreach (Device *device, m_configuredDevices) {
|
|
||||||
qDebug() << "got action" << actionId;
|
|
||||||
foreach (const Action &action, device->actions()) {
|
|
||||||
qDebug() << "got action" << action.id() << actionId;
|
|
||||||
if (action.id() == actionId) {
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Action();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<Action> DeviceManager::allActions() const
|
|
||||||
{
|
|
||||||
QList<Action> ret;
|
|
||||||
foreach (Device *device, m_configuredDevices) {
|
|
||||||
foreach (const Action &action, device->actions()) {
|
|
||||||
ret << action;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
Radio433 *DeviceManager::radio433() const
|
Radio433 *DeviceManager::radio433() const
|
||||||
{
|
{
|
||||||
return m_radio433;
|
return m_radio433;
|
||||||
@ -160,7 +115,7 @@ void DeviceManager::loadPlugins()
|
|||||||
m_supportedDevices.append(deviceClass);
|
m_supportedDevices.append(deviceClass);
|
||||||
}
|
}
|
||||||
m_devicePlugins.insert(pluginIface->pluginId(), pluginIface);
|
m_devicePlugins.insert(pluginIface->pluginId(), pluginIface);
|
||||||
connect(pluginIface,SIGNAL(emitTrigger(QUuid,QVariantMap)),this,SIGNAL(emitTrigger(QUuid,QVariantMap)));
|
connect(pluginIface, &DevicePlugin::emitTrigger, this, &DeviceManager::emitTrigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -176,19 +131,6 @@ void DeviceManager::loadConfiguredDevices()
|
|||||||
Device *device = new Device(settings.value("pluginid").toUuid(), QUuid(idString), settings.value("deviceClassId").toUuid(), this);
|
Device *device = new Device(settings.value("pluginid").toUuid(), QUuid(idString), settings.value("deviceClassId").toUuid(), this);
|
||||||
device->setName(settings.value("devicename").toString());
|
device->setName(settings.value("devicename").toString());
|
||||||
device->setParams(settings.value("params").toMap());
|
device->setParams(settings.value("params").toMap());
|
||||||
settings.beginGroup("triggers");
|
|
||||||
QList<Trigger> triggerList;
|
|
||||||
foreach (const QString &triggerId, settings.childGroups()) {
|
|
||||||
settings.beginGroup(triggerId);
|
|
||||||
QUuid id(triggerId);
|
|
||||||
Trigger trigger(id);
|
|
||||||
trigger.setName(settings.value("triggername").toString());
|
|
||||||
trigger.setParams(settings.value("params").toList());
|
|
||||||
settings.endGroup();
|
|
||||||
triggerList.append(trigger);
|
|
||||||
}
|
|
||||||
device->setTriggers(triggerList);
|
|
||||||
settings.endGroup();
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
m_configuredDevices.append(device);
|
m_configuredDevices.append(device);
|
||||||
}
|
}
|
||||||
@ -203,14 +145,6 @@ void DeviceManager::storeConfiguredDevices()
|
|||||||
settings.setValue("deviceClassId", device->deviceClassId().toString());
|
settings.setValue("deviceClassId", device->deviceClassId().toString());
|
||||||
settings.setValue("pluginid", device->pluginId());
|
settings.setValue("pluginid", device->pluginId());
|
||||||
settings.setValue("params", device->params());
|
settings.setValue("params", device->params());
|
||||||
settings.beginGroup("triggers");
|
|
||||||
foreach (const Trigger &trigger, device->triggers()) {
|
|
||||||
settings.beginGroup(trigger.id().toString());
|
|
||||||
settings.setValue("triggername", trigger.name());
|
|
||||||
settings.setValue("params", trigger.params());
|
|
||||||
settings.endGroup();
|
|
||||||
}
|
|
||||||
settings.endGroup();
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,15 +33,10 @@ public:
|
|||||||
QList<Device*> findConfiguredDevices(const QUuid &deviceClassId);
|
QList<Device*> findConfiguredDevices(const QUuid &deviceClassId);
|
||||||
DeviceClass findDeviceClass(const QUuid &deviceClassId);
|
DeviceClass findDeviceClass(const QUuid &deviceClassId);
|
||||||
|
|
||||||
Trigger findTrigger(const QUuid &triggerId);
|
|
||||||
Action findAction(const QUuid &actionId);
|
|
||||||
|
|
||||||
QList<Action> allActions() const;
|
|
||||||
|
|
||||||
Radio433 *radio433() const;
|
Radio433 *radio433() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void emitTrigger(const QUuid &triggerId, const QVariantMap ¶ms);
|
void emitTrigger(const Trigger &trigger);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
DeviceError executeAction(const Action &action);
|
DeviceError executeAction(const Action &action);
|
||||||
|
|||||||
@ -30,7 +30,7 @@ public slots:
|
|||||||
virtual void executeAction(Device *device, const Action &action) = 0;
|
virtual void executeAction(Device *device, const Action &action) = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void emitTrigger(const QUuid &triggerId, const QVariantMap ¶ms);
|
void emitTrigger(const Trigger &trigger);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DeviceManager *deviceManager() const;
|
DeviceManager *deviceManager() const;
|
||||||
|
|||||||
@ -1,36 +1,22 @@
|
|||||||
#include "trigger.h"
|
#include "trigger.h"
|
||||||
|
|
||||||
Trigger::Trigger(const QUuid &id):
|
Trigger::Trigger(const QUuid &deviceClassid, const QVariantMap ¶ms):
|
||||||
m_id(id)
|
m_deviceClassId(deviceClassid),
|
||||||
|
m_params(params)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Trigger::isValid() const
|
QUuid Trigger::deviceClassId() const
|
||||||
{
|
{
|
||||||
return !m_id.isNull();
|
return m_deviceClassId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Trigger::id() const
|
QVariantMap Trigger::params() const
|
||||||
{
|
|
||||||
return m_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Trigger::name() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Trigger::setName(const QString &name)
|
|
||||||
{
|
|
||||||
m_name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantList Trigger::params() const
|
|
||||||
{
|
{
|
||||||
return m_params;
|
return m_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trigger::setParams(const QVariantList ¶ms)
|
void Trigger::setParams(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
m_params = params;
|
m_params = params;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,21 +8,16 @@
|
|||||||
class Trigger
|
class Trigger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Trigger(const QUuid &id = QUuid());
|
Trigger(const QUuid &deviceClassid, const QVariantMap ¶ms);
|
||||||
bool isValid() const;
|
|
||||||
|
|
||||||
QUuid id() const;
|
QUuid deviceClassId() const;
|
||||||
|
|
||||||
QString name() const;
|
QVariantMap params() const;
|
||||||
void setName(const QString &name);
|
void setParams(const QVariantMap ¶ms);
|
||||||
|
|
||||||
QVariantList params() const;
|
|
||||||
void setParams(const QVariantList ¶ms);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_id;
|
QUuid m_deviceClassId;
|
||||||
QString m_name;
|
QVariantMap m_params;
|
||||||
QVariantList m_params;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRIGGER_H
|
#endif // TRIGGER_H
|
||||||
|
|||||||
@ -349,14 +349,16 @@ void DevicePluginElro::dataReceived(QList<int> rawData)
|
|||||||
qWarning() << "couldn't find any configured device for elro:" << binCode.left(10) ;
|
qWarning() << "couldn't find any configured device for elro:" << binCode.left(10) ;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
params.insert("button", button);
|
|
||||||
params.insert("power", power);
|
params.insert("power", power);
|
||||||
foreach (const Trigger &trigger, device->triggers()) {
|
|
||||||
//qDebug() << "got trigger" << trigger.name();
|
// FIXME: find a better way to get to the remote DeviceClass
|
||||||
if (trigger.name() == button) {
|
DeviceClass deviceClass = supportedDevices().first();
|
||||||
emit emitTrigger(trigger.id(), params);
|
foreach (const TriggerType &triggerType, deviceClass.triggers()) {
|
||||||
|
if (triggerType.name() == button) {
|
||||||
|
Trigger trigger = Trigger(triggerType.id(), params);
|
||||||
|
emit emitTrigger(trigger);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -177,16 +177,6 @@ QVariantMap JsonRPCServer::packDevice(Device *device)
|
|||||||
variant.insert("id", device->id());
|
variant.insert("id", device->id());
|
||||||
variant.insert("deviceClassId", device->deviceClassId());
|
variant.insert("deviceClassId", device->deviceClassId());
|
||||||
variant.insert("name", device->name());
|
variant.insert("name", device->name());
|
||||||
QVariantList triggers;
|
|
||||||
foreach (const Trigger &trigger, device->triggers()) {
|
|
||||||
triggers.append(trigger.id());
|
|
||||||
}
|
|
||||||
variant.insert("triggers", triggers);
|
|
||||||
QVariantList actions;
|
|
||||||
foreach (const Action &action, device->actions()) {
|
|
||||||
actions.append(action.id());
|
|
||||||
}
|
|
||||||
variant.insert("actions", actions);
|
|
||||||
variant.insert("params", device->params());
|
variant.insert("params", device->params());
|
||||||
return variant;
|
return variant;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,18 +36,10 @@ QList<Action> RuleEngine::evaluateTrigger(const QUuid &triggerId)
|
|||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleEngine::RuleError RuleEngine::addRule(const QUuid &triggerId, const QUuid &actionId)
|
RuleEngine::RuleError RuleEngine::addRule(const QUuid &triggerTypeId, const Action &action)
|
||||||
{
|
{
|
||||||
if (!HiveCore::instance()->deviceManager()->findTrigger(triggerId).isValid()) {
|
|
||||||
qWarning() << "Cannot create rule. No such trigger.";
|
|
||||||
return RuleErrorNoSuchTrigger;
|
|
||||||
}
|
|
||||||
if (!HiveCore::instance()->deviceManager()->findAction(actionId).isValid()) {
|
|
||||||
qWarning() << "Cannot create rule. No such action.";
|
|
||||||
return RuleErrorNoSuchAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rule rule = Rule(QUuid::createUuid(), triggerId, actionId);
|
Rule rule = Rule(QUuid::createUuid(), triggerTypeId, action);
|
||||||
m_rules.append(rule);
|
m_rules.append(rule);
|
||||||
|
|
||||||
QSettings settings(rulesFileName);
|
QSettings settings(rulesFileName);
|
||||||
|
|||||||
@ -21,7 +21,7 @@ public:
|
|||||||
|
|
||||||
QList<Action> evaluateTrigger(const QUuid &triggerId);
|
QList<Action> evaluateTrigger(const QUuid &triggerId);
|
||||||
|
|
||||||
RuleError addRule(const QUuid &triggerId, const QUuid &actionId);
|
RuleError addRule(const QUuid &triggerTypeId, const Action &action);
|
||||||
QList<Rule> rules() const;
|
QList<Rule> rules() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user