first attempt to clean up type system
This commit is contained in:
parent
6450807ece
commit
1aba1643f8
@ -180,26 +180,25 @@ QList<DeviceClass> DeviceManager::supportedDevices(const VendorId &vendorId) con
|
||||
return ret;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
DeviceManager::DeviceError DeviceManager::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
qDebug() << "DeviceManager discoverdevices" << params;
|
||||
// Create a copy of the parameter list because we might modify it (fillig in default values etc)
|
||||
ParamList effectiveParams = params;
|
||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||
if (!deviceClass.isValid()) {
|
||||
return qMakePair<DeviceError, QString>(DeviceManager::DeviceErrorDeviceClassNotFound, deviceClass.id().toString());
|
||||
return DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
if (!deviceClass.createMethods().testFlag(DeviceClass::CreateMethodDiscovery)) {
|
||||
return qMakePair<DeviceError, QString>(DeviceManager::DeviceErrorCreationMethodNotSupported, "");
|
||||
return DeviceErrorCreationMethodNotSupported;
|
||||
}
|
||||
QPair<DeviceError, QString> result = verifyParams(deviceClass.discoveryParamTypes(), effectiveParams);
|
||||
if (result.first != DeviceErrorNoError) {
|
||||
qDebug() << "got erorr" << result.first << result.second;
|
||||
DeviceError result = verifyParams(deviceClass.discoveryParamTypes(), effectiveParams);
|
||||
if (result != DeviceErrorNoError) {
|
||||
return result;
|
||||
}
|
||||
DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
|
||||
if (!plugin) {
|
||||
return qMakePair<DeviceError, QString>(DeviceManager::DeviceErrorPluginNotFound, deviceClass.pluginId().toString());
|
||||
return DeviceErrorPluginNotFound;
|
||||
}
|
||||
m_discoveringPlugins.append(plugin);
|
||||
QPair<DeviceError, QString> ret = plugin->discoverDevices(deviceClassId, effectiveParams);
|
||||
@ -228,32 +227,31 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::discoverDevices(const
|
||||
went wrong during setup. Reasons may be a hardware/network failure, wrong username/password or similar, depending on what the device plugin
|
||||
needs to do in order to set up the device.
|
||||
*/
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId id)
|
||||
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId id)
|
||||
{
|
||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||
if (!deviceClass.isValid()) {
|
||||
qWarning() << "cannot find a device class with id" << deviceClassId;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDeviceClassNotFound, deviceClassId.toString());
|
||||
return DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
if (deviceClass.createMethods().testFlag(DeviceClass::CreateMethodUser)) {
|
||||
return addConfiguredDeviceInternal(deviceClassId, params, id);
|
||||
}
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorCreationMethodNotSupported, "CreateMethodUser");
|
||||
return DeviceErrorCreationMethodNotSupported;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &deviceId)
|
||||
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &deviceId)
|
||||
{
|
||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||
if (!deviceClass.isValid()) {
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDeviceClassNotFound, deviceClassId.toString());
|
||||
return DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
if (!deviceClass.createMethods().testFlag(DeviceClass::CreateMethodDiscovery)) {
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorCreationMethodNotSupported, "CreateMethodDiscovery");
|
||||
return DeviceErrorCreationMethodNotSupported;
|
||||
}
|
||||
|
||||
DeviceDescriptor descriptor = m_discoveredDevices.take(deviceDescriptorId);
|
||||
if (!descriptor.isValid()) {
|
||||
return qMakePair<DeviceError>(DeviceErrorDeviceDescriptorNotFound, deviceDescriptorId.toString());
|
||||
return DeviceErrorDeviceDescriptorNotFound;
|
||||
}
|
||||
|
||||
return addConfiguredDeviceInternal(deviceClassId, descriptor.params(), deviceId);
|
||||
@ -351,35 +349,32 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::confirmPairing(const Q
|
||||
return report(DeviceErrorPairingTransactionIdNotFound, pairingTransactionId.toString());
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId id)
|
||||
DeviceManager::DeviceError DeviceManager::addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId id)
|
||||
{
|
||||
ParamList effectiveParams = params;
|
||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||
if (deviceClass.id().isNull()) {
|
||||
qWarning() << "cannot find a device class with id" << deviceClassId;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDeviceClassNotFound, deviceClassId.toString());
|
||||
return DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
|
||||
if (deviceClass.setupMethod() != DeviceClass::SetupMethodJustAdd) {
|
||||
qWarning() << "Cannot setup this device this way. You need to pair this device.";
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorCreationMethodNotSupported, "You need to pair this device.");
|
||||
return DeviceErrorCreationMethodNotSupported;
|
||||
}
|
||||
|
||||
QPair<DeviceError, QString> result = verifyParams(deviceClass.paramTypes(), effectiveParams);
|
||||
if (result.first != DeviceErrorNoError) {
|
||||
DeviceError result = verifyParams(deviceClass.paramTypes(), effectiveParams);
|
||||
if (result != DeviceErrorNoError) {
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach(Device *device, m_configuredDevices) {
|
||||
if (device->id() == id) {
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDuplicateUuid, id.toString());
|
||||
return DeviceErrorDuplicateUuid;
|
||||
}
|
||||
}
|
||||
|
||||
DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
|
||||
if (!plugin) {
|
||||
qWarning() << "Cannot find a plugin for this device class!";
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorPluginNotFound, deviceClass.pluginId().toString());
|
||||
return DeviceErrorPluginNotFound;
|
||||
}
|
||||
|
||||
Device *device = new Device(plugin->pluginId(), id, deviceClassId, this);
|
||||
@ -391,9 +386,9 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDeviceInt
|
||||
case DeviceSetupStatusFailure:
|
||||
qWarning() << "Device setup failed. Not adding device to system.";
|
||||
delete device;
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorSetupFailed, QString("Device setup failed: %1").arg(status.second));
|
||||
return DeviceErrorSetupFailed;
|
||||
case DeviceSetupStatusAsync:
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorAsync, "");
|
||||
return DeviceErrorAsync;
|
||||
case DeviceSetupStatusSuccess:
|
||||
qDebug() << "Device setup complete.";
|
||||
break;
|
||||
@ -402,7 +397,7 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDeviceInt
|
||||
m_configuredDevices.append(device);
|
||||
storeConfiguredDevices();
|
||||
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorNoError, QString());
|
||||
return DeviceErrorNoError;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::removeConfiguredDevice(const DeviceId &deviceId)
|
||||
@ -475,7 +470,7 @@ DeviceClass DeviceManager::findDeviceClass(const DeviceClassId &deviceClassId) c
|
||||
/*! Execute the given \{Action}.
|
||||
This will find the \l{Device} \a action refers to in \l{Action::deviceId()} and
|
||||
its \l{DevicePlugin}. Then will dispatch the execution to the \l{DevicePlugin}.*/
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::executeAction(const Action &action)
|
||||
DeviceManager::DeviceError DeviceManager::executeAction(const Action &action)
|
||||
{
|
||||
Action finalAction = action;
|
||||
qDebug() << "should execute action";
|
||||
@ -490,8 +485,8 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::executeAction(const Ac
|
||||
qDebug() << "checking" << actionType.id() << action.actionTypeId();
|
||||
if (actionType.id() == action.actionTypeId()) {
|
||||
ParamList finalParams = action.params();
|
||||
QPair<DeviceError, QString> paramCheck = verifyParams(actionType.paramTypes(), finalParams);
|
||||
if (paramCheck.first != DeviceErrorNoError) {
|
||||
DeviceError paramCheck = verifyParams(actionType.paramTypes(), finalParams);
|
||||
if (paramCheck != DeviceErrorNoError) {
|
||||
return paramCheck;
|
||||
}
|
||||
finalAction.setParams(finalParams);
|
||||
@ -501,13 +496,13 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::executeAction(const Ac
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorActionTypeNotFound, action.actionTypeId().toString());
|
||||
return DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
|
||||
return m_devicePlugins.value(device->pluginId())->executeAction(device, finalAction);
|
||||
}
|
||||
}
|
||||
return qMakePair<DeviceError, QString>(DeviceErrorDeviceNotFound, action.deviceId().toString());
|
||||
return DeviceErrorDeviceNotFound;
|
||||
}
|
||||
|
||||
void DeviceManager::loadPlugins()
|
||||
@ -926,17 +921,16 @@ QPair<DeviceManager::DeviceSetupStatus,QString> DeviceManager::setupDevice(Devic
|
||||
return status;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::verifyParams(const QList<ParamType> paramTypes, ParamList ¶ms, bool requireAll)
|
||||
DeviceManager::DeviceError DeviceManager::verifyParams(const QList<ParamType> paramTypes, ParamList ¶ms, bool requireAll)
|
||||
{
|
||||
foreach (const Param ¶m, params) {
|
||||
qDebug() << "verifying param" << param.name() << paramTypes;
|
||||
QPair<DeviceManager::DeviceError, QString> result = verifyParam(paramTypes, param);
|
||||
if (result.first != DeviceErrorNoError) {
|
||||
DeviceManager::DeviceError result = verifyParam(paramTypes, param);
|
||||
if (result != DeviceErrorNoError) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (!requireAll) {
|
||||
return report();
|
||||
return DeviceErrorNoError;
|
||||
}
|
||||
foreach (const ParamType ¶mType, paramTypes) {
|
||||
bool found = false;
|
||||
@ -953,37 +947,39 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::verifyParams(const QLi
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return report(DeviceErrorMissingParameter, QString("Missing parameter: %1").arg(paramType.name()));
|
||||
qWarning() << "Missing parameter:" << paramType.name();
|
||||
return DeviceErrorMissingParameter;
|
||||
}
|
||||
}
|
||||
return report();
|
||||
return DeviceErrorNoError;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::verifyParam(const QList<ParamType> paramTypes, const Param ¶m)
|
||||
DeviceManager::DeviceError DeviceManager::verifyParam(const QList<ParamType> paramTypes, const Param ¶m)
|
||||
{
|
||||
foreach (const ParamType ¶mType, paramTypes) {
|
||||
if (paramType.name() == param.name()) {
|
||||
return verifyParam(paramType, param);
|
||||
}
|
||||
}
|
||||
return report(DeviceErrorInvalidParameter, QString("Parameter %1 not in ParamTypes list").arg(param.name()));
|
||||
qWarning() << "Invalid parameter" << param.name() << "in parameter list";
|
||||
return DeviceErrorInvalidParameter;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::verifyParam(const ParamType ¶mType, const Param ¶m)
|
||||
DeviceManager::DeviceError DeviceManager::verifyParam(const ParamType ¶mType, const Param ¶m)
|
||||
{
|
||||
if (paramType.name() == param.name()) {
|
||||
if (!param.value().canConvert(paramType.type())) {
|
||||
return report(DeviceManager::DeviceErrorInvalidParameter, QString("Wrong parameter type for param %1. Got: %2. Expected %3.")
|
||||
.arg(param.name()).arg(param.value().toString()).arg(QVariant::typeToName(paramType.type())));
|
||||
qWarning() << "Wrong parameter type for param" << param.name() << " Got:" << param.value() << " Expected:" << QVariant::typeToName(paramType.type());
|
||||
return DeviceErrorInvalidParameter;
|
||||
}
|
||||
|
||||
if (paramType.maxValue().isValid() && param.value() > paramType.maxValue()) {
|
||||
return report(DeviceManager::DeviceErrorInvalidParameter, QString("Value out of range for param %1. Got: %2. Max: %3.")
|
||||
.arg(param.name()).arg(param.value().toString()).arg(paramType.maxValue().toString()));
|
||||
qWarning() << "Value out of range for param" << param.name() << " Got:" << param.value() << " Max:" << paramType.maxValue();
|
||||
return DeviceErrorInvalidParameter;
|
||||
}
|
||||
if (paramType.minValue().isValid() && param.value() < paramType.minValue()) {
|
||||
return report(DeviceManager::DeviceErrorInvalidParameter, QString("Value out of range for param %1. Got: %2. Min: %3.")
|
||||
.arg(param.name()).arg(param.value().toString()).arg(paramType.minValue().toString()));
|
||||
qWarning() << "Value out of range for param" << param.name() << " Got:" << param.value() << " Min:" << paramType.minValue();
|
||||
return DeviceErrorInvalidParameter;
|
||||
}
|
||||
if (!paramType.allowedValues().isEmpty() && !paramType.allowedValues().contains(param.value())) {
|
||||
QStringList allowedValues;
|
||||
@ -991,13 +987,13 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::verifyParam(const Para
|
||||
allowedValues.append(value.toString());
|
||||
}
|
||||
|
||||
return report(DeviceManager::DeviceErrorInvalidParameter, QString("Value not in allowed values for param %1. Got: %2. Allowed: %3.")
|
||||
.arg(param.name()).arg(param.value().toString()).arg(allowedValues.join(",")));
|
||||
qWarning() << "Value not in allowed values for param" << param.name() << " Got:" << param.value() << " Allowed:" << allowedValues.join(",");
|
||||
return DeviceErrorInvalidParameter;
|
||||
}
|
||||
return report();
|
||||
return DeviceErrorNoError;
|
||||
}
|
||||
return report(DeviceErrorInvalidParameter, QString("Parameter name %1 does not match with ParamType name %2")
|
||||
.arg(param.name()).arg(paramType.name()));
|
||||
qWarning() << "Parameter name" << param.name() << "does not match with ParamType name" << paramType.name();
|
||||
return DeviceErrorInvalidParameter;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DeviceManager::report(DeviceManager::DeviceError error, const QString &message)
|
||||
|
||||
@ -37,6 +37,7 @@ class Radio433;
|
||||
class DeviceManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(DeviceError)
|
||||
public:
|
||||
enum HardwareResource {
|
||||
HardwareResourceNone = 0x00,
|
||||
@ -62,6 +63,7 @@ public:
|
||||
DeviceErrorDeviceDescriptorNotFound,
|
||||
DeviceErrorAsync,
|
||||
DeviceErrorPairingTransactionIdNotFound,
|
||||
// Don't forget to update JsonTypes!
|
||||
};
|
||||
|
||||
enum DeviceSetupStatus {
|
||||
@ -79,11 +81,11 @@ public:
|
||||
|
||||
QList<Vendor> supportedVendors() const;
|
||||
QList<DeviceClass> supportedDevices(const VendorId &vendorId = VendorId()) const;
|
||||
QPair<DeviceError, QString> discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||
DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||
|
||||
QList<Device*> configuredDevices() const;
|
||||
QPair<DeviceError, QString> addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||
QPair<DeviceError, QString> addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &id = DeviceId::createDeviceId());
|
||||
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &id = DeviceId::createDeviceId());
|
||||
QPair<DeviceError, QString> pairDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||
QPair<DeviceError, QString> pairDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId);
|
||||
QPair<DeviceError, QString> confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
|
||||
@ -103,7 +105,7 @@ signals:
|
||||
void actionExecutionFinished(const ActionId, DeviceError status, const QString &errorMessage);
|
||||
|
||||
public slots:
|
||||
QPair<DeviceError, QString> executeAction(const Action &action);
|
||||
DeviceError executeAction(const Action &action);
|
||||
|
||||
private slots:
|
||||
void loadPlugins();
|
||||
@ -123,11 +125,11 @@ private slots:
|
||||
|
||||
private:
|
||||
bool verifyPluginMetadata(const QJsonObject &data);
|
||||
QPair<DeviceError, QString> addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||
DeviceError addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||
QPair<DeviceSetupStatus, QString> setupDevice(Device *device);
|
||||
QPair<DeviceError, QString> verifyParams(const QList<ParamType> paramTypes, ParamList ¶ms, bool requireAll = true);
|
||||
QPair<DeviceError, QString> verifyParam(const QList<ParamType> paramTypes, const Param ¶m);
|
||||
QPair<DeviceError, QString> verifyParam(const ParamType ¶mType, const Param ¶m);
|
||||
DeviceError verifyParams(const QList<ParamType> paramTypes, ParamList ¶ms, bool requireAll = true);
|
||||
DeviceError verifyParam(const QList<ParamType> paramTypes, const Param ¶m);
|
||||
DeviceError verifyParam(const ParamType ¶mType, const Param ¶m);
|
||||
|
||||
QPair<DeviceError, QString> report(DeviceError error = DeviceErrorNoError, const QString &message = QString());
|
||||
|
||||
|
||||
@ -55,5 +55,6 @@ HEADERS += plugin/device.h \
|
||||
types/paramtype.h \
|
||||
types/param.h \
|
||||
types/paramdescriptor.h \
|
||||
types/statedescriptor.h
|
||||
types/statedescriptor.h \
|
||||
typeutils.h
|
||||
|
||||
|
||||
@ -31,6 +31,9 @@
|
||||
|
||||
class DeviceClass
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(CreateMethod)
|
||||
Q_ENUMS(SetupMethod)
|
||||
public:
|
||||
enum CreateMethod {
|
||||
CreateMethodUser = 0x01,
|
||||
|
||||
@ -235,11 +235,11 @@ void DevicePlugin::startMonitoringAutoDevices()
|
||||
be an async operation. Return DeviceErrorAsync or DeviceErrorNoError if the discovery
|
||||
has been started successfully. Return an appropriate error otherwise.
|
||||
Once devices are discovered, emit devicesDiscovered() once. */
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePlugin::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
DeviceManager::DeviceError DevicePlugin::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
Q_UNUSED(deviceClassId)
|
||||
Q_UNUSED(params)
|
||||
return report(DeviceManager::DeviceErrorCreationMethodNotSupported);
|
||||
return DeviceManager::DeviceErrorCreationMethodNotSupported;
|
||||
}
|
||||
|
||||
/*! This will be called when a new device is created. The plugin has the chance to do some setup.
|
||||
|
||||
@ -51,7 +51,7 @@ public:
|
||||
virtual DeviceManager::HardwareResources requiredHardware() const = 0;
|
||||
|
||||
virtual void startMonitoringAutoDevices();
|
||||
virtual QPair<DeviceManager::DeviceError, QString> discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||
virtual DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||
|
||||
virtual QPair<DeviceManager::DeviceSetupStatus, QString> setupDevice(Device *device);
|
||||
virtual void deviceRemoved(Device *device);
|
||||
@ -70,9 +70,9 @@ public:
|
||||
QPair<DeviceManager::DeviceError, QString> setConfigValue(const QString ¶mName, const QVariant &value);
|
||||
|
||||
public slots:
|
||||
virtual QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) {
|
||||
virtual DeviceManager::DeviceError executeAction(Device *device, const Action &action) {
|
||||
Q_UNUSED(device) Q_UNUSED(action)
|
||||
return qMakePair<DeviceManager::DeviceError, QString>(DeviceManager::DeviceErrorNoError, "");
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
signals:
|
||||
|
||||
@ -99,32 +99,32 @@ bool EventDescriptor::operator ==(const Event &event) const
|
||||
|
||||
foreach (const ParamDescriptor ¶mDescriptor, m_paramDescriptors) {
|
||||
switch (paramDescriptor.operatorType()) {
|
||||
case ValueOperatorEquals:
|
||||
case Types::ValueOperatorEquals:
|
||||
if (event.param(paramDescriptor.name()).value() != paramDescriptor.value()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ValueOperatorNotEquals:
|
||||
case Types::ValueOperatorNotEquals:
|
||||
if (event.param(paramDescriptor.name()).value() == paramDescriptor.value()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ValueOperatorGreater:
|
||||
case Types::ValueOperatorGreater:
|
||||
if (event.param(paramDescriptor.name()).value() <= paramDescriptor.value()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ValueOperatorGreaterOrEqual:
|
||||
case Types::ValueOperatorGreaterOrEqual:
|
||||
if (event.param(paramDescriptor.name()).value() < paramDescriptor.value()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ValueOperatorLess:
|
||||
case Types::ValueOperatorLess:
|
||||
if (event.param(paramDescriptor.name()).value() >= paramDescriptor.value()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ValueOperatorLessOrEqual:
|
||||
case Types::ValueOperatorLessOrEqual:
|
||||
if (event.param(paramDescriptor.name()).value() < paramDescriptor.value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -20,16 +20,16 @@
|
||||
|
||||
ParamDescriptor::ParamDescriptor(const QString &name, const QVariant &value):
|
||||
Param(name, value),
|
||||
m_operatorType(ValueOperatorEquals)
|
||||
m_operatorType(Types::ValueOperatorEquals)
|
||||
{
|
||||
}
|
||||
|
||||
ValueOperator ParamDescriptor::operatorType() const
|
||||
Types::ValueOperator ParamDescriptor::operatorType() const
|
||||
{
|
||||
return m_operatorType;
|
||||
}
|
||||
|
||||
void ParamDescriptor::setOperatorType(ValueOperator operatorType)
|
||||
void ParamDescriptor::setOperatorType(Types::ValueOperator operatorType)
|
||||
{
|
||||
m_operatorType = operatorType;
|
||||
}
|
||||
|
||||
@ -27,11 +27,11 @@ class ParamDescriptor : public Param
|
||||
public:
|
||||
ParamDescriptor(const QString &name, const QVariant &value = QVariant());
|
||||
|
||||
ValueOperator operatorType() const;
|
||||
void setOperatorType(ValueOperator operatorType);
|
||||
Types::ValueOperator operatorType() const;
|
||||
void setOperatorType(Types::ValueOperator operatorType);
|
||||
|
||||
private:
|
||||
ValueOperator m_operatorType;
|
||||
Types::ValueOperator m_operatorType;
|
||||
};
|
||||
|
||||
#endif // PARAMDESCRIPTOR_H
|
||||
|
||||
@ -19,12 +19,12 @@
|
||||
#include "statedescriptor.h"
|
||||
|
||||
StateDescriptor::StateDescriptor():
|
||||
m_operatorType(ValueOperatorEquals)
|
||||
m_operatorType(Types::ValueOperatorEquals)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
StateDescriptor::StateDescriptor(const StateTypeId &stateTypeId, const DeviceId &deviceId, const QVariant &stateValue, ValueOperator operatorType):
|
||||
StateDescriptor::StateDescriptor(const StateTypeId &stateTypeId, const DeviceId &deviceId, const QVariant &stateValue, Types::ValueOperator operatorType):
|
||||
m_stateTypeId(stateTypeId),
|
||||
m_deviceId(deviceId),
|
||||
m_stateValue(stateValue),
|
||||
@ -48,7 +48,7 @@ QVariant StateDescriptor::stateValue() const
|
||||
return m_stateValue;
|
||||
}
|
||||
|
||||
ValueOperator StateDescriptor::operatorType() const
|
||||
Types::ValueOperator StateDescriptor::operatorType() const
|
||||
{
|
||||
return m_operatorType;
|
||||
}
|
||||
@ -67,17 +67,17 @@ bool StateDescriptor::operator ==(const State &state) const
|
||||
return false;
|
||||
}
|
||||
switch (m_operatorType) {
|
||||
case ValueOperatorEquals:
|
||||
case Types::ValueOperatorEquals:
|
||||
return m_stateValue == state.value();
|
||||
case ValueOperatorGreater:
|
||||
case Types::ValueOperatorGreater:
|
||||
return state.value() > m_stateValue;
|
||||
case ValueOperatorGreaterOrEqual:
|
||||
case Types::ValueOperatorGreaterOrEqual:
|
||||
return state.value() >= m_stateValue;
|
||||
case ValueOperatorLess:
|
||||
case Types::ValueOperatorLess:
|
||||
return state.value() < m_stateValue;
|
||||
case ValueOperatorLessOrEqual:
|
||||
case Types::ValueOperatorLessOrEqual:
|
||||
return state.value() <= m_stateValue;
|
||||
case ValueOperatorNotEquals:
|
||||
case Types::ValueOperatorNotEquals:
|
||||
return m_stateValue != state.value();
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -31,12 +31,12 @@ class StateDescriptor
|
||||
{
|
||||
public:
|
||||
StateDescriptor();
|
||||
StateDescriptor(const StateTypeId &stateTypeId, const DeviceId &deviceId, const QVariant &stateValue, ValueOperator operatorType = ValueOperatorEquals);
|
||||
StateDescriptor(const StateTypeId &stateTypeId, const DeviceId &deviceId, const QVariant &stateValue, Types::ValueOperator operatorType = Types::ValueOperatorEquals);
|
||||
|
||||
StateTypeId stateTypeId() const;
|
||||
DeviceId deviceId() const;
|
||||
QVariant stateValue() const;
|
||||
ValueOperator operatorType() const;
|
||||
Types::ValueOperator operatorType() const;
|
||||
|
||||
bool operator ==(const StateDescriptor &other) const;
|
||||
|
||||
@ -47,7 +47,7 @@ private:
|
||||
StateTypeId m_stateTypeId;
|
||||
DeviceId m_deviceId;
|
||||
QVariant m_stateValue;
|
||||
ValueOperator m_operatorType;
|
||||
Types::ValueOperator m_operatorType;
|
||||
};
|
||||
QDebug operator<<(QDebug dbg, const StateDescriptor &eventDescriptor);
|
||||
QDebug operator<<(QDebug dbg, const QList<StateDescriptor> &eventDescriptors);
|
||||
|
||||
@ -50,21 +50,28 @@ DECLARE_TYPE_ID(Action)
|
||||
DECLARE_TYPE_ID(Plugin)
|
||||
DECLARE_TYPE_ID(Rule)
|
||||
|
||||
enum ValueOperator {
|
||||
ValueOperatorEquals,
|
||||
ValueOperatorNotEquals,
|
||||
ValueOperatorLess,
|
||||
ValueOperatorGreater,
|
||||
ValueOperatorLessOrEqual,
|
||||
ValueOperatorGreaterOrEqual
|
||||
class Types
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(StateOperator)
|
||||
Q_ENUMS(ValueOperator)
|
||||
|
||||
public:
|
||||
enum ValueOperator {
|
||||
ValueOperatorEquals,
|
||||
ValueOperatorNotEquals,
|
||||
ValueOperatorLess,
|
||||
ValueOperatorGreater,
|
||||
ValueOperatorLessOrEqual,
|
||||
ValueOperatorGreaterOrEqual
|
||||
};
|
||||
enum StateOperator {
|
||||
StateOperatorAnd,
|
||||
StateOperatorOr
|
||||
};
|
||||
};
|
||||
|
||||
enum StateOperator {
|
||||
StateOperatorAnd,
|
||||
StateOperatorOr
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ValueOperator)
|
||||
Q_DECLARE_METATYPE(StateOperator)
|
||||
Q_DECLARE_METATYPE(Types::ValueOperator)
|
||||
Q_DECLARE_METATYPE(Types::StateOperator)
|
||||
|
||||
#endif // TYPEUTILS_H
|
||||
|
||||
@ -72,7 +72,7 @@ DeviceManager::HardwareResources DevicePluginConrad::requiredHardware() const
|
||||
return DeviceManager::HardwareResourceRadio433;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginConrad::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginConrad::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
QList<int> rawData;
|
||||
QByteArray binCode;
|
||||
@ -117,10 +117,10 @@ QPair<DeviceManager::DeviceError, QString> DevicePluginConrad::executeAction(Dev
|
||||
// send data to driver
|
||||
if(transmitData(delay, rawData)){
|
||||
qDebug() << "action" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}else{
|
||||
qDebug() << "could not transmitt" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
|
||||
return report(DeviceManager::DeviceErrorHardwareNotAvailable, "Radio 433 MHz transmitter not available.");
|
||||
return DeviceManager::DeviceErrorHardwareNotAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ public:
|
||||
void radioData(const QList<int> &rawData) override;
|
||||
|
||||
public slots:
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ DeviceManager::HardwareResources DevicePluginElro::requiredHardware() const
|
||||
return DeviceManager::HardwareResourceRadio433;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginElro::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginElro::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
|
||||
QList<int> rawData;
|
||||
@ -162,10 +162,10 @@ QPair<DeviceManager::DeviceError, QString> DevicePluginElro::executeAction(Devic
|
||||
// send data to hardware resource
|
||||
if(transmitData(delay, rawData)){
|
||||
qDebug() << "transmitted" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}else{
|
||||
qDebug() << "could not transmitt" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
|
||||
return report(DeviceManager::DeviceErrorHardwareNotAvailable,QString("Radio 433 MHz transmitter not available."));
|
||||
return DeviceManager::DeviceErrorHardwareNotAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ public:
|
||||
void radioData(const QList<int> &rawData) override;
|
||||
|
||||
public slots:
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -247,13 +247,13 @@ QList<ParamType> DevicePluginEQ3::configurationDescription() const
|
||||
return params;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginEQ3::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
DeviceManager::DeviceError DevicePluginEQ3::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
if(deviceClassId == cubeDeviceClassId){
|
||||
m_cubeDiscovery->detectCubes();
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
return report(DeviceManager::DeviceErrorDeviceClassNotFound);
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
|
||||
void DevicePluginEQ3::startMonitoringAutoDevices()
|
||||
@ -317,36 +317,32 @@ void DevicePluginEQ3::guhTimer()
|
||||
}
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginEQ3::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginEQ3::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
if(device->deviceClassId() == wallThermostateDeviceClassId || device->deviceClassId() == radiatorThermostateDeviceClassId){
|
||||
foreach (MaxCube *cube, m_cubes.keys()){
|
||||
if(cube->serialNumber() == device->paramValue("parent cube").toString()){
|
||||
|
||||
QByteArray rfAddress = device->paramValue("rf address").toByteArray();
|
||||
int roomId = device->paramValue("room id").toInt();
|
||||
|
||||
if (action.actionTypeId() == setSetpointTemperatureActionTypeId){
|
||||
cube->setDeviceSetpointTemp(device->paramValue("rf address").toByteArray(), device->paramValue("room id").toInt(), action.param("setpoint temperature").value().toDouble(), action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync,QString());
|
||||
}
|
||||
if (action.actionTypeId() == setAutoModeActionTypeId){
|
||||
cube->setDeviceAutoMode(device->paramValue("rf address").toByteArray(), device->paramValue("room id").toInt(), action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync,QString());
|
||||
}
|
||||
if (action.actionTypeId() == setManuelModeActionTypeId){
|
||||
cube->setDeviceManuelMode(device->paramValue("rf address").toByteArray(), device->paramValue("room id").toInt(), action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync,QString());
|
||||
}
|
||||
if (action.actionTypeId() == setEcoModeActionTypeId){
|
||||
cube->setDeviceEcoMode(device->paramValue("rf address").toByteArray(), device->paramValue("room id").toInt(), action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync,QString());
|
||||
}
|
||||
if (action.actionTypeId() == displayCurrentTempActionTypeId){
|
||||
cube->displayCurrentTemperature(device->paramValue("rf address").toByteArray(), device->paramValue("room id").toInt(), action.param("display").value().toBool(), action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync,QString());
|
||||
cube->setDeviceSetpointTemp(rfAddress, roomId, action.param("setpoint temperature").value().toDouble(), action.id());
|
||||
} else if (action.actionTypeId() == setAutoModeActionTypeId){
|
||||
cube->setDeviceAutoMode(rfAddress, roomId, action.id());
|
||||
} else if (action.actionTypeId() == setManuelModeActionTypeId){
|
||||
cube->setDeviceManuelMode(rfAddress, roomId, action.id());
|
||||
} else if (action.actionTypeId() == setEcoModeActionTypeId){
|
||||
cube->setDeviceEcoMode(rfAddress, roomId, action.id());
|
||||
} else if (action.actionTypeId() == displayCurrentTempActionTypeId){
|
||||
cube->displayCurrentTemperature(rfAddress, roomId, action.param("display").value().toBool(), action.id());
|
||||
}
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return report(DeviceManager::DeviceErrorActionTypeNotFound,QString());
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
|
||||
void DevicePluginEQ3::cubeConnectionStatusChanged(const bool &connected)
|
||||
|
||||
@ -39,7 +39,7 @@ public:
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
|
||||
QList<ParamType> configurationDescription() const override;
|
||||
QPair<DeviceManager::DeviceError, QString> discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
|
||||
void startMonitoringAutoDevices() override;
|
||||
|
||||
@ -53,7 +53,7 @@ private:
|
||||
QHash<MaxCube*, Device*> m_cubes;
|
||||
|
||||
public slots:
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action);
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action);
|
||||
|
||||
private slots:
|
||||
void cubeConnectionStatusChanged(const bool &connected);
|
||||
|
||||
@ -175,7 +175,7 @@ DeviceManager::HardwareResources DevicePluginIntertechno::requiredHardware() con
|
||||
return DeviceManager::HardwareResourceRadio433;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginIntertechno::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
|
||||
QList<int> rawData;
|
||||
@ -218,7 +218,7 @@ QPair<DeviceManager::DeviceError, QString> DevicePluginIntertechno::executeActio
|
||||
}else if(familyCode == "P"){
|
||||
binCode.append("01010101");
|
||||
}else{
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
QString buttonCode = device->paramValue("buttonCode").toString();
|
||||
@ -258,7 +258,7 @@ QPair<DeviceManager::DeviceError, QString> DevicePluginIntertechno::executeActio
|
||||
}else if(familyCode == "16"){
|
||||
binCode.append("01010101");
|
||||
}else{
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
// =======================================
|
||||
@ -297,10 +297,10 @@ QPair<DeviceManager::DeviceError, QString> DevicePluginIntertechno::executeActio
|
||||
// send data to hardware resource
|
||||
if(transmitData(delay, rawData)){
|
||||
qDebug() << "transmitted" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}else{
|
||||
qWarning() << "ERROR: could not transmitt" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
|
||||
return report(DeviceManager::DeviceErrorHardwareNotAvailable, QString("Radio 433 MHz transmitter not available."));
|
||||
return DeviceManager::DeviceErrorHardwareNotAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ public:
|
||||
void radioData(const QList<int> &rawData) override;
|
||||
|
||||
public slots:
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -65,17 +65,17 @@ DevicePluginLgSmartTv::DevicePluginLgSmartTv()
|
||||
connect(m_discovery,SIGNAL(discoveryDone(QList<TvDevice*>)),this,SLOT(discoveryDone(QList<TvDevice*>)));
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginLgSmartTv::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
DeviceManager::DeviceError DevicePluginLgSmartTv::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
qDebug() << "should discover devices with params:" << params;
|
||||
|
||||
if(deviceClassId != lgSmartTvDeviceClassId){
|
||||
return report(DeviceManager::DeviceErrorDeviceClassNotFound);
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
|
||||
m_discovery->discover(3000);
|
||||
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> DevicePluginLgSmartTv::setupDevice(Device *device)
|
||||
@ -110,84 +110,50 @@ DeviceManager::HardwareResources DevicePluginLgSmartTv::requiredHardware() const
|
||||
return DeviceManager::HardwareResourceTimer;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginLgSmartTv::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginLgSmartTv::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
TvDevice * tvDevice = m_tvList.key(device);
|
||||
|
||||
if(action.actionTypeId() == commandVolumeUpActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::VolUp, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandVolumeDownActionTypeId){
|
||||
} else if(action.actionTypeId() == commandVolumeDownActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::VolDown, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandMuteActionTypeId){
|
||||
} else if(action.actionTypeId() == commandMuteActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Mute, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandChannelUpActionTypeId){
|
||||
} else if(action.actionTypeId() == commandChannelUpActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::ChannelUp, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandChannelDownActionTypeId){
|
||||
} else if(action.actionTypeId() == commandChannelDownActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::ChannelDown, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandPowerOffActionTypeId){
|
||||
} else if(action.actionTypeId() == commandPowerOffActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Power, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandArrowUpActionTypeId){
|
||||
} else if(action.actionTypeId() == commandArrowUpActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Up, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandArrowDownActionTypeId){
|
||||
} else if(action.actionTypeId() == commandArrowDownActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Down, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandArrowLeftActionTypeId){
|
||||
} else if(action.actionTypeId() == commandArrowLeftActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Left, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandArrowRightActionTypeId){
|
||||
} else if(action.actionTypeId() == commandArrowRightActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Right, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandOkActionTypeId){
|
||||
} else if(action.actionTypeId() == commandOkActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Ok, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandBackActionTypeId){
|
||||
} else if(action.actionTypeId() == commandBackActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Back, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandHomeActionTypeId){
|
||||
} else if(action.actionTypeId() == commandHomeActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Home, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandInputSourceActionTypeId){
|
||||
} else if(action.actionTypeId() == commandInputSourceActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::ExternalInput, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandExitActionTypeId){
|
||||
} else if(action.actionTypeId() == commandExitActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Exit, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandInfoActionTypeId){
|
||||
} else if(action.actionTypeId() == commandInfoActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::Info, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandMyAppsActionTypeId){
|
||||
} else if(action.actionTypeId() == commandMyAppsActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::MyApps, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
if(action.actionTypeId() == commandProgramListActionTypeId){
|
||||
} else if(action.actionTypeId() == commandProgramListActionTypeId){
|
||||
tvDevice->sendCommand(TvDevice::ProgramList, action.id());
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
} else {
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
|
||||
return report(DeviceManager::DeviceErrorActionTypeNotFound);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
void DevicePluginLgSmartTv::deviceRemoved(Device *device)
|
||||
|
||||
@ -34,10 +34,10 @@ public:
|
||||
|
||||
TvDiscovery *m_discovery;
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> setupDevice(Device *device) override;
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
void deviceRemoved(Device *device) override;
|
||||
|
||||
|
||||
@ -263,7 +263,7 @@ DeviceManager::HardwareResources DevicePluginMailNotification::requiredHardware(
|
||||
return DeviceManager::HardwareResourceNone;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginMailNotification::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginMailNotification::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
qDebug() << "execute action " << sendMailActionTypeId.toString();
|
||||
if(action.actionTypeId() == sendMailActionTypeId){
|
||||
@ -294,5 +294,5 @@ QPair<DeviceManager::DeviceError, QString> DevicePluginMailNotification::execute
|
||||
m_smtpClient->sendMail(device->paramValue("user").toString(), device->paramValue("recipient").toString(), action.param("subject").value().toString(), action.param("body").value().toString());
|
||||
}
|
||||
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public:
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> setupDevice(Device *device) override;
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
private:
|
||||
SmtpClient *m_smtpClient;
|
||||
|
||||
@ -49,13 +49,13 @@ DeviceManager::HardwareResources DevicePluginMock::requiredHardware() const
|
||||
return DeviceManager::HardwareResourceTimer;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginMock::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
DeviceManager::DeviceError DevicePluginMock::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
Q_UNUSED(deviceClassId)
|
||||
qDebug() << "starting mock discovery:" << params;
|
||||
m_discoveredDeviceCount = params.paramValue("resultCount").toInt();
|
||||
QTimer::singleShot(1000, this, SLOT(emitDevicesDiscovered()));
|
||||
return report(DeviceManager::DeviceErrorNoError);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> DevicePluginMock::setupDevice(Device *device)
|
||||
@ -126,26 +126,26 @@ QList<ParamType> DevicePluginMock::configurationDescription() const
|
||||
return params;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginMock::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginMock::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
if (!myDevices().contains(device)) {
|
||||
qWarning() << "Should execute action for a device which doesn't seem to be mine.";
|
||||
return report(DeviceManager::DeviceErrorDeviceNotFound, "Should execute an action for a device which doesn't seem to be mine.");
|
||||
return DeviceManager::DeviceErrorDeviceNotFound;
|
||||
}
|
||||
|
||||
if (action.actionTypeId() == mockActionIdAsync || action.actionTypeId() == mockActionIdAsyncFailing) {
|
||||
m_asyncActions.append(qMakePair<Action, Device*>(action, device));
|
||||
QTimer::singleShot(1000, this, SLOT(emitActionExecuted()));
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
if (action.actionTypeId() == mockActionIdFailing) {
|
||||
return report(DeviceManager::DeviceErrorSetupFailed);
|
||||
return DeviceManager::DeviceErrorSetupFailed;
|
||||
}
|
||||
|
||||
qDebug() << "Should execute action" << action.actionTypeId();
|
||||
m_daemons.value(device)->actionExecuted(action.actionTypeId());
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
void DevicePluginMock::setState(const StateTypeId &stateTypeId, const QVariant &value)
|
||||
|
||||
@ -37,7 +37,7 @@ public:
|
||||
~DevicePluginMock();
|
||||
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
QPair<DeviceManager::DeviceError, QString> discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> setupDevice(Device *device) override;
|
||||
void deviceRemoved(Device *device) override;
|
||||
@ -47,7 +47,7 @@ public:
|
||||
QList<ParamType> configurationDescription() const override;
|
||||
|
||||
public slots:
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
private slots:
|
||||
void setState(const StateTypeId &stateTypeId, const QVariant &value);
|
||||
|
||||
@ -303,7 +303,7 @@ DevicePluginOpenweathermap::DevicePluginOpenweathermap()
|
||||
connect(m_openweaher, &OpenWeatherMap::weatherDataReady, this, &DevicePluginOpenweathermap::weatherDataReady);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginOpenweathermap::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
DeviceManager::DeviceError DevicePluginOpenweathermap::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
if(deviceClassId != openweathermapDeviceClassId){
|
||||
return report(DeviceManager::DeviceErrorDeviceClassNotFound);
|
||||
@ -319,14 +319,10 @@ QPair<DeviceManager::DeviceError, QString> DevicePluginOpenweathermap::discoverD
|
||||
// if we have an empty search string, perform an autodetection of the location with the WAN ip...
|
||||
if (location.isEmpty()){
|
||||
m_openweaher->searchAutodetect();
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}else{
|
||||
return report(DeviceManager::DeviceErrorDeviceClassNotFound);
|
||||
} else {
|
||||
m_openweaher->search(location);
|
||||
}
|
||||
|
||||
// otherwise search the given string
|
||||
m_openweaher->search(location);
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> DevicePluginOpenweathermap::setupDevice(Device *device)
|
||||
@ -348,12 +344,12 @@ DeviceManager::HardwareResources DevicePluginOpenweathermap::requiredHardware()
|
||||
return DeviceManager::HardwareResourceTimer;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginOpenweathermap::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginOpenweathermap::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
if(action.actionTypeId() == updateWeatherActionTypeId){
|
||||
m_openweaher->update(device->paramValue("id").toString(), device->id());
|
||||
}
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
void DevicePluginOpenweathermap::guhTimer()
|
||||
|
||||
@ -35,10 +35,10 @@ public:
|
||||
|
||||
OpenWeatherMap *m_openweaher;
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> setupDevice(Device *device) override;
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
void guhTimer() override;
|
||||
|
||||
|
||||
@ -69,12 +69,12 @@ QList<ParamType> DevicePluginPhilipsHue::configurationDescription() const
|
||||
return params;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginPhilipsHue::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
DeviceManager::DeviceError DevicePluginPhilipsHue::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
Q_UNUSED(deviceClassId)
|
||||
Q_UNUSED(params)
|
||||
m_discovery->findBridges(4000);
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> DevicePluginPhilipsHue::setupDevice(Device *device)
|
||||
@ -171,17 +171,18 @@ void DevicePluginPhilipsHue::guhTimer()
|
||||
}
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginPhilipsHue::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
qDebug() << "Should execute action in hue plugin";
|
||||
|
||||
Light *light = m_lights.key(device);
|
||||
if (!light) {
|
||||
return report(DeviceManager::DeviceErrorDeviceNotFound, device->id().toString());
|
||||
return DeviceManager::DeviceErrorDeviceNotFound;
|
||||
}
|
||||
|
||||
if (!light->reachable()) {
|
||||
return report(DeviceManager::DeviceErrorSetupFailed, "This light is currently not reachable.");
|
||||
qWarning() << "Hue Bulb not reachable";
|
||||
return DeviceManager::DeviceErrorSetupFailed;
|
||||
}
|
||||
|
||||
if (action.actionTypeId() == hueSetColorActionTypeId) {
|
||||
@ -191,7 +192,7 @@ QPair<DeviceManager::DeviceError, QString> DevicePluginPhilipsHue::executeAction
|
||||
} else if (action.actionTypeId() == hueSetBrightnessActionTypeId) {
|
||||
light->setBri(action.param("brightness").value().toInt());
|
||||
}
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
void DevicePluginPhilipsHue::discoveryDone(const QList<QHostAddress> &bridges)
|
||||
|
||||
@ -41,7 +41,7 @@ public:
|
||||
void startMonitoringAutoDevices() override;
|
||||
|
||||
QList<ParamType> configurationDescription() const override;
|
||||
QPair<DeviceManager::DeviceError, QString> discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> setupDevice(Device *device) override;
|
||||
void deviceRemoved(Device *device) override;
|
||||
@ -51,7 +51,7 @@ public:
|
||||
void guhTimer() override;
|
||||
|
||||
public slots:
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action);
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action);
|
||||
|
||||
private slots:
|
||||
void discoveryDone(const QList<QHostAddress> &bridges);
|
||||
|
||||
@ -161,13 +161,13 @@ DeviceManager::HardwareResources DevicePluginWakeOnLan::requiredHardware() const
|
||||
return DeviceManager::HardwareResourceNone;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginWakeOnLan::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginWakeOnLan::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
qDebug() << "execute action " << action.actionTypeId().toString();
|
||||
if(action.actionTypeId() == wolActionTypeId){
|
||||
wakeup(device->paramValue("mac").toString());
|
||||
}
|
||||
return report();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
void DevicePluginWakeOnLan::wakeup(QString mac)
|
||||
|
||||
@ -35,7 +35,7 @@ public:
|
||||
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
|
||||
private slots:
|
||||
|
||||
@ -146,15 +146,15 @@ DevicePluginWemo::DevicePluginWemo()
|
||||
connect(m_discovery,SIGNAL(discoveryDone(QList<WemoSwitch*>)),this,SLOT(discoveryDone(QList<WemoSwitch*>)));
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginWemo::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
DeviceManager::DeviceError DevicePluginWemo::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
if(deviceClassId != wemoSwitchDeviceClassId){
|
||||
return report(DeviceManager::DeviceErrorDeviceClassNotFound);
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
|
||||
m_discovery->discover(2000);
|
||||
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> DevicePluginWemo::setupDevice(Device *device)
|
||||
@ -196,20 +196,20 @@ DeviceManager::HardwareResources DevicePluginWemo::requiredHardware() const
|
||||
return DeviceManager::HardwareResourceTimer;
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginWemo::executeAction(Device *device, const Action &action)
|
||||
DeviceManager::DeviceError DevicePluginWemo::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
if(device->deviceClassId() == wemoSwitchDeviceClassId){
|
||||
if(action.actionTypeId() == powerActionTypeId){
|
||||
WemoSwitch *wemoSwitch = m_wemoSwitches.key(device);
|
||||
wemoSwitch->setPower(action.param("power").value().toBool(),action.id());
|
||||
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}else{
|
||||
return report(DeviceManager::DeviceErrorActionTypeNotFound);
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
}
|
||||
|
||||
return report(DeviceManager::DeviceErrorDeviceClassNotFound);
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
|
||||
void DevicePluginWemo::deviceRemoved(Device *device)
|
||||
|
||||
@ -32,10 +32,10 @@ class DevicePluginWemo : public DevicePlugin
|
||||
public:
|
||||
explicit DevicePluginWemo();
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> setupDevice(Device *device) override;
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(Device *device, const Action &action) override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
void deviceRemoved(Device *device) override;
|
||||
|
||||
|
||||
@ -127,7 +127,7 @@ QPair<DeviceManager::DeviceError, QString> GuhCore::confirmPairing(const QUuid &
|
||||
return m_deviceManager->confirmPairing(pairingTransactionId, secret);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::executeAction(const Action &action)
|
||||
DeviceManager::DeviceError GuhCore::executeAction(const Action &action)
|
||||
{
|
||||
return m_deviceManager->executeAction(action);
|
||||
}
|
||||
@ -137,17 +137,17 @@ DeviceClass GuhCore::findDeviceClass(const DeviceClassId &deviceClassId) const
|
||||
return m_deviceManager->findDeviceClass(deviceClassId);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
DeviceManager::DeviceError GuhCore::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
return m_deviceManager->discoverDevices(deviceClassId, params);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId &newId)
|
||||
DeviceManager::DeviceError GuhCore::addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId &newId)
|
||||
{
|
||||
return m_deviceManager->addConfiguredDevice(deviceClassId, params, newId);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> GuhCore::addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &newId)
|
||||
DeviceManager::DeviceError GuhCore::addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &newId)
|
||||
{
|
||||
return m_deviceManager->addConfiguredDevice(deviceClassId, deviceDescriptorId, newId);
|
||||
}
|
||||
@ -252,18 +252,18 @@ void GuhCore::gotEvent(const Event &event)
|
||||
// Now execute all the associated rules
|
||||
foreach (const Action &action, m_ruleEngine->evaluateEvent(event)) {
|
||||
qDebug() << "executing action" << action.actionTypeId();
|
||||
QPair<DeviceManager::DeviceError, QString> status = m_deviceManager->executeAction(action);
|
||||
switch(status.first) {
|
||||
DeviceManager::DeviceError status = m_deviceManager->executeAction(action);
|
||||
switch(status) {
|
||||
case DeviceManager::DeviceErrorNoError:
|
||||
break;
|
||||
case DeviceManager::DeviceErrorSetupFailed:
|
||||
qDebug() << "Error executing action. Device setup failed:" << status.second;
|
||||
qDebug() << "Error executing action. Device setup failed.";
|
||||
break;
|
||||
case DeviceManager::DeviceErrorActionParameterError:
|
||||
qDebug() << "Error executing action. Invalid action parameter:" << status.second;
|
||||
qDebug() << "Error executing action. Invalid action parameter.";
|
||||
break;
|
||||
default:
|
||||
qDebug() << "Error executing action:" << status.first << status.second;
|
||||
qDebug() << "Error executing action:" << status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,9 +49,9 @@ public:
|
||||
QList<Vendor> supportedVendors() const;
|
||||
QList<DeviceClass> supportedDevices(const VendorId &vendorId = VendorId()) const;
|
||||
DeviceClass findDeviceClass(const DeviceClassId &deviceClassId) const;
|
||||
QPair<DeviceManager::DeviceError, QString> discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||
QPair<DeviceManager::DeviceError, QString> addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId &newId);
|
||||
QPair<DeviceManager::DeviceError, QString> addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &newId);
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||
DeviceManager::DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms, const DeviceId &newId);
|
||||
DeviceManager::DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const DeviceDescriptorId &deviceDescriptorId, const DeviceId &newId);
|
||||
QList<Device*> configuredDevices() const;
|
||||
Device *findConfiguredDevice(const DeviceId &deviceId) const;
|
||||
QList<Device*> findConfiguredDevices(const DeviceClassId &deviceClassId) const;
|
||||
@ -61,7 +61,7 @@ public:
|
||||
QPair<DeviceManager::DeviceError, QString> pairDevice(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||
QPair<DeviceManager::DeviceError, QString> confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> executeAction(const Action &action);
|
||||
DeviceManager::DeviceError executeAction(const Action &action);
|
||||
|
||||
QList<Rule> rules() const;
|
||||
QList<RuleId> ruleIds() const;
|
||||
|
||||
@ -41,8 +41,7 @@ ActionHandler::ActionHandler(QObject *parent) :
|
||||
setDescription("GetActionType", "Get the ActionType for the given ActionTypeId");
|
||||
params.insert("actionTypeId", "uuid");
|
||||
setParams("GetActionType", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("deviceError", "int");
|
||||
returns.insert("o:actionType", JsonTypes::actionTypeDescription());
|
||||
setReturns("GetActionType", returns);
|
||||
|
||||
@ -67,14 +66,15 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap ¶ms)
|
||||
qDebug() << "actions params in json" << action.params() << params;
|
||||
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> status = GuhCore::instance()->executeAction(action);
|
||||
if (status.first == DeviceManager::DeviceErrorAsync) {
|
||||
DeviceManager::DeviceError status = GuhCore::instance()->executeAction(action);
|
||||
if (status == DeviceManager::DeviceErrorAsync) {
|
||||
JsonReply *reply = createAsyncReply("ExecuteAction");
|
||||
m_asyncActionExecutions.insert(action.id(), reply);
|
||||
return reply;
|
||||
}
|
||||
|
||||
QVariantMap returns = statusToReply(status.first, status.second);
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", status);
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -85,16 +85,14 @@ JsonReply *ActionHandler::GetActionType(const QVariantMap ¶ms) const
|
||||
foreach (const ActionType &actionType, deviceClass.actionTypes()) {
|
||||
if (actionType.id() == actionTypeId) {
|
||||
QVariantMap data;
|
||||
data.insert("success", true);
|
||||
data.insert("errorMessage", QString());
|
||||
data.insert("deviceError", DeviceManager::DeviceErrorNoError);
|
||||
data.insert("actionType", JsonTypes::packActionType(actionType));
|
||||
return createReply(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
QVariantMap data;
|
||||
data.insert("success", false);
|
||||
data.insert("errorMessage", QString("No ActionType with id %1.").arg(actionTypeId.toString()));
|
||||
data.insert("deviceError", DeviceManager::DeviceErrorActionTypeNotFound);
|
||||
return createReply(data);
|
||||
}
|
||||
|
||||
@ -112,19 +110,6 @@ void ActionHandler::actionExecuted(const ActionId &id, DeviceManager::DeviceErro
|
||||
QVariantMap ActionHandler::statusToReply(DeviceManager::DeviceError status, const QString &errorMessage)
|
||||
{
|
||||
QVariantMap returns;
|
||||
returns.insert("success", status == DeviceManager::DeviceErrorNoError);
|
||||
returns.insert("errorMessage", errorMessage);
|
||||
|
||||
switch (status) {
|
||||
case DeviceManager::DeviceErrorNoError:
|
||||
break;
|
||||
case DeviceManager::DeviceErrorDeviceNotFound:
|
||||
returns.insert("errorMessage", QString("Device not found: %1").arg(errorMessage));
|
||||
break;
|
||||
case DeviceManager::DeviceErrorSetupFailed:
|
||||
returns.insert("errorMessage", QString("Device setup failed: %1").arg(errorMessage));
|
||||
break;
|
||||
}
|
||||
|
||||
returns.insert("deviceError", status);
|
||||
return returns;
|
||||
}
|
||||
|
||||
@ -62,8 +62,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
setParams("GetPluginConfiguration", params);
|
||||
QVariantList pluginParams;
|
||||
pluginParams.append(JsonTypes::paramRef());
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("deviceError", "DeviceError");
|
||||
returns.insert("o:configuration", pluginParams);
|
||||
setReturns("GetPluginConfiguration", returns);
|
||||
|
||||
@ -72,8 +71,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
params.insert("pluginId", "uuid");
|
||||
params.insert("configuration", pluginParams);
|
||||
setParams("SetPluginConfiguration", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("deviceError", "DeviceError");
|
||||
setReturns("SetPluginConfiguration", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
@ -89,8 +87,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
deviceParams.append(JsonTypes::paramRef());
|
||||
params.insert("o:deviceParams", deviceParams);
|
||||
setParams("AddConfiguredDevice", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("deviceError", "DeviceError");
|
||||
returns.insert("o:deviceId", "uuid");
|
||||
setReturns("AddConfiguredDevice", returns);
|
||||
|
||||
@ -105,8 +102,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
" or PairDevice."
|
||||
);
|
||||
setParams("PairDevice", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("deviceError", "DeviceError");
|
||||
returns.insert("o:pairingTransactionId", "uuid");
|
||||
returns.insert("o:displayMessage", "string");
|
||||
returns.insert("o:setupMethod", JsonTypes::setupMethodTypesRef());
|
||||
@ -117,8 +113,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
params.insert("pairingTransactionId", "uuid");
|
||||
params.insert("o:secret", "string");
|
||||
setParams("ConfirmPairing", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("deviceError", "DeviceError");
|
||||
returns.insert("o:deviceId", "uuid");
|
||||
setReturns("ConfirmPairing", returns);
|
||||
|
||||
@ -137,8 +132,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
discoveryParams.append(JsonTypes::paramRef());
|
||||
params.insert("o:discoveryParams", discoveryParams);
|
||||
setParams("GetDiscoveredDevices", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("deviceError", "DeviceError");
|
||||
QVariantList deviceDescriptors;
|
||||
deviceDescriptors.append(JsonTypes::deviceDescriptorRef());
|
||||
returns.insert("o:deviceDescriptors", deviceDescriptors);
|
||||
@ -154,8 +148,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
removePolicyList.append(policy);
|
||||
params.insert("o:removePolicyList", removePolicyList);
|
||||
setParams("RemoveConfiguredDevice", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("deviceError", "DeviceError");
|
||||
setReturns("RemoveConfiguredDevice", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
@ -190,8 +183,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
params.insert("deviceId", "uuid");
|
||||
params.insert("stateTypeId", "uuid");
|
||||
setParams("GetStateValue", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("deviceError", "DeviceError");
|
||||
returns.insert("o:value", "variant");
|
||||
setReturns("GetStateValue", returns);
|
||||
|
||||
@ -251,31 +243,13 @@ JsonReply *DeviceHandler::GetDiscoveredDevices(const QVariantMap ¶ms) const
|
||||
|
||||
ParamList discoveryParams = JsonTypes::unpackParams(params.value("discoveryParams").toList());
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> status = GuhCore::instance()->discoverDevices(deviceClassId, discoveryParams);
|
||||
switch (status.first) {
|
||||
case DeviceManager::DeviceErrorAsync:
|
||||
case DeviceManager::DeviceErrorNoError: {
|
||||
DeviceManager::DeviceError status = GuhCore::instance()->discoverDevices(deviceClassId, discoveryParams);
|
||||
if (status == DeviceManager::DeviceErrorAsync ) {
|
||||
JsonReply *reply = createAsyncReply("GetDiscoveredDevices");
|
||||
m_discoverRequests.insert(deviceClassId, reply);
|
||||
return reply;
|
||||
}
|
||||
case DeviceManager::DeviceErrorDeviceClassNotFound:
|
||||
returns.insert("errorMessage", QString("Cannot discover devices. Unknown DeviceClassId: %1").arg(status.second));
|
||||
break;
|
||||
case DeviceManager::DeviceErrorPluginNotFound:
|
||||
returns.insert("errorMessage", "Cannot discover devices. Plugin for DeviceClass not found.");
|
||||
break;
|
||||
case DeviceManager::DeviceErrorCreationMethodNotSupported:
|
||||
returns.insert("errorMessage", "This device can't be discovered.");
|
||||
break;
|
||||
case DeviceManager::DeviceErrorMissingParameter:
|
||||
returns.insert("errorMessage", QString("Missing parameter: %1").arg(status.second));
|
||||
break;
|
||||
default:
|
||||
returns.insert("errorMessage", QString("Unknown error %1 %2").arg(status.first).arg(status.second));
|
||||
}
|
||||
|
||||
returns.insert("success", false);
|
||||
returns.insert("deviceError", status);
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -342,7 +316,7 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
||||
ParamList deviceParams = JsonTypes::unpackParams(params.value("deviceParams").toList());
|
||||
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
|
||||
DeviceId newDeviceId = DeviceId::createDeviceId();
|
||||
QPair<DeviceManager::DeviceError, QString> status;
|
||||
DeviceManager::DeviceError status;
|
||||
if (deviceDescriptorId.isNull()) {
|
||||
qDebug() << "adding a manual device.";
|
||||
status = GuhCore::instance()->addConfiguredDevice(deviceClass, deviceParams, newDeviceId);
|
||||
@ -351,40 +325,16 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
||||
status = GuhCore::instance()->addConfiguredDevice(deviceClass, deviceDescriptorId, newDeviceId);
|
||||
}
|
||||
QVariantMap returns;
|
||||
switch(status.first) {
|
||||
switch (status) {
|
||||
case DeviceManager::DeviceErrorAsync: {
|
||||
JsonReply *asyncReply = createAsyncReply("AddConfiguredDevice");
|
||||
m_asynDeviceAdditions.insert(newDeviceId, asyncReply);
|
||||
return asyncReply;
|
||||
}
|
||||
case DeviceManager::DeviceErrorNoError:
|
||||
returns.insert("success", true);
|
||||
returns.insert("errorMessage", "");
|
||||
returns.insert("deviceId", newDeviceId);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorDeviceClassNotFound:
|
||||
returns.insert("errorMessage", QString("Error creating device. Device class not found: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorMissingParameter:
|
||||
returns.insert("errorMessage", QString("Error creating device. Missing parameter: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorSetupFailed:
|
||||
returns.insert("errorMessage", QString("Error creating device. Device setup failed: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorCreationMethodNotSupported:
|
||||
returns.insert("errorMessage", QString("Error creating device. This device can't be created this way: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
case DeviceManager::DeviceErrorInvalidParameter:
|
||||
returns.insert("errorMessage", QString("Error creating device. Invalid device parameter: %1").arg(status.second));
|
||||
returns.insert("success", false);
|
||||
break;
|
||||
default:
|
||||
returns.insert("errorMessage", "Unknown error. Please report a bug describing what you did.");
|
||||
returns.insert("success", false);
|
||||
returns.insert("deviceError", status);
|
||||
}
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -77,7 +77,6 @@ JsonRPCServer::JsonRPCServer(QObject *parent):
|
||||
setParams("SetNotificationStatus", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("enabled", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
setReturns("SetNotificationStatus", returns);
|
||||
|
||||
// Now set up the logic
|
||||
@ -132,7 +131,6 @@ JsonReply* JsonRPCServer::SetNotificationStatus(const QVariantMap ¶ms)
|
||||
m_clients[clientId] = params.value("enabled").toBool();
|
||||
QVariantMap returns;
|
||||
returns.insert("success", "true");
|
||||
returns.insert("errorMessage", "No error");
|
||||
returns.insert("enabled", m_clients[clientId]);
|
||||
return createReply(returns);
|
||||
}
|
||||
@ -206,12 +204,23 @@ void JsonRPCServer::processData(const QUuid &clientId, const QByteArray &jsonDat
|
||||
connect(reply, &JsonReply::finished, this, &JsonRPCServer::asyncReplyFinished);
|
||||
reply->startWait();
|
||||
} else {
|
||||
Q_ASSERT((targetNamespace == "JSONRPC" && method == "Introspect") || handler->validateReturns(method, reply->data()).first);
|
||||
Q_ASSERT_X((targetNamespace == "JSONRPC" && method == "Introspect") || handler->validateReturns(method, reply->data()).first
|
||||
,"validating return value", formatAssertion(targetNamespace, method, handler, reply->data()).toLatin1().data());
|
||||
sendResponse(clientId, commandId, reply->data());
|
||||
reply->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
QString JsonRPCServer::formatAssertion(const QString &targetNamespace, const QString &method, JsonHandler *handler, const QVariantMap &data) const
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromVariant(handler->introspect(QMetaMethod::Method).value(targetNamespace + "." + method));
|
||||
QJsonDocument doc2 = QJsonDocument::fromVariant(data);
|
||||
return QString("\nMethod: %1\nTemplate: %2\nValue: %3")
|
||||
.arg(targetNamespace + "." + method)
|
||||
.arg(QString(doc.toJson()))
|
||||
.arg(QString(doc2.toJson()));
|
||||
}
|
||||
|
||||
void JsonRPCServer::sendNotification(const QVariantMap ¶ms)
|
||||
{
|
||||
JsonHandler *handler = qobject_cast<JsonHandler*>(sender());
|
||||
|
||||
@ -69,6 +69,8 @@ private:
|
||||
void sendResponse(const QUuid &clientId, int commandId, const QVariantMap ¶ms = QVariantMap());
|
||||
void sendErrorResponse(const QUuid &clientId, int commandId, const QString &error);
|
||||
|
||||
QString formatAssertion(const QString &targetNamespace, const QString &method, JsonHandler *handler, const QVariantMap &data) const;
|
||||
|
||||
private:
|
||||
#ifdef TESTING_ENABLED
|
||||
MockTcpServer *m_tcpServer;
|
||||
|
||||
@ -19,10 +19,13 @@
|
||||
#include "jsontypes.h"
|
||||
|
||||
#include "plugin/device.h"
|
||||
#include "devicemanager.h"
|
||||
#include "ruleengine.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QJsonDocument>
|
||||
#include <QDebug>
|
||||
#include <QMetaEnum>
|
||||
|
||||
bool JsonTypes::s_initialized = false;
|
||||
QString JsonTypes::s_lastError;
|
||||
@ -33,6 +36,8 @@ QVariantList JsonTypes::s_valueOperatorTypes;
|
||||
QVariantList JsonTypes::s_createMethodTypes;
|
||||
QVariantList JsonTypes::s_setupMethodTypes;
|
||||
QVariantList JsonTypes::s_removePolicyTypes;
|
||||
QVariantList JsonTypes::s_deviceErrorTypes;
|
||||
QVariantList JsonTypes::s_ruleErrorTypes;
|
||||
|
||||
QVariantMap JsonTypes::s_paramType;
|
||||
QVariantMap JsonTypes::s_param;
|
||||
@ -56,12 +61,14 @@ QVariantMap JsonTypes::s_rule;
|
||||
void JsonTypes::init()
|
||||
{
|
||||
// BasicTypes
|
||||
s_basicTypes << "uuid" << "string" << "integer" << "double" << "bool";
|
||||
s_stateOperatorTypes << "StateOperatorAnd" << "StateOperatorOr";
|
||||
s_valueOperatorTypes << "OperatorTypeEquals" << "OperatorTypeNotEquals" << "OperatorTypeLess" << "OperatorTypeGreater" << "OperatorTypeLessThan" << "OperatorTypeGreaterThan";
|
||||
s_createMethodTypes << "CreateMethodUser" << "CreateMethodAuto" << "CreateMethodDiscovery";
|
||||
s_setupMethodTypes << "SetupMethodJustAdd" << "SetupMethodDisplayPin" << "SetupMethodEnterPin" << "SetupMethodPushButton";
|
||||
s_removePolicyTypes << "RemovePolicyCascade" << "RemovePolicyUpdate";
|
||||
s_basicTypes = enumToStrings(JsonTypes::staticMetaObject, "BasicTypes");
|
||||
s_stateOperatorTypes = enumToStrings(Types::staticMetaObject, "StateOperator");
|
||||
s_valueOperatorTypes = enumToStrings(Types::staticMetaObject, "ValueOperator");
|
||||
s_createMethodTypes = enumToStrings(DeviceClass::staticMetaObject, "CreateMethod");
|
||||
s_setupMethodTypes = enumToStrings(DeviceClass::staticMetaObject, "SetupMethod");
|
||||
s_removePolicyTypes = enumToStrings(RuleEngine::staticMetaObject, "RemovePolicy");
|
||||
s_deviceErrorTypes = enumToStrings(DeviceManager::staticMetaObject, "DeviceError");
|
||||
s_ruleErrorTypes = enumToStrings(RuleEngine::staticMetaObject, "RuleError");
|
||||
|
||||
// ParamType
|
||||
s_paramType.insert("name", "string");
|
||||
@ -174,6 +181,19 @@ QPair<bool, QString> JsonTypes::report(bool status, const QString &message)
|
||||
return qMakePair<bool, QString>(status, message);
|
||||
}
|
||||
|
||||
QVariantList JsonTypes::enumToStrings(const QMetaObject &metaObject, const QString &enumName)
|
||||
{
|
||||
int enumIndex = metaObject.indexOfEnumerator(enumName.toLatin1().data());
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
|
||||
|
||||
qDebug() << "*** have enum" << metaEnum.name();
|
||||
QVariantList enumStrings;
|
||||
for (int i = 0; i < metaEnum.keyCount(); i++) {
|
||||
enumStrings << metaEnum.valueToKey(metaEnum.value(i));
|
||||
}
|
||||
return enumStrings;
|
||||
}
|
||||
|
||||
QVariantMap JsonTypes::allTypes()
|
||||
{
|
||||
QVariantMap allTypes;
|
||||
@ -184,6 +204,8 @@ QVariantMap JsonTypes::allTypes()
|
||||
allTypes.insert("ValueOperatorType", valueOperatorTypes());
|
||||
allTypes.insert("StateOperatorType", stateOperatorTypes());
|
||||
allTypes.insert("RemovePolicyType", removePolicyTypes());
|
||||
allTypes.insert("DeviceError", deviceErrorTypes());
|
||||
allTypes.insert("RuleError", ruleErrorTypes());
|
||||
allTypes.insert("StateType", stateTypeDescription());
|
||||
allTypes.insert("StateDescriptor", stateDescriptorDescription());
|
||||
allTypes.insert("StateEvaluator", stateEvaluatorDescription());
|
||||
@ -474,19 +496,11 @@ ParamDescriptor JsonTypes::unpackParamDescriptor(const QVariantMap ¶mMap)
|
||||
{
|
||||
ParamDescriptor param(paramMap.value("name").toString(), paramMap.value("value"));
|
||||
QString operatorString = paramMap.value("operator").toString();
|
||||
if (operatorString == "ValueOperatorEquals") {
|
||||
param.setOperatorType(ValueOperatorEquals);
|
||||
} else if (operatorString == "ValueOperatorNotEquals") {
|
||||
param.setOperatorType(ValueOperatorNotEquals);
|
||||
} else if (operatorString == "ValueOperatorLess") {
|
||||
param.setOperatorType(ValueOperatorLess);
|
||||
} else if (operatorString == "ValueOperatorGreater") {
|
||||
param.setOperatorType(ValueOperatorGreater);
|
||||
} else if (operatorString == "ValueOperatorLessOrEqual") {
|
||||
param.setOperatorType(ValueOperatorLessOrEqual);
|
||||
} else if (operatorString == "ValueOperatorGreaterOrEqual") {
|
||||
param.setOperatorType(ValueOperatorGreaterOrEqual);
|
||||
}
|
||||
|
||||
QMetaObject metaObject = Types::staticMetaObject;
|
||||
int enumIndex = metaObject.indexOfEnumerator("ValueOperator");
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
|
||||
param.setOperatorType((Types::ValueOperator)metaEnum.keyToValue(operatorString.toLatin1().data()));
|
||||
return param;
|
||||
}
|
||||
|
||||
@ -511,6 +525,7 @@ EventDescriptor JsonTypes::unpackEventDescriptor(const QVariantMap &eventDescrip
|
||||
QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, const QVariantMap &map)
|
||||
{
|
||||
s_lastError.clear();
|
||||
qDebug() << "validating Map" << templateMap << map;
|
||||
|
||||
// Make sure all values defined in the template are around
|
||||
foreach (const QString &key, templateMap.keys()) {
|
||||
@ -548,7 +563,7 @@ QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, cons
|
||||
|
||||
QPair<bool, QString> JsonTypes::validateProperty(const QVariant &templateValue, const QVariant &value)
|
||||
{
|
||||
// qDebug() << "validating property. template:" << templateValue << "got:" << value;
|
||||
qDebug() << "validating property. template:" << templateValue << "got:" << value;
|
||||
QString strippedTemplateValue = templateValue.toString();
|
||||
|
||||
if (strippedTemplateValue == "variant") {
|
||||
@ -566,6 +581,10 @@ QPair<bool, QString> JsonTypes::validateProperty(const QVariant &templateValue,
|
||||
QString errorString = QString("Param %1 is not a bool.").arg(value.toString());
|
||||
return report(value.canConvert(QVariant::Bool), errorString);
|
||||
}
|
||||
if (strippedTemplateValue == "int") {
|
||||
QString errorString = QString("Param %1 is not a int.").arg(value.toString());
|
||||
return report(value.canConvert(QVariant::Int), errorString);
|
||||
}
|
||||
qWarning() << QString("Unhandled property type: %1 (expected: %2)").arg(value.toString()).arg(strippedTemplateValue);
|
||||
QString errorString = QString("Unhandled property type: %1 (expected: %2)").arg(value.toString()).arg(strippedTemplateValue);
|
||||
return report(false, errorString);
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
#include "plugin/deviceclass.h"
|
||||
#include "plugin/devicedescriptor.h"
|
||||
#include "rule.h"
|
||||
#include "devicemanager.h"
|
||||
#include "ruleengine.h"
|
||||
|
||||
#include "types/event.h"
|
||||
#include "types/action.h"
|
||||
@ -33,6 +35,7 @@
|
||||
|
||||
#include <QVariantMap>
|
||||
#include <QString>
|
||||
#include <QMetaEnum>
|
||||
|
||||
class DevicePlugin;
|
||||
class Device;
|
||||
@ -48,28 +51,47 @@ class Device;
|
||||
static QVariantMap s_##typeName; \
|
||||
public:
|
||||
|
||||
#define DECLARE_TYPE(typeName, jsonName) \
|
||||
#define DECLARE_TYPE(typeName, enumString, className, enumName) \
|
||||
public: \
|
||||
static QString typeName##Ref() { return QStringLiteral("$ref:") + QStringLiteral(jsonName); } \
|
||||
static QString typeName##Ref() { return QStringLiteral("$ref:") + QStringLiteral(enumString); } \
|
||||
static QVariantList typeName() { \
|
||||
if (!s_initialized) { init(); } \
|
||||
return s_##typeName; \
|
||||
} \
|
||||
static QString typeName##ToString(className::enumName value) { \
|
||||
QMetaObject metaObject = className::staticMetaObject; \
|
||||
int enumIndex = metaObject.indexOfEnumerator(enumString); \
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex); \
|
||||
return metaEnum.valueToKey(metaEnum.value(value)); \
|
||||
} \
|
||||
private: \
|
||||
static QVariantList s_##typeName; \
|
||||
public:
|
||||
|
||||
class JsonTypes
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(BasicTypes)
|
||||
public:
|
||||
enum BasicTypes {
|
||||
Uuid,
|
||||
String,
|
||||
Int,
|
||||
Double,
|
||||
Bool
|
||||
};
|
||||
|
||||
|
||||
static QVariantMap allTypes();
|
||||
|
||||
DECLARE_TYPE(basicTypes, "BasicType")
|
||||
DECLARE_TYPE(stateOperatorTypes, "StateOperatorType")
|
||||
DECLARE_TYPE(valueOperatorTypes, "ValueOperatorType")
|
||||
DECLARE_TYPE(createMethodTypes, "CreateMethodType")
|
||||
DECLARE_TYPE(setupMethodTypes, "SetupMethodType")
|
||||
DECLARE_TYPE(removePolicyTypes, "RemovePolicyType")
|
||||
DECLARE_TYPE(basicTypes, "BasicType", JsonTypes, BasicTypes)
|
||||
DECLARE_TYPE(stateOperatorTypes, "StateOperator", Types, StateOperator)
|
||||
DECLARE_TYPE(valueOperatorTypes, "ValueOperator", Types, ValueOperator)
|
||||
DECLARE_TYPE(createMethodTypes, "CreateMethod", DeviceClass, CreateMethod)
|
||||
DECLARE_TYPE(setupMethodTypes, "SetupMethod", DeviceClass, SetupMethod)
|
||||
DECLARE_TYPE(deviceErrorTypes, "DeviceError", DeviceManager, DeviceError)
|
||||
DECLARE_TYPE(removePolicyTypes, "RemovePolicy", RuleEngine, RemovePolicy)
|
||||
DECLARE_TYPE(ruleErrorTypes, "RuleError", RuleEngine, RuleError)
|
||||
DECLARE_OBJECT(paramType, "ParamType")
|
||||
DECLARE_OBJECT(param, "Param")
|
||||
DECLARE_OBJECT(paramDescriptor, "ParamDescriptor")
|
||||
@ -124,11 +146,13 @@ public:
|
||||
static QPair<bool, QString> validateSetupMethodType(const QVariant &variant);
|
||||
static QPair<bool, QString> validateValueOperatorType(const QVariant &variant);
|
||||
|
||||
|
||||
private:
|
||||
static bool s_initialized;
|
||||
static void init();
|
||||
|
||||
static QPair<bool, QString> report(bool status, const QString &message);
|
||||
static QVariantList enumToStrings(const QMetaObject &metaObject, const QString &enumName);
|
||||
|
||||
static QString s_lastError;
|
||||
};
|
||||
|
||||
@ -43,7 +43,8 @@ RulesHandler::RulesHandler(QObject *parent) :
|
||||
setReturns("GetRuleDetails", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("AddRule", "Add a rule.");
|
||||
setDescription("AddRule", "Add a rule. You can describe rules by one or many EventDesciptors and a StateEvaluator. Note that only"
|
||||
"one of either eventDescriptor or eventDescriptorList may be passed at a time.");
|
||||
params.insert("o:eventDescriptor", JsonTypes::eventDescriptorRef());
|
||||
params.insert("o:eventDescriptorList", QVariantList() << JsonTypes::eventDescriptorRef());
|
||||
params.insert("o:stateEvaluator", JsonTypes::stateEvaluatorRef());
|
||||
@ -51,8 +52,7 @@ RulesHandler::RulesHandler(QObject *parent) :
|
||||
actions.append(JsonTypes::actionRef());
|
||||
params.insert("actions", actions);
|
||||
setParams("AddRule", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("ruleError", "int");
|
||||
returns.insert("o:ruleId", "uuid");
|
||||
setReturns("AddRule", returns);
|
||||
|
||||
@ -60,8 +60,7 @@ RulesHandler::RulesHandler(QObject *parent) :
|
||||
setDescription("RemoveRule", "Remove a rule");
|
||||
params.insert("ruleId", "uuid");
|
||||
setParams("RemoveRule", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
returns.insert("ruleError", "int");
|
||||
setReturns("RemoveRule", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
@ -106,8 +105,8 @@ JsonReply* RulesHandler::AddRule(const QVariantMap ¶ms)
|
||||
{
|
||||
if (params.contains("eventDescriptor") && params.contains("eventDescriptorList")) {
|
||||
QVariantMap returns;
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "Only one of \"eventDescriptor\" and \"eventDescriptorList\" may be used.");
|
||||
qWarning() << "Only one of eventDesciptor or eventDescriptorList may be used.";
|
||||
returns.insert("ruleError", RuleEngine::RuleErrorInvalidParameter);
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -133,30 +132,16 @@ JsonReply* RulesHandler::AddRule(const QVariantMap ¶ms)
|
||||
|
||||
QVariantMap returns;
|
||||
if (actions.count() == 0) {
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "Missing parameter: \"actions\".");
|
||||
returns.insert("ruleErorr", RuleEngine::RuleErrorMissingParameter);
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
RuleId newRuleId = RuleId::createRuleId();
|
||||
switch(GuhCore::instance()->addRule(newRuleId, eventDescriptorList, actions)) {
|
||||
case RuleEngine::RuleErrorNoError:
|
||||
returns.insert("success", true);
|
||||
returns.insert("errorMessage", "");
|
||||
RuleEngine::RuleError status = GuhCore::instance()->addRule(newRuleId, eventDescriptorList, actions);
|
||||
if (status == RuleEngine::RuleErrorNoError) {
|
||||
returns.insert("ruleId", newRuleId.toString());
|
||||
break;
|
||||
case RuleEngine::RuleErrorDeviceNotFound:
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "No such device.");
|
||||
break;
|
||||
case RuleEngine::RuleErrorEventTypeNotFound:
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "Device does not have such a event type.");
|
||||
break;
|
||||
default:
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "Unknown error");
|
||||
}
|
||||
returns.insert("ruleError", status);
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -164,19 +149,8 @@ JsonReply* RulesHandler::RemoveRule(const QVariantMap ¶ms)
|
||||
{
|
||||
QVariantMap returns;
|
||||
RuleId ruleId(params.value("ruleId").toString());
|
||||
switch (GuhCore::instance()->removeRule(ruleId)) {
|
||||
case RuleEngine::RuleErrorNoError:
|
||||
returns.insert("success", true);
|
||||
returns.insert("errorMessage", "");
|
||||
break;
|
||||
case RuleEngine::RuleErrorRuleNotFound:
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "No such rule.");
|
||||
break;
|
||||
default:
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "Unknown error");
|
||||
}
|
||||
RuleEngine::RuleError status = GuhCore::instance()->removeRule(ruleId);
|
||||
returns.insert("ruleError", status);
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ RuleEngine::RuleEngine(QObject *parent) :
|
||||
if (groupName.startsWith("ParamDescriptor-")) {
|
||||
settings.beginGroup(groupName);
|
||||
ParamDescriptor paramDescriptor(groupName.remove(QRegExp("^ParamDescriptor-")), settings.value("value"));
|
||||
paramDescriptor.setOperatorType((ValueOperator)settings.value("operator").toInt());
|
||||
paramDescriptor.setOperatorType((Types::ValueOperator)settings.value("operator").toInt());
|
||||
params.append(paramDescriptor);
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
@ -30,6 +30,8 @@
|
||||
class RuleEngine : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(RuleError)
|
||||
Q_ENUMS(RemovePolicy)
|
||||
public:
|
||||
enum RuleError {
|
||||
RuleErrorNoError,
|
||||
@ -37,7 +39,9 @@ public:
|
||||
RuleErrorRuleNotFound,
|
||||
RuleErrorDeviceNotFound,
|
||||
RuleErrorEventTypeNotFound,
|
||||
RuleErrorActionTypeNotFound
|
||||
RuleErrorActionTypeNotFound,
|
||||
RuleErrorInvalidParameter,
|
||||
RuleErrorMissingParameter
|
||||
};
|
||||
|
||||
enum RemovePolicy {
|
||||
@ -75,5 +79,6 @@ private:
|
||||
QList<RuleId> m_ruleIds; // Keeping a list of RuleIds to keep sorting order...
|
||||
QHash<RuleId, Rule> m_rules; // ...but use a Hash for faster finding
|
||||
};
|
||||
Q_DECLARE_METATYPE(RuleEngine::RuleError)
|
||||
|
||||
#endif // RULEENGINE_H
|
||||
|
||||
@ -23,3 +23,4 @@ HEADERS += $$top_srcdir/server/guhcore.h \
|
||||
$$top_srcdir/server/jsonrpc/actionhandler.h \
|
||||
$$top_srcdir/server/jsonrpc/eventhandler.h \
|
||||
$$top_srcdir/server/stateevaluator.h \
|
||||
$$top_srcdir/server/jsontypes.h
|
||||
|
||||
@ -22,12 +22,12 @@
|
||||
|
||||
StateEvaluator::StateEvaluator(const StateDescriptor &stateDescriptor):
|
||||
m_stateDescriptor(stateDescriptor),
|
||||
m_operatorType(StateOperatorAnd)
|
||||
m_operatorType(Types::StateOperatorAnd)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
StateEvaluator::StateEvaluator(QList<StateEvaluator> childEvaluators, StateOperator stateOperator):
|
||||
StateEvaluator::StateEvaluator(QList<StateEvaluator> childEvaluators, Types::StateOperator stateOperator):
|
||||
m_stateDescriptor(),
|
||||
m_childEvaluators(childEvaluators),
|
||||
m_operatorType(stateOperator)
|
||||
@ -54,12 +54,12 @@ void StateEvaluator::appendEvaluator(const StateEvaluator &stateEvaluator)
|
||||
m_childEvaluators.append(stateEvaluator);
|
||||
}
|
||||
|
||||
StateOperator StateEvaluator::operatorType() const
|
||||
Types::StateOperator StateEvaluator::operatorType() const
|
||||
{
|
||||
return m_operatorType;
|
||||
}
|
||||
|
||||
void StateEvaluator::setOperatorType(StateOperator operatorType)
|
||||
void StateEvaluator::setOperatorType(Types::StateOperator operatorType)
|
||||
{
|
||||
m_operatorType = operatorType;
|
||||
}
|
||||
@ -82,7 +82,7 @@ bool StateEvaluator::evaluate() const
|
||||
}
|
||||
}
|
||||
|
||||
if (m_operatorType == StateOperatorOr) {
|
||||
if (m_operatorType == Types::StateOperatorOr) {
|
||||
foreach (const StateEvaluator &stateEvaluator, m_childEvaluators) {
|
||||
if (stateEvaluator.evaluate()) {
|
||||
return true;
|
||||
@ -151,13 +151,13 @@ StateEvaluator StateEvaluator::loadFromSettings(QSettings &settings, const QStri
|
||||
StateTypeId stateTypeId(settings.value("stateTypeId").toString());
|
||||
DeviceId deviceId(settings.value("deviceId").toString());
|
||||
QVariant stateValue = settings.value("value");
|
||||
ValueOperator valueOperator = (ValueOperator)settings.value("operator").toInt();
|
||||
Types::ValueOperator valueOperator = (Types::ValueOperator)settings.value("operator").toInt();
|
||||
StateDescriptor stateDescriptor(stateTypeId, deviceId, stateValue, valueOperator);
|
||||
settings.endGroup();
|
||||
|
||||
StateEvaluator ret(stateDescriptor);
|
||||
|
||||
ret.setOperatorType((StateOperator)settings.value("operator").toInt());
|
||||
ret.setOperatorType((Types::StateOperator)settings.value("operator").toInt());
|
||||
|
||||
settings.beginGroup("childEvaluators");
|
||||
foreach (const QString &evaluatorGroup, settings.childGroups()) {
|
||||
|
||||
@ -27,13 +27,8 @@
|
||||
class StateEvaluator
|
||||
{
|
||||
public:
|
||||
enum OperatorType {
|
||||
OperatorTypeAnd,
|
||||
OperatorTypeOr
|
||||
};
|
||||
|
||||
StateEvaluator(const StateDescriptor &stateDescriptor);
|
||||
StateEvaluator(QList<StateEvaluator> childEvaluators = QList<StateEvaluator>(), StateOperator stateOperator = StateOperatorAnd);
|
||||
StateEvaluator(QList<StateEvaluator> childEvaluators = QList<StateEvaluator>(), Types::StateOperator stateOperator = Types::StateOperatorAnd);
|
||||
|
||||
StateDescriptor stateDescriptor() const;
|
||||
|
||||
@ -41,8 +36,8 @@ public:
|
||||
void setChildEvaluators(const QList<StateEvaluator> &childEvaluators);
|
||||
void appendEvaluator(const StateEvaluator &stateEvaluator);
|
||||
|
||||
StateOperator operatorType() const;
|
||||
void setOperatorType(StateOperator operatorType);
|
||||
Types::StateOperator operatorType() const;
|
||||
void setOperatorType(Types::StateOperator operatorType);
|
||||
|
||||
bool evaluate() const;
|
||||
bool containsDevice(const DeviceId &deviceId) const;
|
||||
@ -56,7 +51,7 @@ private:
|
||||
StateDescriptor m_stateDescriptor;
|
||||
|
||||
QList<StateEvaluator> m_childEvaluators;
|
||||
StateOperator m_operatorType;
|
||||
Types::StateOperator m_operatorType;
|
||||
};
|
||||
|
||||
#endif // STATEEVALUATOR_H
|
||||
|
||||
@ -47,7 +47,7 @@ void TestActions::executeAction_data()
|
||||
QTest::addColumn<DeviceId>("deviceId");
|
||||
QTest::addColumn<ActionTypeId>("actionTypeId");
|
||||
QTest::addColumn<QVariantList>("actionParams");
|
||||
QTest::addColumn<bool>("success");
|
||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||
|
||||
QVariantList params;
|
||||
QVariantMap param1;
|
||||
@ -59,13 +59,13 @@ void TestActions::executeAction_data()
|
||||
param2.insert("value", true);
|
||||
params.append(param2);
|
||||
|
||||
QTest::newRow("valid action") << m_mockDeviceId << mockActionIdWithParams << params << true;
|
||||
QTest::newRow("invalid deviceId") << DeviceId::createDeviceId() << mockActionIdWithParams << params << false;
|
||||
QTest::newRow("invalid actionTypeId") << m_mockDeviceId << ActionTypeId::createActionTypeId() << params << false;
|
||||
QTest::newRow("missing params") << m_mockDeviceId << mockActionIdWithParams << QVariantList() << false;
|
||||
QTest::newRow("async action") << m_mockDeviceId << mockActionIdAsync << QVariantList() << true;
|
||||
QTest::newRow("broken action") << m_mockDeviceId << mockActionIdFailing << QVariantList() << false;
|
||||
QTest::newRow("async broken action") << m_mockDeviceId << mockActionIdAsyncFailing << QVariantList() << false;
|
||||
QTest::newRow("valid action") << m_mockDeviceId << mockActionIdWithParams << params << DeviceManager::DeviceErrorNoError;
|
||||
QTest::newRow("invalid deviceId") << DeviceId::createDeviceId() << mockActionIdWithParams << params << DeviceManager::DeviceErrorDeviceNotFound;
|
||||
QTest::newRow("invalid actionTypeId") << m_mockDeviceId << ActionTypeId::createActionTypeId() << params << DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
QTest::newRow("missing params") << m_mockDeviceId << mockActionIdWithParams << QVariantList() << DeviceManager::DeviceErrorMissingParameter;
|
||||
QTest::newRow("async action") << m_mockDeviceId << mockActionIdAsync << QVariantList() << DeviceManager::DeviceErrorNoError;
|
||||
QTest::newRow("broken action") << m_mockDeviceId << mockActionIdFailing << QVariantList() << DeviceManager::DeviceErrorActionParameterError;
|
||||
QTest::newRow("async broken action") << m_mockDeviceId << mockActionIdAsyncFailing << QVariantList() << DeviceManager::DeviceErrorActionParameterError;
|
||||
}
|
||||
|
||||
void TestActions::executeAction()
|
||||
@ -73,7 +73,7 @@ void TestActions::executeAction()
|
||||
QFETCH(DeviceId, deviceId);
|
||||
QFETCH(ActionTypeId, actionTypeId);
|
||||
QFETCH(QVariantList, actionParams);
|
||||
QFETCH(bool, success);
|
||||
QFETCH(DeviceManager::DeviceError, error);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("actionTypeId", actionTypeId);
|
||||
@ -81,7 +81,7 @@ void TestActions::executeAction()
|
||||
params.insert("params", actionParams);
|
||||
QVariant response = injectAndWait("Actions.ExecuteAction", params);
|
||||
qDebug() << "executeActionresponse" << response;
|
||||
verifySuccess(response, success);
|
||||
verifyError(response, "deviceError", error);
|
||||
|
||||
// Fetch action execution history from mock device
|
||||
QNetworkAccessManager nam;
|
||||
@ -94,7 +94,7 @@ void TestActions::executeAction()
|
||||
reply->deleteLater();
|
||||
QByteArray data = reply->readAll();
|
||||
|
||||
if (success) {
|
||||
if (error == DeviceManager::DeviceErrorNoError) {
|
||||
QVERIFY2(actionTypeId == ActionTypeId(data), QString("ActionTypeId mismatch. Got %1, Expected: %2")
|
||||
.arg(ActionTypeId(data).toString()).arg(actionTypeId.toString()).toLatin1().data());
|
||||
} else {
|
||||
@ -123,24 +123,24 @@ void TestActions::executeAction()
|
||||
void TestActions::getActionTypes_data()
|
||||
{
|
||||
QTest::addColumn<ActionTypeId>("actionTypeId");
|
||||
QTest::addColumn<bool>("success");
|
||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||
|
||||
QTest::newRow("valid actiontypeid") << mockActionIdWithParams << true;
|
||||
QTest::newRow("invalid actiontypeid") << ActionTypeId::createActionTypeId() << false;
|
||||
QTest::newRow("valid actiontypeid") << mockActionIdWithParams << DeviceManager::DeviceErrorNoError;
|
||||
QTest::newRow("invalid actiontypeid") << ActionTypeId::createActionTypeId() << DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
|
||||
void TestActions::getActionTypes()
|
||||
{
|
||||
QFETCH(ActionTypeId, actionTypeId);
|
||||
QFETCH(bool, success);
|
||||
QFETCH(DeviceManager::DeviceError, error);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("actionTypeId", actionTypeId.toString());
|
||||
QVariant response = injectAndWait("Actions.GetActionType", params);
|
||||
|
||||
verifySuccess(response, success);
|
||||
verifyError(response, "deviceError", error);
|
||||
|
||||
if (success) {
|
||||
if (error == DeviceManager::DeviceErrorNoError) {
|
||||
QVERIFY2(ActionTypeId(response.toMap().value("params").toMap().value("actionType").toMap().value("id").toString()) == actionTypeId, "Didnt get reply for same actionTypeId as requested.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,41 +84,41 @@ void TestDevices::getPlugins()
|
||||
void TestDevices::getPluginConfig_data()
|
||||
{
|
||||
QTest::addColumn<PluginId>("pluginId");
|
||||
QTest::addColumn<bool>("success");
|
||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||
|
||||
QTest::newRow("valid plugin") << mockPluginId << true;
|
||||
QTest::newRow("invalid plugin") << PluginId::createPluginId() << false;
|
||||
QTest::newRow("valid plugin") << mockPluginId << DeviceManager::DeviceErrorNoError;
|
||||
QTest::newRow("invalid plugin") << PluginId::createPluginId() << DeviceManager::DeviceErrorPluginNotFound;
|
||||
}
|
||||
|
||||
void TestDevices::getPluginConfig()
|
||||
{
|
||||
QFETCH(PluginId, pluginId);
|
||||
QFETCH(bool, success);
|
||||
QFETCH(DeviceManager::DeviceError, error);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("pluginId", pluginId);
|
||||
QVariant response = injectAndWait("Devices.GetPluginConfiguration", params);
|
||||
verifySuccess(response, success);
|
||||
verifyError(response, "deviceError", error);
|
||||
}
|
||||
|
||||
void TestDevices::setPluginConfig_data()
|
||||
{
|
||||
QTest::addColumn<PluginId>("pluginId");
|
||||
QTest::addColumn<QVariant>("value");
|
||||
QTest::addColumn<bool>("success");
|
||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||
|
||||
QTest::newRow("valid") << mockPluginId << QVariant(13) << true;
|
||||
QTest::newRow("invalid plugin") << PluginId::createPluginId() << QVariant(13) << false;
|
||||
QTest::newRow("too big") << mockPluginId << QVariant(130) << false;
|
||||
QTest::newRow("too small") << mockPluginId << QVariant(-13) << false;
|
||||
QTest::newRow("wrong type") << mockPluginId << QVariant("wrontType") << false;
|
||||
QTest::newRow("valid") << mockPluginId << QVariant(13) << DeviceManager::DeviceErrorNoError;
|
||||
QTest::newRow("invalid plugin") << PluginId::createPluginId() << QVariant(13) << DeviceManager::DeviceErrorPluginNotFound;
|
||||
QTest::newRow("too big") << mockPluginId << QVariant(130) << DeviceManager::DeviceErrorInvalidParameter;
|
||||
QTest::newRow("too small") << mockPluginId << QVariant(-13) << DeviceManager::DeviceErrorInvalidParameter;
|
||||
QTest::newRow("wrong type") << mockPluginId << QVariant("wrontType") << DeviceManager::DeviceErrorInvalidParameter;
|
||||
}
|
||||
|
||||
void TestDevices::setPluginConfig()
|
||||
{
|
||||
QFETCH(PluginId, pluginId);
|
||||
QFETCH(QVariant, value);
|
||||
QFETCH(bool, success);
|
||||
QFETCH(DeviceManager::DeviceError, error);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("pluginId", pluginId);
|
||||
@ -130,13 +130,13 @@ void TestDevices::setPluginConfig()
|
||||
configuration.append(configParam);
|
||||
params.insert("configuration", configuration);
|
||||
QVariant response = injectAndWait("Devices.SetPluginConfiguration", params);
|
||||
verifySuccess(response, success);
|
||||
verifyError(response, "deviceError", error);
|
||||
|
||||
if (success) {
|
||||
if (error == DeviceManager::DeviceErrorNoError) {
|
||||
params.clear();
|
||||
params.insert("pluginId", pluginId);
|
||||
response = injectAndWait("Devices.GetPluginConfiguration", params);
|
||||
verifySuccess(response);
|
||||
verifyError(response, "deviceError");
|
||||
qDebug() << "222" << response.toMap().value("params").toMap().value("configuration").toList().first();
|
||||
QVERIFY2(response.toMap().value("params").toMap().value("configuration").toList().first().toMap().value("name") == "configParamInt", "Value not set correctly");
|
||||
QVERIFY2(response.toMap().value("params").toMap().value("configuration").toList().first().toMap().value("value") == value, "Value not set correctly");
|
||||
@ -250,14 +250,14 @@ void TestDevices::addConfiguredDevice()
|
||||
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
qDebug() << "response is" << response;
|
||||
|
||||
verifySuccess(response, success);
|
||||
verifyError(response, "deviceError", success);
|
||||
|
||||
if (success) {
|
||||
QUuid deviceId(response.toMap().value("params").toMap().value("deviceId").toString());
|
||||
params.clear();
|
||||
params.insert("deviceId", deviceId.toString());
|
||||
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
verifySuccess(response);
|
||||
verifyError(response, "deviceError");
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,7 +296,7 @@ void TestDevices::removeDevice()
|
||||
|
||||
QVariant response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
|
||||
verifySuccess(response, success);
|
||||
verifyError(response, "deviceError", success);
|
||||
|
||||
if (success) {
|
||||
// Make sure the device is gone from settings too
|
||||
@ -323,7 +323,7 @@ void TestDevices::storedDevices()
|
||||
deviceParams.append(httpportParam);
|
||||
params.insert("deviceParams", deviceParams);
|
||||
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
verifySuccess(response);
|
||||
verifyError(response, "deviceError");
|
||||
DeviceId addedDeviceId = DeviceId(response.toMap().value("params").toMap().value("deviceId").toString());
|
||||
QVERIFY(!addedDeviceId.isNull());
|
||||
|
||||
@ -352,14 +352,14 @@ void TestDevices::storedDevices()
|
||||
params.clear();
|
||||
params.insert("deviceId", addedDeviceId);
|
||||
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
verifySuccess(response);
|
||||
verifyError(response, "deviceError");
|
||||
}
|
||||
|
||||
void TestDevices::discoverDevices_data()
|
||||
{
|
||||
QTest::addColumn<DeviceClassId>("deviceClassId");
|
||||
QTest::addColumn<int>("resultCount");
|
||||
QTest::addColumn<bool>("success");
|
||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||
QTest::addColumn<QVariantList>("discoveryParams");
|
||||
|
||||
QVariantList discoveryParams;
|
||||
@ -368,16 +368,16 @@ void TestDevices::discoverDevices_data()
|
||||
resultCountParam.insert("value", 1);
|
||||
discoveryParams.append(resultCountParam);
|
||||
|
||||
QTest::newRow("valid deviceClassId") << mockDeviceClassId << 2 << true << QVariantList();
|
||||
QTest::newRow("valid deviceClassId with params") << mockDeviceClassId << 1 << true << discoveryParams;
|
||||
QTest::newRow("invalid deviceClassId") << DeviceClassId::createDeviceClassId() << 0 << false << QVariantList();
|
||||
QTest::newRow("valid deviceClassId") << mockDeviceClassId << 2 << DeviceManager::DeviceErrorNoError << QVariantList();
|
||||
QTest::newRow("valid deviceClassId with params") << mockDeviceClassId << 1 << DeviceManager::DeviceErrorNoError << discoveryParams;
|
||||
QTest::newRow("invalid deviceClassId") << DeviceClassId::createDeviceClassId() << 0 << DeviceManager::DeviceErrorDeviceClassNotFound << QVariantList();
|
||||
}
|
||||
|
||||
void TestDevices::discoverDevices()
|
||||
{
|
||||
QFETCH(DeviceClassId, deviceClassId);
|
||||
QFETCH(int, resultCount);
|
||||
QFETCH(bool, success);
|
||||
QFETCH(DeviceManager::DeviceError, error);
|
||||
QFETCH(QVariantList, discoveryParams);
|
||||
|
||||
QVariantMap params;
|
||||
@ -385,13 +385,13 @@ void TestDevices::discoverDevices()
|
||||
params.insert("discoveryParams", discoveryParams);
|
||||
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
|
||||
|
||||
verifySuccess(response, success);
|
||||
if (success) {
|
||||
verifyError(response, "deviceError", error);
|
||||
if (error == DeviceManager::DeviceErrorNoError) {
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("deviceDescriptors").toList().count(), resultCount);
|
||||
}
|
||||
|
||||
// If we found something, lets try to add it
|
||||
if (success) {
|
||||
if (DeviceManager::DeviceErrorNoError) {
|
||||
DeviceDescriptorId descriptorId = DeviceDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString());
|
||||
|
||||
params.clear();
|
||||
@ -399,13 +399,13 @@ void TestDevices::discoverDevices()
|
||||
params.insert("deviceDescriptorId", descriptorId.toString());
|
||||
response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
|
||||
verifySuccess(response);
|
||||
verifyError(response, "deviceError");
|
||||
|
||||
DeviceId deviceId(response.toMap().value("params").toMap().value("deviceId").toString());
|
||||
params.clear();
|
||||
params.insert("deviceId", deviceId.toString());
|
||||
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
verifySuccess(response);
|
||||
verifyError(response, "deviceError");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -91,7 +91,7 @@ void GuhTestBase::initTestCase()
|
||||
|
||||
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
|
||||
verifySuccess(response);
|
||||
verifyError(response, "deviceError");
|
||||
|
||||
m_mockDeviceId = DeviceId(response.toMap().value("params").toMap().value("deviceId").toString());
|
||||
QVERIFY2(!m_mockDeviceId.isNull(), "Newly created mock device must not be null.");
|
||||
@ -125,11 +125,11 @@ QVariant GuhTestBase::injectAndWait(const QString &method, const QVariantMap &pa
|
||||
return jsonDoc.toVariant();
|
||||
}
|
||||
|
||||
void GuhTestBase::verifySuccess(const QVariant &response, bool success)
|
||||
void GuhTestBase::verifyError(const QVariant &response, const QString &fieldName, int error)
|
||||
{
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(response);
|
||||
QVERIFY2(response.toMap().value("status").toString() == QString("success"), jsonDoc.toJson().data());
|
||||
QVERIFY2(response.toMap().value("params").toMap().value("success").toBool() == success, jsonDoc.toJson().data());
|
||||
QVERIFY2(response.toMap().value("params").toMap().value(fieldName).toInt() == error, jsonDoc.toJson().data());
|
||||
}
|
||||
|
||||
void GuhTestBase::restartServer()
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
|
||||
#include "typeutils.h"
|
||||
#include "mocktcpserver.h"
|
||||
#include "devicemanager.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QUuid>
|
||||
@ -57,7 +58,7 @@ protected slots:
|
||||
|
||||
protected:
|
||||
QVariant injectAndWait(const QString &method, const QVariantMap ¶ms = QVariantMap());
|
||||
void verifySuccess(const QVariant &response, bool success = true);
|
||||
void verifyError(const QVariant &response, const QString &fieldName, int error = 0);
|
||||
void restartServer();
|
||||
|
||||
protected:
|
||||
|
||||
@ -181,7 +181,7 @@ void TestJSONRPC::enableDisableNotifications()
|
||||
params.insert("enabled", enabled);
|
||||
QVariant response = injectAndWait("JSONRPC.SetNotificationStatus", params);
|
||||
|
||||
verifySuccess(response);
|
||||
verifyError(response, "error");
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("enabled").toString(), enabled);
|
||||
|
||||
}
|
||||
@ -191,7 +191,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
QVariantMap params;
|
||||
params.insert("enabled", true);
|
||||
QVariant response = injectAndWait("JSONRPC.SetNotificationStatus", params);
|
||||
verifySuccess(response);
|
||||
verifyError(response, "serverError");
|
||||
|
||||
// Setup connection to mock client
|
||||
QNetworkAccessManager nam;
|
||||
@ -226,7 +226,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
params.clear();
|
||||
params.insert("enabled", false);
|
||||
response = injectAndWait("JSONRPC.SetNotificationStatus", params);
|
||||
verifySuccess(response);
|
||||
verifyError(response, "serverError");
|
||||
|
||||
// Fire the a statechange once again
|
||||
clientSpy.clear();
|
||||
|
||||
@ -104,14 +104,14 @@ void TestRules::addRemoveRules_data()
|
||||
QTest::addColumn<QVariantMap>("eventDescriptor");
|
||||
QTest::addColumn<QVariantList>("eventDescriptorList");
|
||||
QTest::addColumn<QVariantMap>("stateEvaluator");
|
||||
QTest::addColumn<bool>("success");
|
||||
QTest::addColumn<RuleEngine::RuleError>("error");
|
||||
|
||||
|
||||
QTest::newRow("valid rule. 1 EventDescriptor, StateEvaluator, 1 Action") << validActionNoParams << validEventDescriptor1 << QVariantList() << validStateEvaluator << true;
|
||||
QTest::newRow("valid rule. 2 EventDescriptors, 1 Action") << validActionNoParams << QVariantMap() << eventDescriptorList << validStateEvaluator << true;
|
||||
QTest::newRow("invalid rule: eventDescriptor and eventDescriptorList used") << validActionNoParams << validEventDescriptor1 << eventDescriptorList << validStateEvaluator << false;
|
||||
QTest::newRow("invalid action") << invalidAction << validEventDescriptor1 << QVariantList() << validStateEvaluator << false;
|
||||
QTest::newRow("invalid event descriptor") << validActionNoParams << invalidEventDescriptor << QVariantList() << validStateEvaluator << false;
|
||||
QTest::newRow("valid rule. 1 EventDescriptor, StateEvaluator, 1 Action") << validActionNoParams << validEventDescriptor1 << QVariantList() << validStateEvaluator << RuleEngine::RuleErrorNoError;
|
||||
QTest::newRow("valid rule. 2 EventDescriptors, 1 Action") << validActionNoParams << QVariantMap() << eventDescriptorList << validStateEvaluator << RuleEngine::RuleErrorNoError;
|
||||
QTest::newRow("invalid rule: eventDescriptor and eventDescriptorList used") << validActionNoParams << validEventDescriptor1 << eventDescriptorList << validStateEvaluator << RuleEngine::RuleErrorInvalidParameter;
|
||||
QTest::newRow("invalid action") << invalidAction << validEventDescriptor1 << QVariantList() << validStateEvaluator << RuleEngine::RuleErrorActionTypeNotFound;
|
||||
QTest::newRow("invalid event descriptor") << validActionNoParams << invalidEventDescriptor << QVariantList() << validStateEvaluator << RuleEngine::RuleErrorInvalidParameter;
|
||||
// QTest::newRow("invalid state evaluator") << validActionNoParams << invalidEventDescriptor << QVariantList() << invalidStateEvaluator << false;
|
||||
|
||||
}
|
||||
@ -122,7 +122,7 @@ void TestRules::addRemoveRules()
|
||||
QFETCH(QVariantMap, eventDescriptor);
|
||||
QFETCH(QVariantList, eventDescriptorList);
|
||||
QFETCH(QVariantMap, stateEvaluator);
|
||||
QFETCH(bool, success);
|
||||
QFETCH(RuleEngine::RuleError, error);
|
||||
|
||||
QVariantMap params;
|
||||
QVariantList actions;
|
||||
@ -137,14 +137,14 @@ void TestRules::addRemoveRules()
|
||||
}
|
||||
params.insert("stateEvaluator", stateEvaluator);
|
||||
QVariant response = injectAndWait("Rules.AddRule", params);
|
||||
verifySuccess(response, success);
|
||||
verifyError(response, "ruleError", error);
|
||||
|
||||
RuleId newRuleId = RuleId(response.toMap().value("params").toMap().value("ruleId").toString());
|
||||
|
||||
response = injectAndWait("Rules.GetRules");
|
||||
QVariantList rules = response.toMap().value("params").toMap().value("ruleIds").toList();
|
||||
|
||||
if (!success) {
|
||||
if (error != RuleEngine::RuleErrorNoError) {
|
||||
QVERIFY2(rules.count() == 0, "There should be no rules.");
|
||||
return;
|
||||
}
|
||||
@ -185,7 +185,7 @@ void TestRules::addRemoveRules()
|
||||
params.clear();
|
||||
params.insert("ruleId", newRuleId);
|
||||
response = injectAndWait("Rules.RemoveRule", params);
|
||||
verifySuccess(response, true);
|
||||
verifyError(response, "ruleError");
|
||||
|
||||
response = injectAndWait("Rules.GetRules");
|
||||
rules = response.toMap().value("params").toMap().value("rules").toList();
|
||||
@ -197,7 +197,7 @@ void TestRules::removeInvalidRule()
|
||||
QVariantMap params;
|
||||
params.insert("ruleId", RuleId::createRuleId());
|
||||
QVariant response = injectAndWait("Rules.RemoveRule", params);
|
||||
verifySuccess(response, false);
|
||||
verifyError(response, "ruleError", RuleEngine::RuleErrorInvalidRuleId);
|
||||
}
|
||||
|
||||
void TestRules::loadStoreConfig()
|
||||
@ -253,7 +253,7 @@ void TestRules::loadStoreConfig()
|
||||
QVariant response = injectAndWait("Rules.AddRule", params);
|
||||
|
||||
RuleId newRuleId = RuleId(response.toMap().value("params").toMap().value("ruleId").toString());
|
||||
verifySuccess(response, true);
|
||||
verifyError(response, "ruleError");
|
||||
|
||||
restartServer();
|
||||
|
||||
@ -302,7 +302,7 @@ void TestRules::loadStoreConfig()
|
||||
params.clear();
|
||||
params.insert("ruleId", newRuleId);
|
||||
response = injectAndWait("Rules.RemoveRule", params);
|
||||
verifySuccess(response, true);
|
||||
verifyError(response, "ruleError");
|
||||
|
||||
restartServer();
|
||||
|
||||
@ -329,7 +329,7 @@ void TestRules::evaluateEvent()
|
||||
actions.append(action);
|
||||
addRuleParams.insert("actions", actions);
|
||||
QVariant response = injectAndWait("Rules.AddRule", addRuleParams);
|
||||
verifySuccess(response, true);
|
||||
verifyError(response, "ruleError");
|
||||
|
||||
// Trigger an event
|
||||
QNetworkAccessManager nam;
|
||||
@ -360,29 +360,29 @@ void TestRules::testStateEvaluator_data()
|
||||
QTest::addColumn<DeviceId>("deviceId");
|
||||
QTest::addColumn<StateTypeId>("stateTypeId");
|
||||
QTest::addColumn<QVariant>("value");
|
||||
QTest::addColumn<ValueOperator>("operatorType");
|
||||
QTest::addColumn<Types::ValueOperator>("operatorType");
|
||||
QTest::addColumn<bool>("shouldMatch");
|
||||
|
||||
QTest::newRow("invalid stateId") << m_mockDeviceId << StateTypeId::createStateTypeId() << QVariant(10) << ValueOperatorEquals << false;
|
||||
QTest::newRow("invalid deviceId") << DeviceId::createDeviceId() << mockIntStateId << QVariant(10) << ValueOperatorEquals << false;
|
||||
QTest::newRow("invalid stateId") << m_mockDeviceId << StateTypeId::createStateTypeId() << QVariant(10) << Types::ValueOperatorEquals << false;
|
||||
QTest::newRow("invalid deviceId") << DeviceId::createDeviceId() << mockIntStateId << QVariant(10) << Types::ValueOperatorEquals << false;
|
||||
|
||||
QTest::newRow("equals, not matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << ValueOperatorEquals << false;
|
||||
QTest::newRow("equals, matching") << m_mockDeviceId << mockIntStateId << QVariant(10) << ValueOperatorEquals << true;
|
||||
QTest::newRow("equals, not matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << Types::ValueOperatorEquals << false;
|
||||
QTest::newRow("equals, matching") << m_mockDeviceId << mockIntStateId << QVariant(10) << Types::ValueOperatorEquals << true;
|
||||
|
||||
QTest::newRow("not equal, not matching") << m_mockDeviceId << mockIntStateId << QVariant(10) << ValueOperatorNotEquals << false;
|
||||
QTest::newRow("not equal, matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << ValueOperatorNotEquals << true;
|
||||
QTest::newRow("not equal, not matching") << m_mockDeviceId << mockIntStateId << QVariant(10) << Types::ValueOperatorNotEquals << false;
|
||||
QTest::newRow("not equal, matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << Types::ValueOperatorNotEquals << true;
|
||||
|
||||
QTest::newRow("Greater, not matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << ValueOperatorGreater << false;
|
||||
QTest::newRow("Greater, matching") << m_mockDeviceId << mockIntStateId << QVariant(2) << ValueOperatorGreater << true;
|
||||
QTest::newRow("GreaterOrEqual, not matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << ValueOperatorGreaterOrEqual << false;
|
||||
QTest::newRow("GreaterOrEqual, matching (greater)") << m_mockDeviceId << mockIntStateId << QVariant(2) << ValueOperatorGreaterOrEqual << true;
|
||||
QTest::newRow("GreaterOrEqual, matching (equals)") << m_mockDeviceId << mockIntStateId << QVariant(10) << ValueOperatorGreaterOrEqual << true;
|
||||
QTest::newRow("Greater, not matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << Types::ValueOperatorGreater << false;
|
||||
QTest::newRow("Greater, matching") << m_mockDeviceId << mockIntStateId << QVariant(2) << Types::ValueOperatorGreater << true;
|
||||
QTest::newRow("GreaterOrEqual, not matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << Types::ValueOperatorGreaterOrEqual << false;
|
||||
QTest::newRow("GreaterOrEqual, matching (greater)") << m_mockDeviceId << mockIntStateId << QVariant(2) << Types::ValueOperatorGreaterOrEqual << true;
|
||||
QTest::newRow("GreaterOrEqual, matching (equals)") << m_mockDeviceId << mockIntStateId << QVariant(10) << Types::ValueOperatorGreaterOrEqual << true;
|
||||
|
||||
QTest::newRow("Less, not matching") << m_mockDeviceId << mockIntStateId << QVariant(2) << ValueOperatorLess << false;
|
||||
QTest::newRow("Less, matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << ValueOperatorLess << true;
|
||||
QTest::newRow("LessOrEqual, not matching") << m_mockDeviceId << mockIntStateId << QVariant(2) << ValueOperatorLessOrEqual << false;
|
||||
QTest::newRow("LessOrEqual, matching (less)") << m_mockDeviceId << mockIntStateId << QVariant(777) << ValueOperatorLessOrEqual << true;
|
||||
QTest::newRow("LessOrEqual, matching (equals)") << m_mockDeviceId << mockIntStateId << QVariant(10) << ValueOperatorLessOrEqual << true;
|
||||
QTest::newRow("Less, not matching") << m_mockDeviceId << mockIntStateId << QVariant(2) << Types::ValueOperatorLess << false;
|
||||
QTest::newRow("Less, matching") << m_mockDeviceId << mockIntStateId << QVariant(7777) << Types::ValueOperatorLess << true;
|
||||
QTest::newRow("LessOrEqual, not matching") << m_mockDeviceId << mockIntStateId << QVariant(2) << Types::ValueOperatorLessOrEqual << false;
|
||||
QTest::newRow("LessOrEqual, matching (less)") << m_mockDeviceId << mockIntStateId << QVariant(777) << Types::ValueOperatorLessOrEqual << true;
|
||||
QTest::newRow("LessOrEqual, matching (equals)") << m_mockDeviceId << mockIntStateId << QVariant(10) << Types::ValueOperatorLessOrEqual << true;
|
||||
}
|
||||
|
||||
void TestRules::testStateEvaluator()
|
||||
@ -390,7 +390,7 @@ void TestRules::testStateEvaluator()
|
||||
QFETCH(DeviceId, deviceId);
|
||||
QFETCH(StateTypeId, stateTypeId);
|
||||
QFETCH(QVariant, value);
|
||||
QFETCH(ValueOperator, operatorType);
|
||||
QFETCH(Types::ValueOperator, operatorType);
|
||||
QFETCH(bool, shouldMatch);
|
||||
|
||||
StateDescriptor descriptor(stateTypeId, deviceId, value, operatorType);
|
||||
@ -402,31 +402,31 @@ void TestRules::testStateEvaluator()
|
||||
void TestRules::testStateEvaluator2_data()
|
||||
{
|
||||
QTest::addColumn<int>("intValue");
|
||||
QTest::addColumn<ValueOperator>("intOperator");
|
||||
QTest::addColumn<Types::ValueOperator>("intOperator");
|
||||
|
||||
QTest::addColumn<bool>("boolValue");
|
||||
QTest::addColumn<ValueOperator>("boolOperator");
|
||||
QTest::addColumn<Types::ValueOperator>("boolOperator");
|
||||
|
||||
QTest::addColumn<StateOperator>("stateOperator");
|
||||
QTest::addColumn<Types::StateOperator>("stateOperator");
|
||||
|
||||
QTest::addColumn<bool>("shouldMatch");
|
||||
|
||||
QTest::newRow("Y: 10 && false") << 10 << ValueOperatorEquals << false << ValueOperatorEquals << StateOperatorAnd << true;
|
||||
QTest::newRow("N: 10 && true") << 10 << ValueOperatorEquals << true << ValueOperatorEquals << StateOperatorAnd << false;
|
||||
QTest::newRow("N: 11 && false") << 11 << ValueOperatorEquals << false << ValueOperatorEquals << StateOperatorAnd << false;
|
||||
QTest::newRow("Y: 11 || false") << 11 << ValueOperatorEquals << false << ValueOperatorEquals << StateOperatorOr << true;
|
||||
QTest::newRow("Y: 10 || false") << 10 << ValueOperatorEquals << false << ValueOperatorEquals << StateOperatorOr << true;
|
||||
QTest::newRow("Y: 10 || true") << 10 << ValueOperatorEquals << true << ValueOperatorEquals << StateOperatorOr << true;
|
||||
QTest::newRow("N: 11 || true") << 11 << ValueOperatorEquals << true << ValueOperatorEquals << StateOperatorOr << false;
|
||||
QTest::newRow("Y: 10 && false") << 10 << Types::ValueOperatorEquals << false << Types::ValueOperatorEquals << Types::StateOperatorAnd << true;
|
||||
QTest::newRow("N: 10 && true") << 10 << Types::ValueOperatorEquals << true << Types::ValueOperatorEquals << Types::StateOperatorAnd << false;
|
||||
QTest::newRow("N: 11 && false") << 11 << Types::ValueOperatorEquals << false << Types::ValueOperatorEquals << Types::StateOperatorAnd << false;
|
||||
QTest::newRow("Y: 11 || false") << 11 << Types::ValueOperatorEquals << false << Types::ValueOperatorEquals << Types::StateOperatorOr << true;
|
||||
QTest::newRow("Y: 10 || false") << 10 << Types::ValueOperatorEquals << false << Types::ValueOperatorEquals << Types::StateOperatorOr << true;
|
||||
QTest::newRow("Y: 10 || true") << 10 << Types::ValueOperatorEquals << true << Types::ValueOperatorEquals << Types::StateOperatorOr << true;
|
||||
QTest::newRow("N: 11 || true") << 11 << Types::ValueOperatorEquals << true << Types::ValueOperatorEquals << Types::StateOperatorOr << false;
|
||||
}
|
||||
|
||||
void TestRules::testStateEvaluator2()
|
||||
{
|
||||
QFETCH(int, intValue);
|
||||
QFETCH(ValueOperator, intOperator);
|
||||
QFETCH(Types::ValueOperator, intOperator);
|
||||
QFETCH(bool, boolValue);
|
||||
QFETCH(ValueOperator, boolOperator);
|
||||
QFETCH(StateOperator, stateOperator);
|
||||
QFETCH(Types::ValueOperator, boolOperator);
|
||||
QFETCH(Types::StateOperator, stateOperator);
|
||||
QFETCH(bool, shouldMatch);
|
||||
|
||||
StateDescriptor descriptor1(mockIntStateId, m_mockDeviceId, intValue, intOperator);
|
||||
|
||||
@ -46,18 +46,18 @@ void TestStates::getStateValue_data()
|
||||
|
||||
QTest::addColumn<DeviceId>("deviceId");
|
||||
QTest::addColumn<StateTypeId>("stateTypeId");
|
||||
QTest::addColumn<bool>("success");
|
||||
QTest::addColumn<DeviceManager::DeviceError>("error");
|
||||
|
||||
QTest::newRow("existing state") << device->id() << mockIntStateId << true;
|
||||
QTest::newRow("invalid device") << DeviceId::createDeviceId() << mockIntStateId << false;
|
||||
QTest::newRow("invalid statetype") << device->id() << StateTypeId::createStateTypeId() << false;
|
||||
QTest::newRow("existing state") << device->id() << mockIntStateId << DeviceManager::DeviceErrorNoError;
|
||||
QTest::newRow("invalid device") << DeviceId::createDeviceId() << mockIntStateId << DeviceManager::DeviceErrorDeviceNotFound;
|
||||
QTest::newRow("invalid statetype") << device->id() << StateTypeId::createStateTypeId() << DeviceManager::DeviceErrorInvalidParameter;
|
||||
}
|
||||
|
||||
void TestStates::getStateValue()
|
||||
{
|
||||
QFETCH(DeviceId, deviceId);
|
||||
QFETCH(StateTypeId, stateTypeId);
|
||||
QFETCH(bool, success);
|
||||
QFETCH(DeviceManager::DeviceError, error);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("deviceId", deviceId.toString());
|
||||
@ -65,7 +65,7 @@ void TestStates::getStateValue()
|
||||
|
||||
QVariant response = injectAndWait("Devices.GetStateValue", params);
|
||||
|
||||
verifySuccess(response, success);
|
||||
verifyError(response, "deviceError", error);
|
||||
}
|
||||
|
||||
#include "teststates.moc"
|
||||
|
||||
Reference in New Issue
Block a user