mirror of https://github.com/nymea/nymea.git
trigger changed id..
parent
05225be1d5
commit
f4b6a70735
|
|
@ -126,13 +126,13 @@ void DeviceManager::loadConfiguredDevices()
|
|||
QSettings settings;
|
||||
qDebug() << "loading devices";
|
||||
foreach (const QString &idString, settings.childGroups()) {
|
||||
qDebug() << "found stored device" << idString;
|
||||
settings.beginGroup(idString);
|
||||
Device *device = new Device(settings.value("pluginid").toUuid(), QUuid(idString), settings.value("deviceClassId").toUuid(), this);
|
||||
device->setName(settings.value("devicename").toString());
|
||||
device->setParams(settings.value("params").toMap());
|
||||
settings.endGroup();
|
||||
m_configuredDevices.append(device);
|
||||
qDebug() << "found stored device" << device->name() << idString;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
|||
paramRemote.insert("type", "bool");
|
||||
paramsRemote.append(paramRemote);
|
||||
|
||||
|
||||
/* 1-16
|
||||
* ________________
|
||||
* | I | II|III| IV |
|
||||
|
|
@ -58,9 +57,6 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
|||
* 4 | 4 | 8 | 12| 16 |
|
||||
* |___|___|___|____|
|
||||
*/
|
||||
paramRemote.insert("name", "button");
|
||||
paramRemote.insert("type", "int");
|
||||
paramsRemote.append(paramRemote);
|
||||
|
||||
TriggerType button1Trigger("785c1b30-a3f2-4696-af7c-d532acf3d6f7");
|
||||
button1Trigger.setName("1");
|
||||
|
|
@ -206,6 +202,11 @@ void DevicePluginIntertechno::dataReceived(QList<int> rawData)
|
|||
return;
|
||||
}
|
||||
|
||||
QList<Device*> deviceList = deviceManager()->findConfiguredDevices(intertechnoRemote);
|
||||
if(deviceList.isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
||||
int delay = rawData.first()/31;
|
||||
QByteArray binCode;
|
||||
|
||||
|
|
@ -386,78 +387,33 @@ void DevicePluginIntertechno::dataReceived(QList<int> rawData)
|
|||
return;
|
||||
}
|
||||
|
||||
qDebug() << "family code = " << familyCode << "button code =" << buttonCode << power;
|
||||
return;
|
||||
//qDebug() << "family code = " << familyCode << "button code =" << buttonCode << power;
|
||||
|
||||
// ===================================================
|
||||
Device *device = 0;
|
||||
foreach (Device *dev, deviceList) {
|
||||
if (dev->params().contains("familycode") && dev->params().value("familycode").toString() == familyCode) {
|
||||
// Yippie! We found the device.
|
||||
device = dev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!device) {
|
||||
qWarning() << "couldn't find any configured device for intertech familycode:" << familyCode;
|
||||
return;
|
||||
}
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("power", power);
|
||||
|
||||
// // get the channel of the remote signal (5 channels, true=1, false=0)
|
||||
// QList<bool> group;
|
||||
// for(int i = 1; i < 10; i+=2){
|
||||
// if(binCode.at(i-1) == '0' && binCode.at(i) == '1'){
|
||||
// group << false;
|
||||
// }else if(binCode.at(i-1) == '0' && binCode.at(i) == '0'){
|
||||
// group << true;
|
||||
// }else {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // get the button letter
|
||||
// QString button;
|
||||
// QByteArray buttonCode = binCode.mid(10,10);
|
||||
|
||||
// if(buttonCode == "0001010101"){
|
||||
// button = "A";
|
||||
// }else if(buttonCode == "0100010101"){
|
||||
// button = "B";
|
||||
// }else if(buttonCode == "0101000101"){
|
||||
// button = "C";
|
||||
// }else if(buttonCode == "0101010001"){
|
||||
// button = "D";
|
||||
// }else if(buttonCode == "0101010100"){
|
||||
// button = "E";
|
||||
// }else{
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // get power status -> On = 0100, Off = 0001
|
||||
// bool power;
|
||||
// if(binCode.right(4).toInt(0,2) == 1){
|
||||
// power = true;
|
||||
// }else if(binCode.right(4).toInt(0,2) == 4){
|
||||
// power = false;
|
||||
// }else{
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Device *device = 0;
|
||||
// QList<Device*> deviceList = deviceManager()->findConfiguredDevices(intertechnoRemote);
|
||||
// foreach (Device *dev, deviceList) {
|
||||
// if (dev->params().contains("channel1") && dev->params().value("channel1").toBool() == group.at(0) &&
|
||||
// dev->params().contains("channel2") && dev->params().value("channel2").toBool() == group.at(1) &&
|
||||
// dev->params().contains("channel3") && dev->params().value("channel3").toBool() == group.at(2) &&
|
||||
// dev->params().contains("channel4") && dev->params().value("channel4").toBool() == group.at(3) &&
|
||||
// dev->params().contains("channel5") && dev->params().value("channel5").toBool() == group.at(4)
|
||||
// ) {
|
||||
// // Yippie! We found the device.
|
||||
// device = dev;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!device) {
|
||||
// qWarning() << "couldn't find any configured device for mumbi:" << binCode.left(10) ;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// QVariantMap params;
|
||||
// params.insert("button", button);
|
||||
// params.insert("power", power);
|
||||
// foreach (const Trigger &trigger, device->triggers()) {
|
||||
// //qDebug() << "got trigger" << trigger.name();
|
||||
// if (trigger.name() == button) {
|
||||
// emit emitTrigger(trigger.id(), params);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// FIXME: find a better way to get to the remote DeviceClass
|
||||
DeviceClass deviceClass = supportedDevices().first();
|
||||
foreach (const TriggerType &triggerType, deviceClass.triggers()) {
|
||||
if (triggerType.name() == buttonCode) {
|
||||
//qDebug() << "emit trigger " << triggerType.name();
|
||||
Trigger trigger = Trigger(triggerType.id(), params);
|
||||
emit emitTrigger(trigger);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,17 +44,13 @@ HiveCore::HiveCore(QObject *parent) :
|
|||
qDebug() << "*****************************************";
|
||||
m_jsonServer = new JsonRPCServer(this);
|
||||
|
||||
connect(m_deviceManager,SIGNAL(emitTrigger(QUuid,QVariantMap)),this,SLOT(gotSignal(QUuid,QVariantMap)));
|
||||
connect(m_deviceManager, &DeviceManager::emitTrigger, this, &HiveCore::gotSignal);
|
||||
|
||||
}
|
||||
|
||||
void HiveCore::gotSignal(const QUuid &triggerId, const QVariantMap ¶ms)
|
||||
void HiveCore::gotSignal(const Trigger &trigger)
|
||||
{
|
||||
qDebug() << "##################################################";
|
||||
qDebug() << "id: " << triggerId;
|
||||
qDebug() << params;
|
||||
|
||||
foreach (const Action &action, m_ruleEngine->evaluateTrigger(triggerId)) {
|
||||
foreach (const Action &action, m_ruleEngine->evaluateTrigger(trigger)) {
|
||||
m_deviceManager->executeAction(action);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define HIVECORE_H
|
||||
|
||||
#include "rule.h"
|
||||
#include "trigger.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ private:
|
|||
RuleEngine *m_ruleEngine;
|
||||
|
||||
private slots:
|
||||
void gotSignal(const QUuid &triggerId, const QVariantMap ¶ms);
|
||||
void gotSignal(const Trigger &trigger);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include "rule.h"
|
||||
|
||||
Rule::Rule(const QUuid &id, const QUuid &triggerId, const Action &action):
|
||||
Rule::Rule(const QUuid &id, const QUuid &triggerTypeId, const Action &action):
|
||||
m_id(id),
|
||||
m_triggerId(triggerId),
|
||||
m_triggerTypeId(triggerTypeId),
|
||||
m_action(action)
|
||||
{
|
||||
}
|
||||
|
|
@ -12,9 +12,9 @@ QUuid Rule::id() const
|
|||
return m_id;
|
||||
}
|
||||
|
||||
QUuid Rule::triggerId() const
|
||||
QUuid Rule::triggerTypeId() const
|
||||
{
|
||||
return m_triggerId;
|
||||
return m_triggerTypeId;
|
||||
}
|
||||
|
||||
Action Rule::action() const
|
||||
|
|
|
|||
|
|
@ -8,15 +8,15 @@
|
|||
class Rule
|
||||
{
|
||||
public:
|
||||
Rule(const QUuid &id, const QUuid &triggerId, const Action &action);
|
||||
Rule(const QUuid &id, const QUuid &triggerTypeId, const Action &action);
|
||||
|
||||
QUuid id() const;
|
||||
QUuid triggerId() const;
|
||||
QUuid triggerTypeId() const;
|
||||
Action action() const;
|
||||
|
||||
private:
|
||||
QUuid m_id;
|
||||
QUuid m_triggerId;
|
||||
QUuid m_triggerTypeId;
|
||||
Action m_action;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ RuleEngine::RuleEngine(QObject *parent) :
|
|||
|
||||
}
|
||||
|
||||
QList<Action> RuleEngine::evaluateTrigger(const QUuid &triggerId)
|
||||
QList<Action> RuleEngine::evaluateTrigger(const Trigger &trigger)
|
||||
{
|
||||
QList<Action> actions;
|
||||
for (int i = 0; i < m_rules.count(); ++i) {
|
||||
if (m_rules.at(i).triggerId() == triggerId) {
|
||||
if (m_rules.at(i).triggerTypeId() == trigger.) {
|
||||
actions << m_rules.at(i).action();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define RULEENGINE_H
|
||||
|
||||
#include "rule.h"
|
||||
#include "trigger.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
|
|
@ -19,7 +20,7 @@ public:
|
|||
|
||||
explicit RuleEngine(QObject *parent = 0);
|
||||
|
||||
QList<Action> evaluateTrigger(const QUuid &triggerId);
|
||||
QList<Action> evaluateTrigger(const Trigger &trigger);
|
||||
|
||||
RuleError addRule(const QUuid &triggerTypeId, const Action &action);
|
||||
QList<Rule> rules() const;
|
||||
|
|
|
|||
|
|
@ -5,5 +5,7 @@ if [ -z $1 ]; then
|
|||
echo "usage $0 host"
|
||||
else
|
||||
(echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{d85c1ef4-197c-4053-8e40-707aa671d302}","deviceParams":{"channel1":"false", "channel2":"false", "channel3":"false", "channel4": "false", "channel5":"false" }}}'; sleep 1) | nc $1 1234
|
||||
# (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{308ae6e6-38b3-4b3a-a513-3199da2764f8}","deviceParams":{"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
|
||||
# (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{308ae6e6-38b3-4b3a-a513-3199da2764f8}","deviceParams":{"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
|
||||
(echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{ab73ad2f-6594-45a3-9063-8f72d365c5e5}","deviceParams":{"familycode":"J"}}}'; sleep 1) | nc $1 1234
|
||||
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in New Issue