added means to emit triggers
This commit is contained in:
parent
c46403b4c0
commit
2f0520189d
@ -27,3 +27,23 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap Device::params() const
|
||||||
|
{
|
||||||
|
return m_params;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setParams(const QVariantMap ¶ms)
|
||||||
|
{
|
||||||
|
m_params = params;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
#ifndef DEVICE_H
|
#ifndef DEVICE_H
|
||||||
#define DEVICE_H
|
#define DEVICE_H
|
||||||
|
|
||||||
|
#include "trigger.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
class Device: public QObject
|
class Device: public QObject
|
||||||
{
|
{
|
||||||
@ -18,10 +21,18 @@ 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);
|
||||||
|
|
||||||
|
QVariantMap params() const;
|
||||||
|
void setParams(const QVariantMap ¶ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_id;
|
QUuid m_id;
|
||||||
QUuid m_deviceClassId;
|
QUuid m_deviceClassId;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
QList<Trigger> m_triggers;
|
||||||
|
QVariantMap m_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -35,3 +35,13 @@ void DeviceClass::setTriggers(const QList<TriggerType> &triggers)
|
|||||||
{
|
{
|
||||||
m_triggers = 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;
|
QList<TriggerType> triggers() const;
|
||||||
void setTriggers(const QList<TriggerType> &triggers);
|
void setTriggers(const QList<TriggerType> &triggers);
|
||||||
|
|
||||||
|
QVariantList params() const;
|
||||||
|
void setParams(const QVariantList ¶ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_id;
|
QUuid m_id;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QList<TriggerType> m_triggers;
|
QList<TriggerType> m_triggers;
|
||||||
|
QVariantList m_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -25,10 +25,12 @@ QList<DeviceClass> DeviceManager::supportedDevices()
|
|||||||
return m_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 *device = new Device(deviceClass.id(), this);
|
||||||
device->setName(deviceClass.name());
|
device->setName(deviceClass.name());
|
||||||
|
device->setParams(params);
|
||||||
|
m_configuredDevices.append(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Device *> DeviceManager::configuredDevices() const
|
QList<Device *> DeviceManager::configuredDevices() const
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#define DEVICEMANAGER_H
|
#define DEVICEMANAGER_H
|
||||||
|
|
||||||
#include "deviceclass.h"
|
#include "deviceclass.h"
|
||||||
|
#include "trigger.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ public:
|
|||||||
|
|
||||||
QList<DeviceClass> supportedDevices();
|
QList<DeviceClass> supportedDevices();
|
||||||
|
|
||||||
void createDevice(const DeviceClass &deviceClass);
|
void createDevice(const DeviceClass &deviceClass, const QVariantMap ¶ms);
|
||||||
|
|
||||||
QList<Device*> configuredDevices() const;
|
QList<Device*> configuredDevices() const;
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ public:
|
|||||||
Radio433 *radio433() const;
|
Radio433 *radio433() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void emitTrigger(const Trigger &trigger);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void loadPlugins();
|
void loadPlugins();
|
||||||
|
|||||||
@ -8,8 +8,9 @@
|
|||||||
|
|
||||||
class DeviceManager;
|
class DeviceManager;
|
||||||
|
|
||||||
class DevicePlugin
|
class DevicePlugin: public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DevicePlugin();
|
DevicePlugin();
|
||||||
virtual ~DevicePlugin();
|
virtual ~DevicePlugin();
|
||||||
@ -23,7 +24,7 @@ public:
|
|||||||
virtual QList<DeviceClass> supportedDevices() const = 0;
|
virtual QList<DeviceClass> supportedDevices() const = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void emitTrigger(const Trigger &trigger);
|
void emitTrigger(const QUuid &triggerId, const QVariantMap ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DeviceManager *deviceManager() const;
|
DeviceManager *deviceManager() const;
|
||||||
@ -31,6 +32,6 @@ protected:
|
|||||||
private:
|
private:
|
||||||
DeviceManager *m_deviceManager;
|
DeviceManager *m_deviceManager;
|
||||||
};
|
};
|
||||||
Q_DECLARE_INTERFACE(DevicePlugin, "org.hoveyourhome.DevicePlugin")
|
Q_DECLARE_INTERFACE(DevicePlugin, "org.hiveyourhome.DevicePlugin")
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -10,14 +10,15 @@ SOURCES += device.cpp \
|
|||||||
deviceplugin.cpp \
|
deviceplugin.cpp \
|
||||||
radio433.cpp \
|
radio433.cpp \
|
||||||
gpio.cpp \
|
gpio.cpp \
|
||||||
trigger.cpp \
|
trigger.cpp \
|
||||||
triggertype.cpp
|
triggertype.cpp
|
||||||
|
|
||||||
HEADERS += device.h \
|
HEADERS += device.h \
|
||||||
deviceclass.h \
|
deviceclass.h \
|
||||||
devicemanager.h \
|
devicemanager.h \
|
||||||
|
deviceplugin.h \
|
||||||
radio433.h \
|
radio433.h \
|
||||||
gpio.h \
|
gpio.h \
|
||||||
trigger.h \
|
trigger.h \
|
||||||
triggertype.h
|
triggertype.h
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "rfswitch.h"
|
#include "rfswitch.h"
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
#include "devicemanager.h"
|
#include "devicemanager.h"
|
||||||
#include "radio433.h"
|
#include "radio433.h"
|
||||||
|
|
||||||
@ -21,11 +22,28 @@ QList<DeviceClass> RfSwitch::supportedDevices() const
|
|||||||
|
|
||||||
DeviceClass deviceClassRfRemote(QUuid::createUuid());
|
DeviceClass deviceClassRfRemote(QUuid::createUuid());
|
||||||
deviceClassRfRemote.setName("RF Remote");
|
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;
|
QList<TriggerType> buttonTriggers;
|
||||||
|
|
||||||
QVariantList params;
|
QVariantList params;
|
||||||
QVariantMap param;
|
QVariantMap param;
|
||||||
param.insert("name", "on");
|
param.insert("name", "power");
|
||||||
param.insert("type", "bool");
|
param.insert("type", "bool");
|
||||||
params.append(param);
|
params.append(param);
|
||||||
|
|
||||||
@ -75,5 +93,43 @@ void RfSwitch::dataReceived(QList<int> rawData)
|
|||||||
{
|
{
|
||||||
qDebug() << "data received from Radio433" << 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"
|
#include "deviceplugin.h"
|
||||||
|
|
||||||
class RfSwitch : public QObject, public DevicePlugin
|
class RfSwitch : public DevicePlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|||||||
@ -63,19 +63,6 @@ void JsonRPCServer::processData(int clientId, const QByteArray &jsonData)
|
|||||||
} else {
|
} else {
|
||||||
qDebug() << "got unknown namespace" << targetNamspace;
|
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)
|
QVariantMap JsonRPCServer::packDeviceClass(const DeviceClass &deviceClass)
|
||||||
@ -92,6 +79,7 @@ QVariantMap JsonRPCServer::packDeviceClass(const DeviceClass &deviceClass)
|
|||||||
|
|
||||||
triggerTypes.append(triggerMap);
|
triggerTypes.append(triggerMap);
|
||||||
}
|
}
|
||||||
|
variant.insert("params", deviceClass.params());
|
||||||
variant.insert("triggers", triggerTypes);
|
variant.insert("triggers", triggerTypes);
|
||||||
return variant;
|
return variant;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user