mirror of https://github.com/nymea/nymea.git
added means to emit triggers
parent
c46403b4c0
commit
2f0520189d
|
|
@ -27,3 +27,23 @@ void Device::setName(const QString &name)
|
|||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QList<Trigger> Device::triggers() const
|
||||
{
|
||||
return m_triggers;
|
||||
}
|
||||
|
||||
void Device::setTriggers(const QList<Trigger> triggers)
|
||||
{
|
||||
m_triggers = triggers;
|
||||
}
|
||||
|
||||
QVariantMap Device::params() const
|
||||
{
|
||||
return m_params;
|
||||
}
|
||||
|
||||
void Device::setParams(const QVariantMap ¶ms)
|
||||
{
|
||||
m_params = params;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef DEVICE_H
|
||||
#define DEVICE_H
|
||||
|
||||
#include "trigger.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QUuid>
|
||||
#include <QVariant>
|
||||
|
||||
class Device: public QObject
|
||||
{
|
||||
|
|
@ -18,10 +21,18 @@ public:
|
|||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QList<Trigger> triggers() const;
|
||||
void setTriggers(const QList<Trigger> triggers);
|
||||
|
||||
QVariantMap params() const;
|
||||
void setParams(const QVariantMap ¶ms);
|
||||
|
||||
private:
|
||||
QUuid m_id;
|
||||
QUuid m_deviceClassId;
|
||||
QString m_name;
|
||||
QList<Trigger> m_triggers;
|
||||
QVariantMap m_params;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -35,3 +35,13 @@ void DeviceClass::setTriggers(const QList<TriggerType> &triggers)
|
|||
{
|
||||
m_triggers = triggers;
|
||||
}
|
||||
|
||||
QVariantList DeviceClass::params() const
|
||||
{
|
||||
return m_params;
|
||||
}
|
||||
|
||||
void DeviceClass::setParams(const QVariantList ¶ms)
|
||||
{
|
||||
m_params = params;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,14 @@ public:
|
|||
QList<TriggerType> triggers() const;
|
||||
void setTriggers(const QList<TriggerType> &triggers);
|
||||
|
||||
QVariantList params() const;
|
||||
void setParams(const QVariantList ¶ms);
|
||||
|
||||
private:
|
||||
QUuid m_id;
|
||||
QString m_name;
|
||||
QList<TriggerType> m_triggers;
|
||||
QVariantList m_params;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,10 +25,12 @@ QList<DeviceClass> DeviceManager::supportedDevices()
|
|||
return m_supportedDevices;
|
||||
}
|
||||
|
||||
void DeviceManager::createDevice(const DeviceClass &deviceClass)
|
||||
void DeviceManager::createDevice(const DeviceClass &deviceClass, const QVariantMap ¶ms)
|
||||
{
|
||||
Device *device = new Device(deviceClass.id(), this);
|
||||
device->setName(deviceClass.name());
|
||||
device->setParams(params);
|
||||
m_configuredDevices.append(device);
|
||||
}
|
||||
|
||||
QList<Device *> DeviceManager::configuredDevices() const
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define DEVICEMANAGER_H
|
||||
|
||||
#include "deviceclass.h"
|
||||
#include "trigger.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ public:
|
|||
|
||||
QList<DeviceClass> supportedDevices();
|
||||
|
||||
void createDevice(const DeviceClass &deviceClass);
|
||||
void createDevice(const DeviceClass &deviceClass, const QVariantMap ¶ms);
|
||||
|
||||
QList<Device*> configuredDevices() const;
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ public:
|
|||
Radio433 *radio433() const;
|
||||
|
||||
signals:
|
||||
void emitTrigger(const Trigger &trigger);
|
||||
|
||||
private slots:
|
||||
void loadPlugins();
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@
|
|||
|
||||
class DeviceManager;
|
||||
|
||||
class DevicePlugin
|
||||
class DevicePlugin: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DevicePlugin();
|
||||
virtual ~DevicePlugin();
|
||||
|
|
@ -23,7 +24,7 @@ public:
|
|||
virtual QList<DeviceClass> supportedDevices() const = 0;
|
||||
|
||||
signals:
|
||||
void emitTrigger(const Trigger &trigger);
|
||||
void emitTrigger(const QUuid &triggerId, const QVariantMap ¶ms);
|
||||
|
||||
protected:
|
||||
DeviceManager *deviceManager() const;
|
||||
|
|
@ -31,6 +32,6 @@ protected:
|
|||
private:
|
||||
DeviceManager *m_deviceManager;
|
||||
};
|
||||
Q_DECLARE_INTERFACE(DevicePlugin, "org.hoveyourhome.DevicePlugin")
|
||||
Q_DECLARE_INTERFACE(DevicePlugin, "org.hiveyourhome.DevicePlugin")
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,14 +10,15 @@ SOURCES += device.cpp \
|
|||
deviceplugin.cpp \
|
||||
radio433.cpp \
|
||||
gpio.cpp \
|
||||
trigger.cpp \
|
||||
triggertype.cpp
|
||||
trigger.cpp \
|
||||
triggertype.cpp
|
||||
|
||||
HEADERS += device.h \
|
||||
deviceclass.h \
|
||||
devicemanager.h \
|
||||
deviceplugin.h \
|
||||
radio433.h \
|
||||
gpio.h \
|
||||
trigger.h \
|
||||
triggertype.h
|
||||
trigger.h \
|
||||
triggertype.h
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "rfswitch.h"
|
||||
|
||||
#include "device.h"
|
||||
#include "devicemanager.h"
|
||||
#include "radio433.h"
|
||||
|
||||
|
|
@ -21,11 +22,28 @@ QList<DeviceClass> RfSwitch::supportedDevices() const
|
|||
|
||||
DeviceClass deviceClassRfRemote(QUuid::createUuid());
|
||||
deviceClassRfRemote.setName("RF Remote");
|
||||
|
||||
QVariantList deviceParams;
|
||||
QVariantMap channelParam;
|
||||
channelParam.insert("name", "channel");
|
||||
channelParam.insert("type", "string");
|
||||
channelParam.insert("name", "channel2");
|
||||
channelParam.insert("type", "bool");
|
||||
channelParam.insert("name", "channel3");
|
||||
channelParam.insert("type", "bool");
|
||||
channelParam.insert("name", "channel4");
|
||||
channelParam.insert("type", "bool");
|
||||
channelParam.insert("name", "channel5");
|
||||
channelParam.insert("type", "bool");
|
||||
deviceParams.append(channelParam);
|
||||
|
||||
deviceClassRfRemote.setParams(deviceParams);
|
||||
|
||||
QList<TriggerType> buttonTriggers;
|
||||
|
||||
QVariantList params;
|
||||
QVariantMap param;
|
||||
param.insert("name", "on");
|
||||
param.insert("name", "power");
|
||||
param.insert("type", "bool");
|
||||
params.append(param);
|
||||
|
||||
|
|
@ -75,5 +93,43 @@ void RfSwitch::dataReceived(QList<int> rawData)
|
|||
{
|
||||
qDebug() << "data received from Radio433" << rawData;
|
||||
|
||||
// TODO: Lets assume we found a device of class "deviceClassRfRemote"
|
||||
DeviceClass deviceClassRfRemote = supportedDevices().first();
|
||||
|
||||
// TODO: Lets assume we received group "1000"
|
||||
QList<bool> group;
|
||||
group << true << false << false << false << false;
|
||||
|
||||
Device *device = 0;
|
||||
QList<Device*> deviceList = deviceManager()->findConfiguredDevices(deviceClassRfRemote);
|
||||
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 data:" << rawData;
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Lets assume we received button "A" "on"
|
||||
QString button = "A";
|
||||
bool power = true;
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("button", button);
|
||||
params.insert("power", power);
|
||||
foreach (const Trigger &trigger, device->triggers()) {
|
||||
if (trigger.name() == button) {
|
||||
emit emitTrigger(trigger.id(), params);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "deviceplugin.h"
|
||||
|
||||
class RfSwitch : public QObject, public DevicePlugin
|
||||
class RfSwitch : public DevicePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
|
|||
|
|
@ -63,19 +63,6 @@ void JsonRPCServer::processData(int clientId, const QByteArray &jsonData)
|
|||
} else {
|
||||
qDebug() << "got unknown namespace" << targetNamspace;
|
||||
}
|
||||
|
||||
//DeviceJsonPlugin plugin;
|
||||
// {<device>: "name", <method>: "doBla", <id>: "int", <command> { <name>: "name", ... }}
|
||||
|
||||
// if(command.value("device").toString() == m_device->deviceName()){
|
||||
// return m_device->process(command,params);
|
||||
// }
|
||||
// if(command.value("device").toString() == m_radio->deviceName()){
|
||||
// return m_radio->process(command,params);
|
||||
// }else{
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
QVariantMap JsonRPCServer::packDeviceClass(const DeviceClass &deviceClass)
|
||||
|
|
@ -92,6 +79,7 @@ QVariantMap JsonRPCServer::packDeviceClass(const DeviceClass &deviceClass)
|
|||
|
||||
triggerTypes.append(triggerMap);
|
||||
}
|
||||
variant.insert("params", deviceClass.params());
|
||||
variant.insert("triggers", triggerTypes);
|
||||
return variant;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue