introduce ParamType and Param, to get more type safety and better possibilities for comparison in rules
This commit is contained in:
parent
6485ebbff5
commit
e312e36ab9
@ -167,7 +167,7 @@ DeviceManager::DeviceError DeviceManager::discoverDevices(const DeviceClassId &d
|
|||||||
Optionally you can supply an id yourself if you must keep track of the added device. If you don't supply it, a new one will
|
Optionally you can supply an id yourself if you must keep track of the added device. If you don't supply it, a new one will
|
||||||
be generated.
|
be generated.
|
||||||
*/
|
*/
|
||||||
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const QVariantMap ¶ms, const DeviceId id)
|
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id)
|
||||||
{
|
{
|
||||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||||
if (!deviceClass.isValid()) {
|
if (!deviceClass.isValid()) {
|
||||||
@ -198,7 +198,7 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassI
|
|||||||
return addConfiguredDeviceInternal(deviceClassId, descriptor.params(), deviceId);
|
return addConfiguredDeviceInternal(deviceClassId, descriptor.params(), deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DeviceManager::addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QVariantMap ¶ms, const DeviceId id)
|
DeviceManager::DeviceError DeviceManager::addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id)
|
||||||
{
|
{
|
||||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||||
if (deviceClass.id().isNull()) {
|
if (deviceClass.id().isNull()) {
|
||||||
@ -207,18 +207,24 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDeviceInternal(const Devi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we have all required params
|
// Make sure we have all required params
|
||||||
foreach (const QVariant ¶m, deviceClass.params()) {
|
foreach (const ParamType ¶mType, deviceClass.params()) {
|
||||||
if (!params.contains(param.toMap().value("name").toString())) {
|
bool found = false;
|
||||||
qWarning() << "Missing parameter when creating device:" << param.toMap().value("name").toString();
|
foreach (const Param ¶m, params) {
|
||||||
|
if (param.name() == paramType.name()) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
qWarning() << "Missing parameter when creating device:" << paramType.name();
|
||||||
return DeviceErrorMissingParameter;
|
return DeviceErrorMissingParameter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Make sure we don't have unused params
|
// Make sure we don't have unused params
|
||||||
foreach (const QString ¶mId, params.keys()) {
|
foreach (const Param ¶m, params) {
|
||||||
qDebug() << "searching" << paramId << "in" << deviceClass.params();
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
foreach (const QVariant ¶m, deviceClass.params()) {
|
foreach (const ParamType ¶mType, deviceClass.params()) {
|
||||||
if (param.toMap().value("name").toString() == paramId) {
|
if (paramType.name() == param.name()) {
|
||||||
found = true;
|
found = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -399,7 +405,17 @@ void DeviceManager::loadConfiguredDevices()
|
|||||||
settings.beginGroup(idString);
|
settings.beginGroup(idString);
|
||||||
Device *device = new Device(PluginId(settings.value("pluginid").toString()), DeviceId(idString), DeviceClassId(settings.value("deviceClassId").toString()), this);
|
Device *device = new Device(PluginId(settings.value("pluginid").toString()), DeviceId(idString), DeviceClassId(settings.value("deviceClassId").toString()), this);
|
||||||
device->setName(settings.value("devicename").toString());
|
device->setName(settings.value("devicename").toString());
|
||||||
device->setParams(settings.value("params").toMap());
|
|
||||||
|
QList<Param> params;
|
||||||
|
foreach (QString paramNameString, settings.childGroups()) {
|
||||||
|
settings.beginGroup(paramNameString);
|
||||||
|
Param param(paramNameString.remove(QRegExp("^Param-")));
|
||||||
|
param.setValue(settings.value("value"));
|
||||||
|
param.setOperand((Param::OperandType)settings.value("operand").toInt());
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
device->setParams(params);
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
setupDevice(device);
|
setupDevice(device);
|
||||||
@ -417,7 +433,12 @@ void DeviceManager::storeConfiguredDevices()
|
|||||||
settings.setValue("devicename", device->name());
|
settings.setValue("devicename", device->name());
|
||||||
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());
|
foreach (const Param ¶m, device->params()) {
|
||||||
|
settings.beginGroup("Param-" + param.name());
|
||||||
|
settings.setValue("value", param.value());
|
||||||
|
settings.setValue("operand", param.operand());
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,7 +72,7 @@ public:
|
|||||||
DeviceError discoverDevices(const DeviceClassId &deviceClassId, const QVariantMap ¶ms) const;
|
DeviceError discoverDevices(const DeviceClassId &deviceClassId, const QVariantMap ¶ms) const;
|
||||||
|
|
||||||
QList<Device*> configuredDevices() const;
|
QList<Device*> configuredDevices() const;
|
||||||
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QVariantMap ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||||
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &id = DeviceId::createDeviceId());
|
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &id = DeviceId::createDeviceId());
|
||||||
DeviceError removeConfiguredDevice(const DeviceId &deviceId);
|
DeviceError removeConfiguredDevice(const DeviceId &deviceId);
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ private slots:
|
|||||||
void timerEvent();
|
void timerEvent();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceError addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QVariantMap ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
DeviceError addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QList<Param> ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||||
bool setupDevice(Device *device);
|
bool setupDevice(Device *device);
|
||||||
|
|
||||||
QHash<VendorId, Vendor> m_supportedVendors;
|
QHash<VendorId, Vendor> m_supportedVendors;
|
||||||
|
|||||||
@ -20,6 +20,8 @@ SOURCES += plugin/device.cpp \
|
|||||||
types/eventtype.cpp \
|
types/eventtype.cpp \
|
||||||
types/event.cpp \
|
types/event.cpp \
|
||||||
types/vendor.cpp \
|
types/vendor.cpp \
|
||||||
|
types/paramtype.cpp \
|
||||||
|
types/param.cpp
|
||||||
|
|
||||||
HEADERS += plugin/device.h \
|
HEADERS += plugin/device.h \
|
||||||
plugin/deviceclass.h \
|
plugin/deviceclass.h \
|
||||||
@ -36,4 +38,6 @@ HEADERS += plugin/device.h \
|
|||||||
types/event.h \
|
types/event.h \
|
||||||
types/vendor.h \
|
types/vendor.h \
|
||||||
types/typeutils.h \
|
types/typeutils.h \
|
||||||
|
types/paramtype.h \
|
||||||
|
types/param.h
|
||||||
|
|
||||||
|
|||||||
@ -82,23 +82,43 @@ void Device::setName(const QString &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the parameter of this Device. It must match the parameter description in the associated \l{DeviceClass}. */
|
/*! Returns the parameter of this Device. It must match the parameter description in the associated \l{DeviceClass}. */
|
||||||
QVariantMap Device::params() const
|
QList<Param> Device::params() const
|
||||||
{
|
{
|
||||||
return m_params;
|
return m_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Sets the \a params of this Device. It must match the parameter description in the associated \l{DeviceClass}. */
|
/*! Sets the \a params of this Device. It must match the parameter description in the associated \l{DeviceClass}. */
|
||||||
void Device::setParams(const QVariantMap ¶ms)
|
void Device::setParams(const QList<Param> ¶ms)
|
||||||
{
|
{
|
||||||
m_params = params;
|
m_params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant Device::paramValue(const QString ¶mName) const
|
||||||
|
{
|
||||||
|
foreach (const Param ¶m, m_params) {
|
||||||
|
if (param.name() == paramName) {
|
||||||
|
return param.value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
/*! Returns the states of this Device. It must match the \l{StateType} description in the associated \l{DeviceClass}. */
|
/*! Returns the states of this Device. It must match the \l{StateType} description in the associated \l{DeviceClass}. */
|
||||||
QList<State> Device::states() const
|
QList<State> Device::states() const
|
||||||
{
|
{
|
||||||
return m_states;
|
return m_states;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Device::hasParam(const QString ¶mName) const
|
||||||
|
{
|
||||||
|
foreach (const Param ¶m, m_params) {
|
||||||
|
if (param.name() == paramName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Sets the \a states of this Device. It must match the \l{StateType} description in the associated \l{DeviceClass}. */
|
/*! Sets the \a states of this Device. It must match the \l{StateType} description in the associated \l{DeviceClass}. */
|
||||||
void Device::setStates(const QList<State> &states)
|
void Device::setStates(const QList<State> &states)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "plugin/deviceclass.h"
|
#include "plugin/deviceclass.h"
|
||||||
#include "types/state.h"
|
#include "types/state.h"
|
||||||
|
#include "types/param.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
@ -43,10 +44,13 @@ public:
|
|||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|
||||||
QVariantMap params() const;
|
QList<Param> params() const;
|
||||||
void setParams(const QVariantMap ¶ms);
|
void setParams(const QList<Param> ¶ms);
|
||||||
|
|
||||||
|
QVariant paramValue(const QString ¶mName) const;
|
||||||
|
|
||||||
QList<State> states() const;
|
QList<State> states() const;
|
||||||
|
bool hasParam(const QString ¶mName) const;
|
||||||
void setStates(const QList<State> &states);
|
void setStates(const QList<State> &states);
|
||||||
|
|
||||||
bool hasState(const StateTypeId &stateTypeId) const;
|
bool hasState(const StateTypeId &stateTypeId) const;
|
||||||
@ -65,7 +69,7 @@ private:
|
|||||||
DeviceClassId m_deviceClassId;
|
DeviceClassId m_deviceClassId;
|
||||||
PluginId m_pluginId;
|
PluginId m_pluginId;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QVariantMap m_params;
|
QList<Param> m_params;
|
||||||
QList<State> m_states;
|
QList<State> m_states;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -129,14 +129,14 @@ void DeviceClass::setActions(const QList<ActionType> &actionTypes)
|
|||||||
|
|
||||||
/*! Returns the params description of this DeviceClass. \{Device}{Devices} created
|
/*! Returns the params description of this DeviceClass. \{Device}{Devices} created
|
||||||
from this DeviceClass must have their params matching to this template. */
|
from this DeviceClass must have their params matching to this template. */
|
||||||
QVariantList DeviceClass::params() const
|
QList<ParamType> DeviceClass::params() const
|
||||||
{
|
{
|
||||||
return m_params;
|
return m_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Set the \a params of this DeviceClass. \{Device}{Devices} created
|
/*! Set the \a params of this DeviceClass. \{Device}{Devices} created
|
||||||
from this DeviceClass must have their actions matching to this template. */
|
from this DeviceClass must have their actions matching to this template. */
|
||||||
void DeviceClass::setParams(const QVariantList ¶ms)
|
void DeviceClass::setParams(const QList<ParamType> ¶ms)
|
||||||
{
|
{
|
||||||
m_params = params;
|
m_params = params;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
#include "types/eventtype.h"
|
#include "types/eventtype.h"
|
||||||
#include "types/actiontype.h"
|
#include "types/actiontype.h"
|
||||||
#include "types/statetype.h"
|
#include "types/statetype.h"
|
||||||
|
#include "types/paramtype.h"
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
@ -62,8 +63,8 @@ public:
|
|||||||
QList<ActionType> actions() const;
|
QList<ActionType> actions() const;
|
||||||
void setActions(const QList<ActionType> &actionTypes);
|
void setActions(const QList<ActionType> &actionTypes);
|
||||||
|
|
||||||
QVariantList params() const;
|
QList<ParamType> params() const;
|
||||||
void setParams(const QVariantList ¶ms);
|
void setParams(const QList<ParamType> ¶ms);
|
||||||
|
|
||||||
CreateMethod createMethod() const;
|
CreateMethod createMethod() const;
|
||||||
void setCreateMethod(CreateMethod createMethod);
|
void setCreateMethod(CreateMethod createMethod);
|
||||||
@ -80,7 +81,7 @@ private:
|
|||||||
QList<StateType> m_states;
|
QList<StateType> m_states;
|
||||||
QList<EventType> m_events;
|
QList<EventType> m_events;
|
||||||
QList<ActionType> m_actions;
|
QList<ActionType> m_actions;
|
||||||
QVariantList m_params;
|
QList<ParamType> m_params;
|
||||||
CreateMethod m_createMethod;
|
CreateMethod m_createMethod;
|
||||||
SetupMethod m_setupMethod;
|
SetupMethod m_setupMethod;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -58,12 +58,12 @@ void DeviceDescriptor::setDescription(const QString &description)
|
|||||||
m_description = description;
|
m_description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap DeviceDescriptor::params() const
|
QList<Param> DeviceDescriptor::params() const
|
||||||
{
|
{
|
||||||
return m_params;
|
return m_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceDescriptor::setParams(const QVariantMap ¶ms)
|
void DeviceDescriptor::setParams(const QList<Param> ¶ms)
|
||||||
{
|
{
|
||||||
m_params = params;
|
m_params = params;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#define DEVICEDESCRIPTION_H
|
#define DEVICEDESCRIPTION_H
|
||||||
|
|
||||||
#include <typeutils.h>
|
#include <typeutils.h>
|
||||||
|
#include <types/param.h>
|
||||||
|
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
|
||||||
@ -23,15 +24,15 @@ public:
|
|||||||
QString description() const;
|
QString description() const;
|
||||||
void setDescription(const QString &description);
|
void setDescription(const QString &description);
|
||||||
|
|
||||||
QVariantMap params() const;
|
QList<Param> params() const;
|
||||||
void setParams(const QVariantMap ¶ms);
|
void setParams(const QList<Param> ¶ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceDescriptorId m_id;
|
DeviceDescriptorId m_id;
|
||||||
DeviceClassId m_deviceClassId;
|
DeviceClassId m_deviceClassId;
|
||||||
QString m_title;
|
QString m_title;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
QVariantMap m_params;
|
QList<Param> m_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEDESCRIPTION_H
|
#endif // DEVICEDESCRIPTION_H
|
||||||
|
|||||||
@ -216,12 +216,12 @@ QList<Device *> DevicePlugin::myDevices() const
|
|||||||
Find a certain device from myDevices() by its params. All parameters must
|
Find a certain device from myDevices() by its params. All parameters must
|
||||||
match or the device will not be found. Be prepared for nullptrs.
|
match or the device will not be found. Be prepared for nullptrs.
|
||||||
*/
|
*/
|
||||||
Device *DevicePlugin::findDeviceByParams(const QVariantMap ¶ms) const
|
Device *DevicePlugin::findDeviceByParams(const QList<Param> ¶ms) const
|
||||||
{
|
{
|
||||||
foreach (Device *device, myDevices()) {
|
foreach (Device *device, myDevices()) {
|
||||||
bool matching = true;
|
bool matching = true;
|
||||||
foreach (const QString ¶mName, device->params().keys()) {
|
foreach (const Param ¶m, params) {
|
||||||
if (device->params().value(paramName) == params.value(paramName)) {
|
if (device->paramValue(param.name()) == param.value()) {
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,7 +74,7 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
DeviceManager *deviceManager() const;
|
DeviceManager *deviceManager() const;
|
||||||
QList<Device*> myDevices() const;
|
QList<Device*> myDevices() const;
|
||||||
Device* findDeviceByParams(const QVariantMap ¶ms) const;
|
Device* findDeviceByParams(const QList<Param> ¶ms) const;
|
||||||
|
|
||||||
void transmitData(QList<int> rawData);
|
void transmitData(QList<int> rawData);
|
||||||
|
|
||||||
|
|||||||
@ -58,13 +58,23 @@ DeviceId Action::deviceId() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the parameters for this Action.*/
|
/*! Returns the parameters for this Action.*/
|
||||||
QVariantMap Action::params() const
|
QList<Param> Action::params() const
|
||||||
{
|
{
|
||||||
return m_params;
|
return m_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Set the the parameters for this Action. \a params must match the template in the \l{ActionType} referred by \l{Action::actionTypeId()}*/
|
/*! Set the the parameters for this Action. \a params must match the template in the \l{ActionType} referred by \l{Action::actionTypeId()}*/
|
||||||
void Action::setParams(const QVariantMap ¶ms)
|
void Action::setParams(const QList<Param> ¶ms)
|
||||||
{
|
{
|
||||||
m_params = params;
|
m_params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Param Action::param(const QString ¶mName) const
|
||||||
|
{
|
||||||
|
foreach (const Param ¶m, m_params) {
|
||||||
|
if (param.name() == paramName) {
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Param(QString());
|
||||||
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
#define ACTION_H
|
#define ACTION_H
|
||||||
|
|
||||||
#include "typeutils.h"
|
#include "typeutils.h"
|
||||||
|
#include "param.h"
|
||||||
|
|
||||||
#include <QVariantList>
|
#include <QVariantList>
|
||||||
|
|
||||||
@ -33,13 +34,14 @@ public:
|
|||||||
ActionTypeId actionTypeId() const;
|
ActionTypeId actionTypeId() const;
|
||||||
DeviceId deviceId() const;
|
DeviceId deviceId() const;
|
||||||
|
|
||||||
QVariantMap params() const;
|
QList<Param> params() const;
|
||||||
void setParams(const QVariantMap ¶ms);
|
void setParams(const QList<Param> ¶ms);
|
||||||
|
Param param(const QString ¶mName) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ActionTypeId m_actionTypeId;
|
ActionTypeId m_actionTypeId;
|
||||||
DeviceId m_deviceId;
|
DeviceId m_deviceId;
|
||||||
QVariantMap m_params;
|
QList<Param> m_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ACTION_H
|
#endif // ACTION_H
|
||||||
|
|||||||
@ -36,7 +36,7 @@
|
|||||||
/*! Constructs a Event reflecting the \l{Event} given by \a EventTypeId, associated with
|
/*! Constructs a Event reflecting the \l{Event} given by \a EventTypeId, associated with
|
||||||
the \l{Device} given by \a deviceId and the parameters given by \a params. The parameters must
|
the \l{Device} given by \a deviceId and the parameters given by \a params. The parameters must
|
||||||
match the description in the reflecting \l{Event}.*/
|
match the description in the reflecting \l{Event}.*/
|
||||||
Event::Event(const EventTypeId &eventTypeId, const DeviceId &deviceId, const QVariantMap ¶ms):
|
Event::Event(const EventTypeId &eventTypeId, const DeviceId &deviceId, const QList<Param> ¶ms):
|
||||||
m_eventTypeId(eventTypeId),
|
m_eventTypeId(eventTypeId),
|
||||||
m_deviceId(deviceId),
|
m_deviceId(deviceId),
|
||||||
m_params(params)
|
m_params(params)
|
||||||
@ -56,31 +56,43 @@ DeviceId Event::deviceId() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the parameters of this Event.*/
|
/*! Returns the parameters of this Event.*/
|
||||||
QVariantMap Event::params() const
|
QList<Param> Event::params() const
|
||||||
{
|
{
|
||||||
return m_params;
|
return m_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Set the parameters of this Event to \a params.*/
|
/*! Set the parameters of this Event to \a params.*/
|
||||||
void Event::setParams(const QVariantMap ¶ms)
|
void Event::setParams(const QList<Param> ¶ms)
|
||||||
{
|
{
|
||||||
m_params = params;
|
m_params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Param Event::param(const QString ¶mName) const
|
||||||
|
{
|
||||||
|
foreach (const Param ¶m, m_params) {
|
||||||
|
if (param.name() == paramName) {
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Param(QString());
|
||||||
|
}
|
||||||
|
|
||||||
/*! Compare this Event to the Event given by \a other.
|
/*! Compare this Event to the Event given by \a other.
|
||||||
Events are equal (returns true) if eventTypeId, deviceId and params match. */
|
Events are equal (returns true) if eventTypeId, deviceId and params match. */
|
||||||
bool Event::operator ==(const Event &other) const
|
bool Event::operator ==(const Event &other) const
|
||||||
{
|
{
|
||||||
|
bool paramsMatch = true;
|
||||||
bool result =m_eventTypeId == other.eventTypeId()
|
foreach (const Param &otherParam, other.params()) {
|
||||||
&& m_deviceId == other.deviceId()
|
Param param = this->param(otherParam.name());
|
||||||
&& m_params == other.params();
|
if (!param.isValid() || param.value() != otherParam.value()) {
|
||||||
|
paramsMatch = false;
|
||||||
qDebug() << "comparing event" << *this << "with" << other << "result is" << result << "params" << m_params << "other" << other.params();
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return m_eventTypeId == other.eventTypeId()
|
return m_eventTypeId == other.eventTypeId()
|
||||||
&& m_deviceId == other.deviceId()
|
&& m_deviceId == other.deviceId()
|
||||||
&& m_params == other.params();
|
&& paramsMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDebug operator<<(QDebug dbg, const Event &event)
|
QDebug operator<<(QDebug dbg, const Event &event)
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
#define EVENT_H
|
#define EVENT_H
|
||||||
|
|
||||||
#include "typeutils.h"
|
#include "typeutils.h"
|
||||||
|
#include "types/param.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariantList>
|
#include <QVariantList>
|
||||||
@ -28,20 +29,21 @@
|
|||||||
class Event
|
class Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Event(const EventTypeId &eventTypeId, const DeviceId &deviceId, const QVariantMap ¶ms);
|
Event(const EventTypeId &eventTypeId, const DeviceId &deviceId, const QList<Param> ¶ms = QList<Param>());
|
||||||
|
|
||||||
EventTypeId eventTypeId() const;
|
EventTypeId eventTypeId() const;
|
||||||
DeviceId deviceId() const;
|
DeviceId deviceId() const;
|
||||||
|
|
||||||
QVariantMap params() const;
|
QList<Param> params() const;
|
||||||
void setParams(const QVariantMap ¶ms);
|
void setParams(const QList<Param> ¶ms);
|
||||||
|
Param param(const QString ¶mName) const;
|
||||||
|
|
||||||
bool operator ==(const Event &other) const;
|
bool operator ==(const Event &other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventTypeId m_eventTypeId;
|
EventTypeId m_eventTypeId;
|
||||||
DeviceId m_deviceId;
|
DeviceId m_deviceId;
|
||||||
QVariantMap m_params;
|
QList<Param> m_params;
|
||||||
};
|
};
|
||||||
QDebug operator<<(QDebug dbg, const Event &event);
|
QDebug operator<<(QDebug dbg, const Event &event);
|
||||||
QDebug operator<<(QDebug dbg, const QList<Event> &events);
|
QDebug operator<<(QDebug dbg, const QList<Event> &events);
|
||||||
|
|||||||
62
libguh/types/param.cpp
Normal file
62
libguh/types/param.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include "param.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
Param::Param(const QString &name, const QVariant &value):
|
||||||
|
m_name (name),
|
||||||
|
m_value(value),
|
||||||
|
m_operand(OperandTypeEquals)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Param::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Param::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant Param::value() const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Param::setValue(const QVariant &value)
|
||||||
|
{
|
||||||
|
m_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Param::OperandType Param::operand() const
|
||||||
|
{
|
||||||
|
return m_operand;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Param::setOperand(Param::OperandType operand)
|
||||||
|
{
|
||||||
|
m_operand = operand;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Param::isValid() const
|
||||||
|
{
|
||||||
|
return !m_name.isEmpty() && m_value.isValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug dbg, const Param ¶m)
|
||||||
|
{
|
||||||
|
dbg.nospace() << "Param(Name: " << param.name() << ", Value:" << param.value() << ")";
|
||||||
|
|
||||||
|
return dbg.space();
|
||||||
|
}
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug dbg, const QList<Param> ¶ms)
|
||||||
|
{
|
||||||
|
dbg.nospace() << "ParamList (count:" << params.count() << ")";
|
||||||
|
for (int i = 0; i < params.count(); i++ ) {
|
||||||
|
dbg.nospace() << " " << i << ": " << params.at(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dbg.space();
|
||||||
|
}
|
||||||
41
libguh/types/param.h
Normal file
41
libguh/types/param.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#ifndef PARAM_H
|
||||||
|
#define PARAM_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
class Param
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum OperandType {
|
||||||
|
OperandTypeEquals,
|
||||||
|
OperandTypeNotEquals,
|
||||||
|
OperandTypeLess,
|
||||||
|
OperandTypeGreater,
|
||||||
|
OperandTypeLessThan,
|
||||||
|
OperandTypeGreaterThan
|
||||||
|
};
|
||||||
|
|
||||||
|
Param(const QString &name, const QVariant &value = QVariant());
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
QVariant value() const;
|
||||||
|
void setValue(const QVariant &value);
|
||||||
|
|
||||||
|
OperandType operand() const;
|
||||||
|
void setOperand(OperandType operand);
|
||||||
|
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
QVariant m_value;
|
||||||
|
OperandType m_operand;
|
||||||
|
};
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug dbg, const Param ¶m);
|
||||||
|
QDebug operator<<(QDebug dbg, const QList<Param> ¶ms);
|
||||||
|
|
||||||
|
#endif // PARAM_H
|
||||||
58
libguh/types/paramtype.cpp
Normal file
58
libguh/types/paramtype.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "paramtype.h"
|
||||||
|
|
||||||
|
ParamType::ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue):
|
||||||
|
m_name(name),
|
||||||
|
m_type(type),
|
||||||
|
m_defaultValue(defaultValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ParamType::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant::Type ParamType::type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setType(QVariant::Type type)
|
||||||
|
{
|
||||||
|
m_type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ParamType::defaultValue() const
|
||||||
|
{
|
||||||
|
return m_defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setDefaultValue(const QVariant &defaultValue)
|
||||||
|
{
|
||||||
|
m_defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ParamType::minValue() const
|
||||||
|
{
|
||||||
|
return m_minValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setMinValue(const QVariant &minValue)
|
||||||
|
{
|
||||||
|
m_minValue = minValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ParamType::maxValue() const
|
||||||
|
{
|
||||||
|
return m_maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParamType::setMaxValue(const QVariant &maxValue)
|
||||||
|
{
|
||||||
|
m_maxValue = maxValue;
|
||||||
|
}
|
||||||
34
libguh/types/paramtype.h
Normal file
34
libguh/types/paramtype.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef PARAMTYPE_H
|
||||||
|
#define PARAMTYPE_H
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
class ParamType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue = QVariant());
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
QVariant::Type type() const;
|
||||||
|
void setType(QVariant::Type type);
|
||||||
|
|
||||||
|
QVariant defaultValue() const;
|
||||||
|
void setDefaultValue(const QVariant &defaultValue);
|
||||||
|
|
||||||
|
QVariant minValue() const;
|
||||||
|
void setMinValue(const QVariant &minValue);
|
||||||
|
|
||||||
|
QVariant maxValue() const;
|
||||||
|
void setMaxValue(const QVariant &maxValue);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
QVariant::Type m_type;
|
||||||
|
QVariant m_defaultValue;
|
||||||
|
QVariant m_minValue;
|
||||||
|
QVariant m_maxValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PARAMTYPE_H
|
||||||
@ -28,14 +28,4 @@ DECLARE_TYPE_ID(StateType)
|
|||||||
DECLARE_TYPE_ID(ActionType)
|
DECLARE_TYPE_ID(ActionType)
|
||||||
DECLARE_TYPE_ID(Plugin)
|
DECLARE_TYPE_ID(Plugin)
|
||||||
|
|
||||||
|
|
||||||
enum ParamOperand {
|
|
||||||
ParamOperandEquals,
|
|
||||||
ParamOperandNotEquals,
|
|
||||||
ParamOperandLess,
|
|
||||||
ParamOperandGreater,
|
|
||||||
ParamOperandLessThan,
|
|
||||||
ParamOperandGreaterThan
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TYPEUTILS_H
|
#endif // TYPEUTILS_H
|
||||||
|
|||||||
@ -85,8 +85,10 @@ bool DevicePluginBoblight::configureAutoDevice(QList<Device *> loadedDevices, De
|
|||||||
if (loadedDevices.count() < m_bobClient->lightsCount()) {
|
if (loadedDevices.count() < m_bobClient->lightsCount()) {
|
||||||
int index = loadedDevices.count();
|
int index = loadedDevices.count();
|
||||||
device->setName("Boblight Channel " + QString::number(index));
|
device->setName("Boblight Channel " + QString::number(index));
|
||||||
QVariantMap params;
|
QList<Param> params;
|
||||||
params.insert("channel", index);
|
Param param("channel");
|
||||||
|
param.setValue(index);
|
||||||
|
params.append(param);
|
||||||
device->setParams(params);
|
device->setParams(params);
|
||||||
device->setStateValue(colorStateTypeId, m_bobClient->currentColor(index));
|
device->setStateValue(colorStateTypeId, m_bobClient->currentColor(index));
|
||||||
return true;
|
return true;
|
||||||
@ -120,12 +122,12 @@ DeviceManager::DeviceError DevicePluginBoblight::executeAction(Device *device, c
|
|||||||
if (!m_bobClient->connected()) {
|
if (!m_bobClient->connected()) {
|
||||||
return DeviceManager::DeviceErrorSetupFailed;
|
return DeviceManager::DeviceErrorSetupFailed;
|
||||||
}
|
}
|
||||||
QColor newColor = action.params().first().value<QColor>();
|
QColor newColor = action.param("color").value().value<QColor>();
|
||||||
if (!newColor.isValid()) {
|
if (!newColor.isValid()) {
|
||||||
return DeviceManager::DeviceErrorActionParameterError;
|
return DeviceManager::DeviceErrorActionParameterError;
|
||||||
}
|
}
|
||||||
qDebug() << "executing boblight action" << newColor;
|
qDebug() << "executing boblight action" << newColor;
|
||||||
m_bobClient->setColor(device->params().value("channel").toInt(), newColor);
|
m_bobClient->setColor(device->paramValue("channel").toInt(), newColor);
|
||||||
m_bobClient->sync();
|
m_bobClient->sync();
|
||||||
|
|
||||||
device->setStateValue(colorStateTypeId, newColor);
|
device->setStateValue(colorStateTypeId, newColor);
|
||||||
|
|||||||
@ -91,22 +91,16 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
|
|||||||
DeviceClass deviceClassElroRemote(pluginId(), elroVendorId, elroRemoteId);
|
DeviceClass deviceClassElroRemote(pluginId(), elroVendorId, elroRemoteId);
|
||||||
deviceClassElroRemote.setName("Elro Remote");
|
deviceClassElroRemote.setName("Elro Remote");
|
||||||
|
|
||||||
QVariantList deviceParamsRemote;
|
QList<ParamType> deviceParamsRemote;
|
||||||
QVariantMap channelParam;
|
ParamType channelParam = ParamType("channel1", QVariant::Bool);
|
||||||
channelParam.insert("name", "channel1");
|
|
||||||
channelParam.insert("type", "bool");
|
|
||||||
deviceParamsRemote.append(channelParam);
|
deviceParamsRemote.append(channelParam);
|
||||||
channelParam.insert("name", "channel2");
|
channelParam = ParamType("channel2", QVariant::Bool);
|
||||||
channelParam.insert("type", "bool");
|
|
||||||
deviceParamsRemote.append(channelParam);
|
deviceParamsRemote.append(channelParam);
|
||||||
channelParam.insert("name", "channel3");
|
channelParam = ParamType("channel3", QVariant::Bool);
|
||||||
channelParam.insert("type", "bool");
|
|
||||||
deviceParamsRemote.append(channelParam);
|
deviceParamsRemote.append(channelParam);
|
||||||
channelParam.insert("name", "channel4");
|
channelParam = ParamType("channel4", QVariant::Bool);
|
||||||
channelParam.insert("type", "bool");
|
|
||||||
deviceParamsRemote.append(channelParam);
|
deviceParamsRemote.append(channelParam);
|
||||||
channelParam.insert("name", "channel5");
|
channelParam = ParamType("channel5", QVariant::Bool);
|
||||||
channelParam.insert("type", "bool");
|
|
||||||
deviceParamsRemote.append(channelParam);
|
deviceParamsRemote.append(channelParam);
|
||||||
|
|
||||||
deviceClassElroRemote.setParams(deviceParamsRemote);
|
deviceClassElroRemote.setParams(deviceParamsRemote);
|
||||||
@ -152,37 +146,26 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
|
|||||||
DeviceClass deviceClassElroSwitch(pluginId(), elroVendorId, elroSwitchId);
|
DeviceClass deviceClassElroSwitch(pluginId(), elroVendorId, elroSwitchId);
|
||||||
deviceClassElroSwitch.setName("Elro Power Switch");
|
deviceClassElroSwitch.setName("Elro Power Switch");
|
||||||
|
|
||||||
QVariantList deviceParamsSwitch;
|
QList<ParamType> deviceParamsSwitch;
|
||||||
QVariantMap paramSwitch;
|
ParamType paramSwitch = ParamType("channel1", QVariant::Bool);
|
||||||
paramSwitch.insert("name", "channel1");
|
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
paramSwitch.insert("name", "channel2");
|
paramSwitch = ParamType("channel2", QVariant::Bool);
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
paramSwitch.insert("name", "channel3");
|
paramSwitch = ParamType("channel3", QVariant::Bool);
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
paramSwitch.insert("name", "channel4");
|
paramSwitch = ParamType("channel4", QVariant::Bool);
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
paramSwitch.insert("name", "channel5");
|
paramSwitch = ParamType("channel5", QVariant::Bool);
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
paramSwitch.insert("name", "A");
|
paramSwitch = ParamType("channel6", QVariant::Bool);
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
paramSwitch.insert("name", "B");
|
paramSwitch = ParamType("channel7", QVariant::Bool);
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
paramSwitch.insert("name", "C");
|
paramSwitch = ParamType("channel8", QVariant::Bool);
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
paramSwitch.insert("name", "D");
|
paramSwitch = ParamType("channel9", QVariant::Bool);
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
paramSwitch.insert("name", "E");
|
paramSwitch = ParamType("channel10", QVariant::Bool);
|
||||||
paramSwitch.insert("type", "bool");
|
|
||||||
deviceParamsSwitch.append(paramSwitch);
|
deviceParamsSwitch.append(paramSwitch);
|
||||||
|
|
||||||
deviceClassElroSwitch.setParams(deviceParamsSwitch);
|
deviceClassElroSwitch.setParams(deviceParamsSwitch);
|
||||||
@ -230,27 +213,27 @@ DeviceManager::DeviceError DevicePluginElro::executeAction(Device *device, const
|
|||||||
// =======================================
|
// =======================================
|
||||||
// create the bincode
|
// create the bincode
|
||||||
// channels
|
// channels
|
||||||
if(device->params().value("channel1").toBool()){
|
if(device->paramValue("channel1").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
if(device->params().value("channel2").toBool()){
|
if(device->paramValue("channel2").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
if(device->params().value("channel3").toBool()){
|
if(device->paramValue("channel3").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
if(device->params().value("channel4").toBool()){
|
if(device->paramValue("channel4").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
if(device->params().value("channel5").toBool()){
|
if(device->paramValue("channel5").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
@ -258,33 +241,33 @@ DeviceManager::DeviceError DevicePluginElro::executeAction(Device *device, const
|
|||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// Buttons
|
// Buttons
|
||||||
if(device->params().value("A").toBool()){
|
if(device->paramValue("A").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
if(device->params().value("B").toBool()){
|
if(device->paramValue("B").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
if(device->params().value("C").toBool()){
|
if(device->paramValue("C").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
if(device->params().value("D").toBool()){
|
if(device->paramValue("D").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
if(device->params().value("E").toBool()){
|
if(device->paramValue("E").toBool()){
|
||||||
binCode.append("00");
|
binCode.append("00");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("01");
|
binCode.append("01");
|
||||||
}
|
}
|
||||||
// Power
|
// Power
|
||||||
if(action.params().value("power").toBool()){
|
if(action.param("power").value().toBool()){
|
||||||
binCode.append("0001");
|
binCode.append("0001");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("0100");
|
binCode.append("0100");
|
||||||
@ -312,7 +295,7 @@ DeviceManager::DeviceError DevicePluginElro::executeAction(Device *device, const
|
|||||||
// =======================================
|
// =======================================
|
||||||
// send data to driver
|
// send data to driver
|
||||||
//qDebug() << "rawData" << rawData;
|
//qDebug() << "rawData" << rawData;
|
||||||
qDebug() << "transmit" << pluginName() << action.params().value("power").toBool();
|
qDebug() << "transmit" << pluginName() << action.param("power").value().toBool();
|
||||||
transmitData(rawData);
|
transmitData(rawData);
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
@ -409,11 +392,11 @@ void DevicePluginElro::radioData(QList<int> rawData)
|
|||||||
Device *device = 0;
|
Device *device = 0;
|
||||||
QList<Device*> deviceList = deviceManager()->findConfiguredDevices(elroRemoteId);
|
QList<Device*> deviceList = deviceManager()->findConfiguredDevices(elroRemoteId);
|
||||||
foreach (Device *dev, deviceList) {
|
foreach (Device *dev, deviceList) {
|
||||||
if (dev->params().contains("channel1") && dev->params().value("channel1").toBool() == group.at(0) &&
|
if (dev->hasParam("channel1") && dev->paramValue("channel1").toBool() == group.at(0) &&
|
||||||
dev->params().contains("channel2") && dev->params().value("channel2").toBool() == group.at(1) &&
|
dev->hasParam("channel2") && dev->paramValue("channel2").toBool() == group.at(1) &&
|
||||||
dev->params().contains("channel3") && dev->params().value("channel3").toBool() == group.at(2) &&
|
dev->hasParam("channel3") && dev->paramValue("channel3").toBool() == group.at(2) &&
|
||||||
dev->params().contains("channel4") && dev->params().value("channel4").toBool() == group.at(3) &&
|
dev->hasParam("channel4") && dev->paramValue("channel4").toBool() == group.at(3) &&
|
||||||
dev->params().contains("channel5") && dev->params().value("channel5").toBool() == group.at(4)
|
dev->hasParam("channel5") && dev->paramValue("channel5").toBool() == group.at(4)
|
||||||
) {
|
) {
|
||||||
// Yippie! We found the device.
|
// Yippie! We found the device.
|
||||||
device = dev;
|
device = dev;
|
||||||
@ -425,8 +408,9 @@ void DevicePluginElro::radioData(QList<int> rawData)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap params;
|
QList<Param> params;
|
||||||
params.insert("power", power);
|
Param powerParam("power", power);
|
||||||
|
params.append(powerParam);
|
||||||
|
|
||||||
// FIXME: find a better way to get to the remote DeviceClass
|
// FIXME: find a better way to get to the remote DeviceClass
|
||||||
DeviceClass deviceClass = supportedDevices().first();
|
DeviceClass deviceClass = supportedDevices().first();
|
||||||
|
|||||||
@ -189,11 +189,9 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
|||||||
DeviceClass deviceClassIntertechnoRemote(pluginId(), intertechnoVendorId, intertechnoRemote);
|
DeviceClass deviceClassIntertechnoRemote(pluginId(), intertechnoVendorId, intertechnoRemote);
|
||||||
deviceClassIntertechnoRemote.setName("Intertechno Remote");
|
deviceClassIntertechnoRemote.setName("Intertechno Remote");
|
||||||
|
|
||||||
QVariantList remoteParams;
|
QList<ParamType> remoteParams;
|
||||||
QVariantMap familyParam;
|
|
||||||
// family code = A-P
|
// family code = A-P
|
||||||
familyParam.insert("name", "familyCode");
|
ParamType familyParam("familyCode", QVariant::String);
|
||||||
familyParam.insert("type", "string");
|
|
||||||
remoteParams.append(familyParam);
|
remoteParams.append(familyParam);
|
||||||
|
|
||||||
deviceClassIntertechnoRemote.setParams(remoteParams);
|
deviceClassIntertechnoRemote.setParams(remoteParams);
|
||||||
@ -309,11 +307,9 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
|||||||
DeviceClass deviceClassIntertechnoSwitch(pluginId(), intertechnoVendorId, intertechnoSwitch);
|
DeviceClass deviceClassIntertechnoSwitch(pluginId(), intertechnoVendorId, intertechnoSwitch);
|
||||||
deviceClassIntertechnoSwitch.setName("Intertechno Switch");
|
deviceClassIntertechnoSwitch.setName("Intertechno Switch");
|
||||||
|
|
||||||
QVariantList switchDeviceParams;
|
QList<ParamType> switchDeviceParams;
|
||||||
QVariantMap buttonParam;
|
|
||||||
// button code = 1-16
|
// button code = 1-16
|
||||||
buttonParam.insert("name", "buttonCode");
|
ParamType buttonParam("buttonCode", QVariant::Int);
|
||||||
buttonParam.insert("type", "int");
|
|
||||||
|
|
||||||
switchDeviceParams.append(familyParam);
|
switchDeviceParams.append(familyParam);
|
||||||
switchDeviceParams.append(buttonParam);
|
switchDeviceParams.append(buttonParam);
|
||||||
@ -363,7 +359,7 @@ DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device
|
|||||||
QList<int> rawData;
|
QList<int> rawData;
|
||||||
QByteArray binCode;
|
QByteArray binCode;
|
||||||
|
|
||||||
QString familyCode = device->params().value("familyCode").toString();
|
QString familyCode = device->paramValue("familyCode").toString();
|
||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// generate bin from family code
|
// generate bin from family code
|
||||||
@ -403,7 +399,7 @@ DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device
|
|||||||
return DeviceManager::DeviceErrorDeviceParameterError;
|
return DeviceManager::DeviceErrorDeviceParameterError;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString buttonCode = device->params().value("buttonCode").toString();
|
QString buttonCode = device->paramValue("buttonCode").toString();
|
||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// generate bin from button code
|
// generate bin from button code
|
||||||
@ -449,7 +445,7 @@ DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device
|
|||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// add power nibble
|
// add power nibble
|
||||||
if(action.params().value("power").toBool()){
|
if(action.param("power").value().toBool()){
|
||||||
binCode.append("0101");
|
binCode.append("0101");
|
||||||
}else{
|
}else{
|
||||||
binCode.append("0100");
|
binCode.append("0100");
|
||||||
@ -476,7 +472,7 @@ DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device
|
|||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// send data to driver
|
// send data to driver
|
||||||
qDebug() << "transmit" << pluginName() << familyCode << buttonCode << action.params().value("power").toBool();
|
qDebug() << "transmit" << pluginName() << familyCode << buttonCode << action.param("power").value().toBool();
|
||||||
transmitData(rawData);
|
transmitData(rawData);
|
||||||
|
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
@ -687,7 +683,7 @@ void DevicePluginIntertechno::radioData(QList<int> rawData)
|
|||||||
// ===================================================
|
// ===================================================
|
||||||
Device *device = 0;
|
Device *device = 0;
|
||||||
foreach (Device *dev, deviceList) {
|
foreach (Device *dev, deviceList) {
|
||||||
if (dev->params().contains("familyCode") && dev->params().value("familyCode").toString() == familyCode) {
|
if (dev->paramValue("familyCode").toString() == familyCode) {
|
||||||
// Yippie! We found the device.
|
// Yippie! We found the device.
|
||||||
device = dev;
|
device = dev;
|
||||||
break;
|
break;
|
||||||
@ -698,8 +694,9 @@ void DevicePluginIntertechno::radioData(QList<int> rawData)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap params;
|
QList<Param> params;
|
||||||
params.insert("power", power);
|
Param powerParam("power", power);
|
||||||
|
params.append(powerParam);
|
||||||
|
|
||||||
// FIXME: find a better way to get to the remote DeviceClass
|
// FIXME: find a better way to get to the remote DeviceClass
|
||||||
DeviceClass deviceClass = supportedDevices().first();
|
DeviceClass deviceClass = supportedDevices().first();
|
||||||
|
|||||||
@ -37,10 +37,8 @@ QList<DeviceClass> DevicePluginLircd::supportedDevices() const
|
|||||||
DeviceClass deviceClassLircd(pluginId(), lircdVendorId, lircdDeviceClassId);
|
DeviceClass deviceClassLircd(pluginId(), lircdVendorId, lircdDeviceClassId);
|
||||||
deviceClassLircd.setName("IR Receiver");
|
deviceClassLircd.setName("IR Receiver");
|
||||||
|
|
||||||
QVariantList params;
|
QList<ParamType> params;
|
||||||
QVariantMap remoteNameParam;
|
ParamType remoteNameParam("remoteName", QVariant::String);
|
||||||
remoteNameParam.insert("name", "remoteName");
|
|
||||||
remoteNameParam.insert("type", "string");
|
|
||||||
params.append(remoteNameParam);
|
params.append(remoteNameParam);
|
||||||
deviceClassLircd.setParams(params);
|
deviceClassLircd.setParams(params);
|
||||||
|
|
||||||
@ -102,7 +100,7 @@ void DevicePluginLircd::buttonPressed(const QString &remoteName, const QString &
|
|||||||
Device *remote = nullptr;
|
Device *remote = nullptr;
|
||||||
QList<Device*> configuredRemotes = deviceManager()->findConfiguredDevices(lircdDeviceClassId);
|
QList<Device*> configuredRemotes = deviceManager()->findConfiguredDevices(lircdDeviceClassId);
|
||||||
foreach (Device *device, configuredRemotes) {
|
foreach (Device *device, configuredRemotes) {
|
||||||
if (device->params().value("remoteName").toString() == remoteName) {
|
if (device->paramValue("remoteName").toString() == remoteName) {
|
||||||
remote = device;
|
remote = device;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -115,9 +113,10 @@ void DevicePluginLircd::buttonPressed(const QString &remoteName, const QString &
|
|||||||
qDebug() << "found remote" << remoteName << supportedDevices().first().events().count();
|
qDebug() << "found remote" << remoteName << supportedDevices().first().events().count();
|
||||||
foreach (const EventType &eventType, supportedDevices().first().events()) {
|
foreach (const EventType &eventType, supportedDevices().first().events()) {
|
||||||
if (eventType.name() == buttonName) {
|
if (eventType.name() == buttonName) {
|
||||||
QVariantMap param;
|
QList<Param> params;
|
||||||
param.insert("repeat", repeat);
|
Param param("repeat", repeat);
|
||||||
Event event(eventType.id(), remote->id(), param);
|
params.append(param);
|
||||||
|
Event event(eventType.id(), remote->id(), params);
|
||||||
emitEvent(event);
|
emitEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,10 +54,8 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||||||
DeviceClass deviceClassMock(pluginId(), guhVendorId, mockDeviceClassId);
|
DeviceClass deviceClassMock(pluginId(), guhVendorId, mockDeviceClassId);
|
||||||
deviceClassMock.setName("Mock Device");
|
deviceClassMock.setName("Mock Device");
|
||||||
|
|
||||||
QVariantList mockParams;
|
QList<ParamType> mockParams;
|
||||||
QVariantMap portParam;
|
ParamType portParam("httpport", QVariant::Int);
|
||||||
portParam.insert("name", "httpport");
|
|
||||||
portParam.insert("type", "int");
|
|
||||||
mockParams.append(portParam);
|
mockParams.append(portParam);
|
||||||
|
|
||||||
deviceClassMock.setParams(mockParams);
|
deviceClassMock.setParams(mockParams);
|
||||||
@ -137,7 +135,7 @@ PluginId DevicePluginMock::pluginId() const
|
|||||||
|
|
||||||
bool DevicePluginMock::deviceCreated(Device *device)
|
bool DevicePluginMock::deviceCreated(Device *device)
|
||||||
{
|
{
|
||||||
qDebug() << "Mockdevice created returning true" << device->params().value("httpport").toInt();
|
qDebug() << "Mockdevice created returning true" << device->paramValue("httpport").toInt();
|
||||||
|
|
||||||
HttpDaemon *daemon = new HttpDaemon(device, this);
|
HttpDaemon *daemon = new HttpDaemon(device, this);
|
||||||
m_daemons.insert(device, daemon);
|
m_daemons.insert(device, daemon);
|
||||||
@ -169,8 +167,9 @@ bool DevicePluginMock::configureAutoDevice(QList<Device *> loadedDevices, Device
|
|||||||
}
|
}
|
||||||
|
|
||||||
device->setName("Mock Device (Auto created)");
|
device->setName("Mock Device (Auto created)");
|
||||||
QVariantMap params;
|
QList<Param> params;
|
||||||
params.insert("httpport", 4242);
|
Param param("httpport", 4242);
|
||||||
|
params.append(param);
|
||||||
device->setParams(params);
|
device->setParams(params);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -202,7 +201,7 @@ void DevicePluginMock::triggerEvent(const EventTypeId &id)
|
|||||||
|
|
||||||
Device *device = m_daemons.key(daemon);
|
Device *device = m_daemons.key(daemon);
|
||||||
|
|
||||||
Event event(id, device->id(), QVariantMap());
|
Event event(id, device->id());
|
||||||
|
|
||||||
qDebug() << "Emitting event " << event.eventTypeId();
|
qDebug() << "Emitting event " << event.eventTypeId();
|
||||||
emit emitEvent(event);
|
emit emitEvent(event);
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
HttpDaemon::HttpDaemon(Device *device, DevicePlugin *parent):
|
HttpDaemon::HttpDaemon(Device *device, DevicePlugin *parent):
|
||||||
QTcpServer(parent), disabled(false), m_plugin(parent), m_device(device)
|
QTcpServer(parent), disabled(false), m_plugin(parent), m_device(device)
|
||||||
{
|
{
|
||||||
listen(QHostAddress::Any, device->params().value("httpport").toInt());
|
listen(QHostAddress::Any, device->paramValue("httpport").toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpDaemon::incomingConnection(qintptr socket)
|
void HttpDaemon::incomingConnection(qintptr socket)
|
||||||
|
|||||||
@ -192,20 +192,14 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
|
|||||||
deviceClassOpenweathermap.setCreateMethod(DeviceClass::CreateMethodDiscovery);
|
deviceClassOpenweathermap.setCreateMethod(DeviceClass::CreateMethodDiscovery);
|
||||||
|
|
||||||
// Params
|
// Params
|
||||||
QVariantList params;
|
QList<ParamType> params;
|
||||||
QVariantMap locationParam;
|
ParamType locationParam("location", QVariant::String);
|
||||||
locationParam.insert("name", "location");
|
|
||||||
locationParam.insert("type", "string");
|
|
||||||
params.append(locationParam);
|
params.append(locationParam);
|
||||||
|
|
||||||
QVariantMap countryParam;
|
ParamType countryParam("country", QVariant::String);
|
||||||
countryParam.insert("name", "country");
|
|
||||||
countryParam.insert("type", "string");
|
|
||||||
params.append(countryParam);
|
params.append(countryParam);
|
||||||
|
|
||||||
QVariantMap idParam;
|
ParamType idParam("id", QVariant::String);
|
||||||
idParam.insert("name", "id");
|
|
||||||
idParam.insert("type", "string");
|
|
||||||
params.append(idParam);
|
params.append(idParam);
|
||||||
|
|
||||||
deviceClassOpenweathermap.setParams(params);
|
deviceClassOpenweathermap.setParams(params);
|
||||||
@ -310,7 +304,7 @@ DeviceManager::DeviceError DevicePluginOpenweathermap::discoverDevices(const Dev
|
|||||||
|
|
||||||
bool DevicePluginOpenweathermap::deviceCreated(Device *device)
|
bool DevicePluginOpenweathermap::deviceCreated(Device *device)
|
||||||
{
|
{
|
||||||
m_openweaher->update(device->params().value("id").toString());
|
m_openweaher->update(device->paramValue("id").toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +317,7 @@ DeviceManager::DeviceError DevicePluginOpenweathermap::executeAction(Device *dev
|
|||||||
{
|
{
|
||||||
qDebug() << "execute action " << updateWeatherActionTypeId.toString();
|
qDebug() << "execute action " << updateWeatherActionTypeId.toString();
|
||||||
if(action.actionTypeId() == updateWeatherActionTypeId){
|
if(action.actionTypeId() == updateWeatherActionTypeId){
|
||||||
m_openweaher->update(device->params().value("id").toString());
|
m_openweaher->update(device->paramValue("id").toString());
|
||||||
}
|
}
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
@ -341,7 +335,7 @@ PluginId DevicePluginOpenweathermap::pluginId() const
|
|||||||
void DevicePluginOpenweathermap::guhTimer()
|
void DevicePluginOpenweathermap::guhTimer()
|
||||||
{
|
{
|
||||||
foreach (Device *device, deviceManager()->findConfiguredDevices(openweathermapDeviceClassId)) {
|
foreach (Device *device, deviceManager()->findConfiguredDevices(openweathermapDeviceClassId)) {
|
||||||
m_openweaher->update(device->params().value("id").toString());
|
m_openweaher->update(device->paramValue("id").toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,10 +344,13 @@ void DevicePluginOpenweathermap::searchResultsReady(const QList<QVariantMap> &ci
|
|||||||
QList<DeviceDescriptor> retList;
|
QList<DeviceDescriptor> retList;
|
||||||
foreach (QVariantMap elemant, cityList) {
|
foreach (QVariantMap elemant, cityList) {
|
||||||
DeviceDescriptor descriptor(openweathermapDeviceClassId, elemant.value("name").toString(),elemant.value("country").toString());
|
DeviceDescriptor descriptor(openweathermapDeviceClassId, elemant.value("name").toString(),elemant.value("country").toString());
|
||||||
QVariantMap params;
|
QList<Param> params;
|
||||||
params.insert("location", elemant.value("name"));
|
Param locationParam("location", elemant.value("name"));
|
||||||
params.insert("country", elemant.value("country"));
|
params.append(locationParam);
|
||||||
params.insert("id", elemant.value("id"));
|
Param countryParam("country", elemant.value("country"));
|
||||||
|
params.append(countryParam);
|
||||||
|
Param idParam("id", elemant.value("id"));
|
||||||
|
params.append(idParam);
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
retList.append(descriptor);
|
retList.append(descriptor);
|
||||||
}
|
}
|
||||||
@ -373,7 +370,7 @@ void DevicePluginOpenweathermap::weatherDataReady(const QByteArray &data)
|
|||||||
QVariantMap dataMap = jsonDoc.toVariant().toMap();
|
QVariantMap dataMap = jsonDoc.toVariant().toMap();
|
||||||
|
|
||||||
foreach (Device *device, deviceManager()->findConfiguredDevices(openweathermapDeviceClassId)) {
|
foreach (Device *device, deviceManager()->findConfiguredDevices(openweathermapDeviceClassId)) {
|
||||||
if(device->params().value("id").toString() == dataMap.value("id").toString()){
|
if(device->paramValue("id").toString() == dataMap.value("id").toString()){
|
||||||
|
|
||||||
if(dataMap.contains("clouds")){
|
if(dataMap.contains("clouds")){
|
||||||
int cloudiness = dataMap.value("clouds").toMap().value("all").toInt();
|
int cloudiness = dataMap.value("clouds").toMap().value("all").toInt();
|
||||||
|
|||||||
@ -48,10 +48,8 @@ QList<DeviceClass> DevicePluginWifiDetector::supportedDevices() const
|
|||||||
DeviceClass deviceClassWifiDetector(pluginId(), guhVendorId, detectorId);
|
DeviceClass deviceClassWifiDetector(pluginId(), guhVendorId, detectorId);
|
||||||
deviceClassWifiDetector.setName("WiFi Device");
|
deviceClassWifiDetector.setName("WiFi Device");
|
||||||
|
|
||||||
QVariantList detectorParams;
|
QList<ParamType> detectorParams;
|
||||||
QVariantMap macParam;
|
ParamType macParam("mac", QVariant::String);
|
||||||
macParam.insert("name", "mac");
|
|
||||||
macParam.insert("type", "string");
|
|
||||||
detectorParams.append(macParam);
|
detectorParams.append(macParam);
|
||||||
|
|
||||||
deviceClassWifiDetector.setParams(detectorParams);
|
deviceClassWifiDetector.setParams(detectorParams);
|
||||||
@ -123,7 +121,7 @@ void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatu
|
|||||||
|
|
||||||
foreach (Device *device, watchedDevices) {
|
foreach (Device *device, watchedDevices) {
|
||||||
bool wasInRange = device->stateValue(inRangeStateTypeId).toBool();
|
bool wasInRange = device->stateValue(inRangeStateTypeId).toBool();
|
||||||
bool wasFound = foundDevices.contains(device->params().value("mac").toString().toLower());
|
bool wasFound = foundDevices.contains(device->paramValue("mac").toString().toLower());
|
||||||
if (wasInRange != wasFound) {
|
if (wasInRange != wasFound) {
|
||||||
device->setStateValue(inRangeStateTypeId, wasFound);
|
device->setStateValue(inRangeStateTypeId, wasFound);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,7 +48,7 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap ¶ms)
|
|||||||
|
|
||||||
DeviceId deviceId(params.value("deviceId").toString());
|
DeviceId deviceId(params.value("deviceId").toString());
|
||||||
ActionTypeId actionTypeId(params.value("actionTypeId").toString());
|
ActionTypeId actionTypeId(params.value("actionTypeId").toString());
|
||||||
QVariantMap actionParams = params.value("params").toMap();
|
QList<Param> actionParams = JsonTypes::unpackParams(params.value("params").toList());
|
||||||
|
|
||||||
Action action(deviceId, actionTypeId);
|
Action action(deviceId, actionTypeId);
|
||||||
action.setParams(actionParams);
|
action.setParams(actionParams);
|
||||||
|
|||||||
@ -250,7 +250,12 @@ JsonReply* DeviceHandler::SetPluginConfiguration(const QVariantMap ¶ms)
|
|||||||
JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
DeviceClassId deviceClass(params.value("deviceClassId").toString());
|
DeviceClassId deviceClass(params.value("deviceClassId").toString());
|
||||||
QVariantMap deviceParams = params.value("deviceParams").toMap();
|
QList<Param> deviceParams;
|
||||||
|
foreach (const QString ¶mName, params.value("deviceParams").toMap().keys()) {
|
||||||
|
Param param(paramName);
|
||||||
|
param.setValue(params.value("deviceParams").toMap().value(paramName));
|
||||||
|
deviceParams.append(param);
|
||||||
|
}
|
||||||
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
|
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
|
||||||
DeviceId newDeviceId = DeviceId::createDeviceId();
|
DeviceId newDeviceId = DeviceId::createDeviceId();
|
||||||
DeviceManager::DeviceError status;
|
DeviceManager::DeviceError status;
|
||||||
|
|||||||
@ -31,6 +31,7 @@ QVariantList JsonTypes::s_basicTypes;
|
|||||||
QVariantList JsonTypes::s_ruleTypes;
|
QVariantList JsonTypes::s_ruleTypes;
|
||||||
QVariantList JsonTypes::s_createMethodTypes;
|
QVariantList JsonTypes::s_createMethodTypes;
|
||||||
QVariantList JsonTypes::s_setupMethodTypes;
|
QVariantList JsonTypes::s_setupMethodTypes;
|
||||||
|
QVariantList JsonTypes::s_operandTypes;
|
||||||
|
|
||||||
QVariantMap JsonTypes::s_paramType;
|
QVariantMap JsonTypes::s_paramType;
|
||||||
QVariantMap JsonTypes::s_param;
|
QVariantMap JsonTypes::s_param;
|
||||||
@ -54,16 +55,19 @@ void JsonTypes::init()
|
|||||||
s_ruleTypes << "RuleTypeMatchAll" << "RuleTypeMatchAny";
|
s_ruleTypes << "RuleTypeMatchAll" << "RuleTypeMatchAny";
|
||||||
s_createMethodTypes << "CreateMethodUser" << "CreateMethodAuto" << "CreateMethodDiscovery";
|
s_createMethodTypes << "CreateMethodUser" << "CreateMethodAuto" << "CreateMethodDiscovery";
|
||||||
s_setupMethodTypes << "SetupMethodJustAdd" << "SetupMethodDisplayPin" << "SetupMethodEnterPin" << "SetupMethodPushButton";
|
s_setupMethodTypes << "SetupMethodJustAdd" << "SetupMethodDisplayPin" << "SetupMethodEnterPin" << "SetupMethodPushButton";
|
||||||
|
s_operandTypes << "OperandTypeEquals" << "OperandTypeNotEquals" << "OperandTypeLess" << "OperandTypeGreater" << "OperandTypeLessThan" << "OperandTypeGreaterThan";
|
||||||
|
|
||||||
// ParamType
|
// ParamType
|
||||||
s_paramType.insert("name", "string");
|
s_paramType.insert("name", "string");
|
||||||
s_paramType.insert("type", basicTypesRef());
|
s_paramType.insert("type", basicTypesRef());
|
||||||
// s_paramType.insert("default", "value");
|
s_paramType.insert("o:defaultValue", "value");
|
||||||
// s_paramType.insert("value", "value");
|
s_paramType.insert("o:minValue", "value");
|
||||||
|
s_paramType.insert("o:maxValue", "value");
|
||||||
|
|
||||||
// Param
|
// Param
|
||||||
s_param.insert("name", "string");
|
s_param.insert("name", "string");
|
||||||
s_param.insert("value", basicTypesRef());
|
s_param.insert("value", basicTypesRef());
|
||||||
|
s_param.insert("operand", operandTypesRef());
|
||||||
|
|
||||||
// StateType
|
// StateType
|
||||||
s_stateType.insert("id", "uuid");
|
s_stateType.insert("id", "uuid");
|
||||||
@ -147,6 +151,7 @@ QVariantMap JsonTypes::allTypes()
|
|||||||
allTypes.insert("ParamType", paramTypeDescription());
|
allTypes.insert("ParamType", paramTypeDescription());
|
||||||
allTypes.insert("CreateMethodType", createMethodTypes());
|
allTypes.insert("CreateMethodType", createMethodTypes());
|
||||||
allTypes.insert("SetupMethodType", setupMethodTypes());
|
allTypes.insert("SetupMethodType", setupMethodTypes());
|
||||||
|
allTypes.insert("OperandType", operandTypes());
|
||||||
allTypes.insert("StateType", stateTypeDescription());
|
allTypes.insert("StateType", stateTypeDescription());
|
||||||
allTypes.insert("EventType", eventTypeDescription());
|
allTypes.insert("EventType", eventTypeDescription());
|
||||||
allTypes.insert("ActionType", actionTypeDescription());
|
allTypes.insert("ActionType", actionTypeDescription());
|
||||||
@ -178,7 +183,11 @@ QVariantMap JsonTypes::packEvent(const Event &event)
|
|||||||
QVariantMap variant;
|
QVariantMap variant;
|
||||||
variant.insert("eventTypeId", event.eventTypeId());
|
variant.insert("eventTypeId", event.eventTypeId());
|
||||||
variant.insert("deviceId", event.deviceId());
|
variant.insert("deviceId", event.deviceId());
|
||||||
variant.insert("params", event.params());
|
QVariantList params;
|
||||||
|
foreach (const Param ¶m, event.params()) {
|
||||||
|
params.append(packParam(param));
|
||||||
|
}
|
||||||
|
variant.insert("params", params);
|
||||||
return variant;
|
return variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +205,11 @@ QVariantMap JsonTypes::packAction(const Action &action)
|
|||||||
QVariantMap variant;
|
QVariantMap variant;
|
||||||
variant.insert("actionTypeId", action.actionTypeId());
|
variant.insert("actionTypeId", action.actionTypeId());
|
||||||
variant.insert("deviceId", action.deviceId());
|
variant.insert("deviceId", action.deviceId());
|
||||||
variant.insert("params", action.params());
|
QVariantList params;
|
||||||
|
foreach (const Param ¶m, action.params()) {
|
||||||
|
params.append(packParam(param));
|
||||||
|
}
|
||||||
|
variant.insert("params", params);
|
||||||
return variant;
|
return variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +223,32 @@ QVariantMap JsonTypes::packStateType(const StateType &stateType)
|
|||||||
return variantMap;
|
return variantMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariantMap JsonTypes::packParam(const Param ¶m)
|
||||||
|
{
|
||||||
|
QVariantMap variantMap;
|
||||||
|
variantMap.insert("name", param.name());
|
||||||
|
variantMap.insert("value", param.value());
|
||||||
|
variantMap.insert("operand", s_operandTypes.at(param.operand()));
|
||||||
|
return variantMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap JsonTypes::packParamType(const ParamType ¶mType)
|
||||||
|
{
|
||||||
|
QVariantMap variantMap;
|
||||||
|
variantMap.insert("name", paramType.name());
|
||||||
|
variantMap.insert("type", QVariant::typeToName(paramType.type()));
|
||||||
|
if (paramType.defaultValue().isValid()) {
|
||||||
|
variantMap.insert("defaultValue", paramType.defaultValue());
|
||||||
|
}
|
||||||
|
if (paramType.minValue().isValid()) {
|
||||||
|
variantMap.insert("minValue", paramType.minValue());
|
||||||
|
}
|
||||||
|
if (paramType.maxValue().isValid()) {
|
||||||
|
variantMap.insert("maxValue", paramType.maxValue());
|
||||||
|
}
|
||||||
|
return variantMap;
|
||||||
|
}
|
||||||
|
|
||||||
QVariantMap JsonTypes::packVendor(const Vendor &vendor)
|
QVariantMap JsonTypes::packVendor(const Vendor &vendor)
|
||||||
{
|
{
|
||||||
QVariantMap variantMap;
|
QVariantMap variantMap;
|
||||||
@ -235,7 +274,12 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass)
|
|||||||
foreach (const ActionType &actionType, deviceClass.actions()) {
|
foreach (const ActionType &actionType, deviceClass.actions()) {
|
||||||
actionTypes.append(packActionType(actionType));
|
actionTypes.append(packActionType(actionType));
|
||||||
}
|
}
|
||||||
variant.insert("params", deviceClass.params());
|
QVariantList paramTypes;
|
||||||
|
foreach (const ParamType ¶mType, deviceClass.params()) {
|
||||||
|
paramTypes.append(packParamType(paramType));
|
||||||
|
}
|
||||||
|
|
||||||
|
variant.insert("params", paramTypes);
|
||||||
variant.insert("states", stateTypes);
|
variant.insert("states", stateTypes);
|
||||||
variant.insert("events", eventTypes);
|
variant.insert("events", eventTypes);
|
||||||
variant.insert("actions", actionTypes);
|
variant.insert("actions", actionTypes);
|
||||||
@ -257,7 +301,11 @@ QVariantMap JsonTypes::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());
|
||||||
variant.insert("params", device->params());
|
QVariantList params;
|
||||||
|
foreach (const Param ¶m, device->params()) {
|
||||||
|
params.append(packParam(param));
|
||||||
|
}
|
||||||
|
variant.insert("params", params);
|
||||||
return variant;
|
return variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,6 +341,35 @@ QVariantMap JsonTypes::packRule(const Rule &rule)
|
|||||||
return ruleMap;
|
return ruleMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Param JsonTypes::unpackParam(const QVariantMap ¶mMap)
|
||||||
|
{
|
||||||
|
Param param(paramMap.value("name").toString(), paramMap.value("value"));
|
||||||
|
QString operandString = paramMap.value("operand").toString();
|
||||||
|
if (operandString == "OperandTypeEquals") {
|
||||||
|
param.setOperand(Param::OperandTypeEquals);
|
||||||
|
} else if (operandString == "OperandTypeNotEquals") {
|
||||||
|
param.setOperand(Param::OperandTypeNotEquals);
|
||||||
|
} else if (operandString == "OperandTypeLess") {
|
||||||
|
param.setOperand(Param::OperandTypeLess);
|
||||||
|
} else if (operandString == "OperandTypeGreater") {
|
||||||
|
param.setOperand(Param::OperandTypeGreater);
|
||||||
|
} else if (operandString == "OperandTypeLessThan") {
|
||||||
|
param.setOperand(Param::OperandTypeLessThan);
|
||||||
|
} else if (operandString == "OperandTypeGreaterThan") {
|
||||||
|
param.setOperand(Param::OperandTypeGreaterThan);
|
||||||
|
}
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Param> JsonTypes::unpackParams(const QVariantList ¶mList)
|
||||||
|
{
|
||||||
|
QList<Param> params;
|
||||||
|
foreach (const QVariant ¶mVariant, paramList) {
|
||||||
|
params.append(unpackParam(paramVariant.toMap()));
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, const QVariantMap &map)
|
QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, const QVariantMap &map)
|
||||||
{
|
{
|
||||||
s_lastError.clear();
|
s_lastError.clear();
|
||||||
@ -333,6 +410,7 @@ QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, cons
|
|||||||
|
|
||||||
QPair<bool, QString> JsonTypes::validateProperty(const QVariant &templateValue, const QVariant &value)
|
QPair<bool, QString> JsonTypes::validateProperty(const QVariant &templateValue, const QVariant &value)
|
||||||
{
|
{
|
||||||
|
qDebug() << "validating property. template:" << templateValue << "got:" << value;
|
||||||
QString strippedTemplateValue = templateValue.toString();
|
QString strippedTemplateValue = templateValue.toString();
|
||||||
|
|
||||||
if (strippedTemplateValue == "variant") {
|
if (strippedTemplateValue == "variant") {
|
||||||
@ -378,20 +456,26 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
|
|||||||
case QVariant::String:
|
case QVariant::String:
|
||||||
if (templateVariant.toString().startsWith("$ref:")) {
|
if (templateVariant.toString().startsWith("$ref:")) {
|
||||||
QString refName = templateVariant.toString();
|
QString refName = templateVariant.toString();
|
||||||
if (refName == JsonTypes::actionRef()) {
|
if (refName == actionRef()) {
|
||||||
qDebug() << "validating action";
|
qDebug() << "validating action";
|
||||||
QPair<bool, QString> result = validateMap(actionDescription(), variant.toMap());
|
QPair<bool, QString> result = validateMap(actionDescription(), variant.toMap());
|
||||||
if (!result.first) {
|
if (!result.first) {
|
||||||
qDebug() << "Error validating action";
|
qDebug() << "Error validating action";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} else if (refName == JsonTypes::eventRef()) {
|
} else if (refName == eventRef()) {
|
||||||
qDebug() << "validating event";
|
qDebug() << "validating event";
|
||||||
QPair<bool, QString> result = validateMap(eventDescription(), variant.toMap());
|
QPair<bool, QString> result = validateMap(eventDescription(), variant.toMap());
|
||||||
if (!result.first) {
|
if (!result.first) {
|
||||||
qDebug() << "event not valid";
|
qDebug() << "event not valid";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
} else if (refName == paramRef()) {
|
||||||
|
QPair<bool, QString> result = validateMap(paramDescription(), variant.toMap());
|
||||||
|
if (!result.first) {
|
||||||
|
qDebug() << "Param not valid";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} else if (refName == deviceRef()) {
|
} else if (refName == deviceRef()) {
|
||||||
QPair<bool, QString> result = validateMap(deviceDescription(), variant.toMap());
|
QPair<bool, QString> result = validateMap(deviceDescription(), variant.toMap());
|
||||||
if (!result.first) {
|
if (!result.first) {
|
||||||
@ -475,6 +559,12 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
|
|||||||
qDebug() << "value not allowed in" << createMethodTypesRef();
|
qDebug() << "value not allowed in" << createMethodTypesRef();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
} else if (refName == operandTypesRef()) {
|
||||||
|
QPair<bool, QString> result = validateOperandType(variant);
|
||||||
|
if (!result.first) {
|
||||||
|
qDebug() << QString("value %1 not allowed in %2").arg(variant.toString()).arg(operandTypesRef());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "unhandled ref:" << refName;
|
qDebug() << "unhandled ref:" << refName;
|
||||||
return report(false, QString("Unhandled ref %1. Server implementation incomplete.").arg(refName));
|
return report(false, QString("Unhandled ref %1. Server implementation incomplete.").arg(refName));
|
||||||
@ -543,3 +633,8 @@ QPair<bool, QString> JsonTypes::validateSetupMethodType(const QVariant &variant)
|
|||||||
{
|
{
|
||||||
return report(s_setupMethodTypes.contains(variant.toString()), QString("Unknwon setupMethod type %1").arg(variant.toString()));
|
return report(s_setupMethodTypes.contains(variant.toString()), QString("Unknwon setupMethod type %1").arg(variant.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPair<bool, QString> JsonTypes::validateOperandType(const QVariant &variant)
|
||||||
|
{
|
||||||
|
return report(s_operandTypes.contains(variant.toString()), QString("Unknown operand type %1").arg(variant.toString()));
|
||||||
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "types/event.h"
|
#include "types/event.h"
|
||||||
#include "types/action.h"
|
#include "types/action.h"
|
||||||
#include "types/actiontype.h"
|
#include "types/actiontype.h"
|
||||||
|
#include "types/paramtype.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ public:
|
|||||||
DECLARE_TYPE(ruleTypes, "RuleType")
|
DECLARE_TYPE(ruleTypes, "RuleType")
|
||||||
DECLARE_TYPE(createMethodTypes, "CreateMethodType")
|
DECLARE_TYPE(createMethodTypes, "CreateMethodType")
|
||||||
DECLARE_TYPE(setupMethodTypes, "SetupMethodType")
|
DECLARE_TYPE(setupMethodTypes, "SetupMethodType")
|
||||||
|
DECLARE_TYPE(operandTypes, "OperandType")
|
||||||
DECLARE_OBJECT(paramType, "ParamType")
|
DECLARE_OBJECT(paramType, "ParamType")
|
||||||
DECLARE_OBJECT(param, "Param")
|
DECLARE_OBJECT(param, "Param")
|
||||||
DECLARE_OBJECT(stateType, "StateType")
|
DECLARE_OBJECT(stateType, "StateType")
|
||||||
@ -86,6 +88,8 @@ public:
|
|||||||
static QVariantMap packActionType(const ActionType &actionType);
|
static QVariantMap packActionType(const ActionType &actionType);
|
||||||
static QVariantMap packAction(const Action &action);
|
static QVariantMap packAction(const Action &action);
|
||||||
static QVariantMap packStateType(const StateType &stateType);
|
static QVariantMap packStateType(const StateType &stateType);
|
||||||
|
static QVariantMap packParam(const Param ¶m);
|
||||||
|
static QVariantMap packParamType(const ParamType ¶mType);
|
||||||
static QVariantMap packVendor(const Vendor &vendor);
|
static QVariantMap packVendor(const Vendor &vendor);
|
||||||
static QVariantMap packDeviceClass(const DeviceClass &deviceClass);
|
static QVariantMap packDeviceClass(const DeviceClass &deviceClass);
|
||||||
static QVariantMap packPlugin(DevicePlugin *plugin);
|
static QVariantMap packPlugin(DevicePlugin *plugin);
|
||||||
@ -93,6 +97,9 @@ public:
|
|||||||
static QVariantMap packDeviceDescriptor(const DeviceDescriptor &descriptor);
|
static QVariantMap packDeviceDescriptor(const DeviceDescriptor &descriptor);
|
||||||
static QVariantMap packRule(const Rule &rule);
|
static QVariantMap packRule(const Rule &rule);
|
||||||
|
|
||||||
|
static Param unpackParam(const QVariantMap ¶mMap);
|
||||||
|
static QList<Param> unpackParams(const QVariantList ¶mList);
|
||||||
|
|
||||||
static QPair<bool, QString> validateMap(const QVariantMap &templateMap, const QVariantMap &map);
|
static QPair<bool, QString> validateMap(const QVariantMap &templateMap, const QVariantMap &map);
|
||||||
static QPair<bool, QString> validateProperty(const QVariant &templateValue, const QVariant &value);
|
static QPair<bool, QString> validateProperty(const QVariant &templateValue, const QVariant &value);
|
||||||
static QPair<bool, QString> validateList(const QVariantList &templateList, const QVariantList &list);
|
static QPair<bool, QString> validateList(const QVariantList &templateList, const QVariantList &list);
|
||||||
@ -101,6 +108,7 @@ public:
|
|||||||
static QPair<bool, QString> validateRuleType(const QVariant &variant);
|
static QPair<bool, QString> validateRuleType(const QVariant &variant);
|
||||||
static QPair<bool, QString> validateCreateMethodType(const QVariant &variant);
|
static QPair<bool, QString> validateCreateMethodType(const QVariant &variant);
|
||||||
static QPair<bool, QString> validateSetupMethodType(const QVariant &variant);
|
static QPair<bool, QString> validateSetupMethodType(const QVariant &variant);
|
||||||
|
static QPair<bool, QString> validateOperandType(const QVariant &variant);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool s_initialized;
|
static bool s_initialized;
|
||||||
|
|||||||
@ -82,7 +82,7 @@ JsonReply* RulesHandler::AddRule(const QVariantMap ¶ms)
|
|||||||
|
|
||||||
EventTypeId eventTypeId(eventMap.value("eventTypeId").toString());
|
EventTypeId eventTypeId(eventMap.value("eventTypeId").toString());
|
||||||
DeviceId eventDeviceId(eventMap.value("deviceId").toString());
|
DeviceId eventDeviceId(eventMap.value("deviceId").toString());
|
||||||
QVariantMap eventParams = eventMap.value("params").toMap();
|
QList<Param> eventParams = JsonTypes::unpackParams(eventMap.value("params").toList());
|
||||||
Event event(eventTypeId, eventDeviceId, eventParams);
|
Event event(eventTypeId, eventDeviceId, eventParams);
|
||||||
|
|
||||||
QList<Action> actions;
|
QList<Action> actions;
|
||||||
@ -91,7 +91,7 @@ JsonReply* RulesHandler::AddRule(const QVariantMap ¶ms)
|
|||||||
foreach (const QVariant &actionVariant, actionList) {
|
foreach (const QVariant &actionVariant, actionList) {
|
||||||
QVariantMap actionMap = actionVariant.toMap();
|
QVariantMap actionMap = actionVariant.toMap();
|
||||||
Action action(DeviceId(actionMap.value("deviceId").toString()), ActionTypeId(actionMap.value("actionTypeId").toString()));
|
Action action(DeviceId(actionMap.value("deviceId").toString()), ActionTypeId(actionMap.value("actionTypeId").toString()));
|
||||||
action.setParams(actionMap.value("params").toMap());
|
action.setParams(JsonTypes::unpackParams(actionMap.value("params").toList()));
|
||||||
actions.append(action);
|
actions.append(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -80,7 +80,17 @@ RuleEngine::RuleEngine(QObject *parent) :
|
|||||||
settings.beginGroup("event");
|
settings.beginGroup("event");
|
||||||
EventTypeId eventTypeId(settings.value("eventTypeId").toString());
|
EventTypeId eventTypeId(settings.value("eventTypeId").toString());
|
||||||
DeviceId deviceId(settings.value("deviceId").toString());
|
DeviceId deviceId(settings.value("deviceId").toString());
|
||||||
Event event(eventTypeId, deviceId, settings.value("params").toMap());
|
QList<Param> params;
|
||||||
|
foreach (QString groupName, settings.childGroups()) {
|
||||||
|
if (groupName.startsWith("Param-")) {
|
||||||
|
settings.beginGroup(groupName);
|
||||||
|
Param param(groupName.remove(QRegExp("^Param-")), settings.value("value"));
|
||||||
|
param.setOperand((Param::OperandType)settings.value("operand").toInt());
|
||||||
|
params.append(param);
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Event event(eventTypeId, deviceId, params);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup("states");
|
settings.beginGroup("states");
|
||||||
@ -99,7 +109,18 @@ RuleEngine::RuleEngine(QObject *parent) :
|
|||||||
foreach (const QString &actionIdString, settings.childGroups()) {
|
foreach (const QString &actionIdString, settings.childGroups()) {
|
||||||
settings.beginGroup(actionIdString);
|
settings.beginGroup(actionIdString);
|
||||||
Action action = Action(DeviceId(settings.value("deviceId").toString()), ActionTypeId(settings.value("actionTypeId").toString()));
|
Action action = Action(DeviceId(settings.value("deviceId").toString()), ActionTypeId(settings.value("actionTypeId").toString()));
|
||||||
action.setParams(settings.value("params").toMap());
|
QList<Param> params;
|
||||||
|
foreach (QString paramNameString, settings.childGroups()) {
|
||||||
|
if (paramNameString.startsWith("Param-")) {
|
||||||
|
settings.beginGroup(paramNameString);
|
||||||
|
Param param(paramNameString.remove(QRegExp("^Param-")), settings.value("value"));
|
||||||
|
param.setOperand((Param::OperandType)settings.value("operand").toInt());
|
||||||
|
params.append(param);
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
action.setParams(params);
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
actions.append(action);
|
actions.append(action);
|
||||||
}
|
}
|
||||||
@ -187,7 +208,13 @@ RuleEngine::RuleError RuleEngine::addRule(const Event &event, const QList<State>
|
|||||||
settings.beginGroup("event");
|
settings.beginGroup("event");
|
||||||
settings.setValue("eventTypeId", event.eventTypeId());
|
settings.setValue("eventTypeId", event.eventTypeId());
|
||||||
settings.setValue("deviceId", event.deviceId());
|
settings.setValue("deviceId", event.deviceId());
|
||||||
settings.setValue("params", event.params());
|
foreach (const Param ¶m, event.params()) {
|
||||||
|
settings.beginGroup("Param-" + param.name());
|
||||||
|
settings.setValue("value", param.value());
|
||||||
|
settings.setValue("operand", param.operand());
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup("states");
|
settings.beginGroup("states");
|
||||||
@ -205,7 +232,12 @@ RuleEngine::RuleError RuleEngine::addRule(const Event &event, const QList<State>
|
|||||||
settings.beginGroup(action.actionTypeId().toString());
|
settings.beginGroup(action.actionTypeId().toString());
|
||||||
settings.setValue("deviceId", action.deviceId());
|
settings.setValue("deviceId", action.deviceId());
|
||||||
settings.setValue("actionTypeId", action.actionTypeId());
|
settings.setValue("actionTypeId", action.actionTypeId());
|
||||||
settings.setValue("params", action.params());
|
foreach (const Param ¶m, action.params()) {
|
||||||
|
settings.beginGroup("Param-" + param.name());
|
||||||
|
settings.setValue("value", param.value());
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -315,6 +315,7 @@ void TestJSONRPC::getConfiguredDevices()
|
|||||||
QVariant response = injectAndWait("Devices.GetConfiguredDevices");
|
QVariant response = injectAndWait("Devices.GetConfiguredDevices");
|
||||||
|
|
||||||
QVariantList devices = response.toMap().value("params").toMap().value("devices").toList();
|
QVariantList devices = response.toMap().value("params").toMap().value("devices").toList();
|
||||||
|
qDebug() << "got devices" << devices;
|
||||||
QCOMPARE(devices.count(), 2); // There should be one auto created mock device and the one created in initTestcase()
|
QCOMPARE(devices.count(), 2); // There should be one auto created mock device and the one created in initTestcase()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user