Move devicemanager's implementation out of libnymea into libnymea-core

This commit is contained in:
Michael Zanetti 2019-06-18 14:23:20 +02:00
parent 77a3e851bd
commit d24abfe3d0
97 changed files with 2816 additions and 2450 deletions

View File

@ -1,5 +1,5 @@
usr/lib/@DEB_HOST_MULTIARCH@/libnymea.so
usr/include/nymea/* usr/include/nymea
usr/bin/nymea-generateplugininfo usr/bin
libnymea/plugin/plugin.pri usr/include/nymea/
libnymea/devices/plugin.pri usr/include/nymea/
usr/lib/@DEB_HOST_MULTIARCH@/pkgconfig/nymea.pc

View File

@ -91,7 +91,7 @@
\li \b Discovery
\list
\li \b 1. | The user started to discover devices. The method \l{DevicePlugin::discoverDevices()}{discoverDevices()} will be called in the plugin.
\li \b 2. | Return \l{DeviceManager::DeviceError}{DeviceErrorAsync} and start the discovery in the source code.
\li \b 2. | Return \l{Device::DeviceError}{DeviceErrorAsync} and start the discovery in the source code.
\li \b 3. | Once the discovery is finished, the plugin can emit the signal \l{DevicePlugin::devicesDiscovered} to inform the \l{DeviceManager} about the result.
\endlist
\li \b Setup
@ -110,7 +110,7 @@
\li \b Discovery
\list
\li \b 1. | The user started to discover devices. The method \l{DevicePlugin::discoverDevices()}{discoverDevices()} will be called in the plugin.
\li \b 2. | Return \l{DeviceManager::DeviceError}{DeviceErrorAsync} and start the discovery in the source code.
\li \b 2. | Return \l{Device::DeviceError}{DeviceErrorAsync} and start the discovery in the source code.
\li \b 3. | Once the discovery is finished, the plugin can emit the signal \l{DevicePlugin::devicesDiscovered} to inform the \l{DeviceManager} about the result.
\endlist
\li \b Pairing
@ -135,7 +135,7 @@
\li \b Discovery
\list
\li \b 1. | The user started to discover devices. The method \l{DevicePlugin::discoverDevices()}{discoverDevices()} will be called in the plugin.
\li \b 2. | Return \l{DeviceManager::DeviceError}{DeviceErrorAsync} and start the discovery in the source code.
\li \b 2. | Return \l{Device::DeviceError}{DeviceErrorAsync} and start the discovery in the source code.
\li \b 3. | Once the discovery is finished, the plugin can emit the signal \l{DevicePlugin::devicesDiscovered} to inform the \l{DeviceManager} about the result.
\endlist
\li \b Pairing
@ -161,13 +161,13 @@
\li \b Discovery
\list
\li \b 1. | The user started to discover devices. The method \l{DevicePlugin::discoverDevices()}{discoverDevices()} will be called in the plugin.
\li \b 2. | Return \l{DeviceManager::DeviceError}{DeviceErrorAsync} and start the discovery in the source code.
\li \b 2. | Return \l{Device::DeviceError}{DeviceErrorAsync} and start the discovery in the source code.
\li \b 3. | Once the discovery is finished, the plugin can emit the signal \l{DevicePlugin::devicesDiscovered} to inform the \l{DeviceManager} about the result.
\endlist
\li \b{Display pin}
\list
\li \b 4. | Once the user selected one of the discovered devices the device manager will call the method \l{DevicePlugin::displayPin()} in the plugin. Here can be sent the command to display the pin on the device. The pin which will be displayed on the device will be passed as secret in the \l{DevicePlugin::confirmPairing()} method.
\li \b 5. | Returns the \l{DeviceManager::DeviceError} to inform about the result (sync or async).
\li \b 5. | Returns the \l{Device::DeviceError} to inform about the result (sync or async).
\endlist
\li \b Pairing
\list

View File

@ -131,7 +131,7 @@
In order to implement this simple action and emit the Event once the button will be pressed, you need to implement following code:
\quotefromfile simplebutton/devicepluginsimplebutton.cpp
\skipto DeviceManager::DeviceError DevicePluginSimpleButton::executeAction
\skipto Device::DeviceError DevicePluginSimpleButton::executeAction
\printuntil }\n
In this code section you can see the implementation of the \tt executeAction method for this example tutorial. The method

View File

@ -22,6 +22,7 @@
#include "loggingcategories.h"
#include <QDebug>
#include <QJsonObject>
DeviceClassId cloudNotificationsDeviceClassId = DeviceClassId("81c1bbcc-543a-48fd-bd18-ab6a76f9c38d");
ParamTypeId cloudNotificationsDeviceClassUserParamId = ParamTypeId("5bdeaf08-91a9-42bc-a9f9-ef6b02ecaa3c");
@ -42,7 +43,7 @@ CloudNotifications::CloudNotifications(AWSConnector* awsConnector, QObject *pare
connect(m_awsConnector, &AWSConnector::pushNotificationSent, this, &CloudNotifications::pushNotificationSent);
}
QJsonObject CloudNotifications::metaData() const
PluginMetadata CloudNotifications::metaData() const
{
QVariantMap pluginMetaData;
pluginMetaData.insert("id", "ccc6dbc8-e352-48a1-8e87-3c89a4669fc2");
@ -132,13 +133,10 @@ QJsonObject CloudNotifications::metaData() const
vendors.append(guhVendor);
pluginMetaData.insert("vendors", vendors);
// Mark this plugin as built-in
pluginMetaData.insert("builtIn", true);
return QJsonObject::fromVariantMap(pluginMetaData);
return PluginMetadata(QJsonObject::fromVariantMap(pluginMetaData), true);
}
DeviceManager::DeviceSetupStatus CloudNotifications::setupDevice(Device *device)
Device::DeviceSetupStatus CloudNotifications::setupDevice(Device *device)
{
device->setStateValue(connectedStateTypeId, m_awsConnector->isConnected());
qCDebug(dcCloud) << "Cloud Notifications Device setup:" << device->name() << "Connected:" << m_awsConnector->isConnected();
@ -148,21 +146,21 @@ DeviceManager::DeviceSetupStatus CloudNotifications::setupDevice(Device *device)
connect(m_awsConnector, &AWSConnector::disconnected, device, [device]() {
device->setStateValue(connectedStateTypeId, false);
});
return DeviceManager::DeviceSetupStatusSuccess;
return Device::DeviceSetupStatusSuccess;
}
void CloudNotifications::startMonitoringAutoDevices()
{
}
DeviceManager::DeviceError CloudNotifications::executeAction(Device *device, const Action &action)
Device::DeviceError CloudNotifications::executeAction(Device *device, const Action &action)
{
qCDebug(dcCloud()) << "executeAction" << device << action.id() << action.params();
QString userId = device->paramValue(cloudNotificationsDeviceClassUserParamId).toString();
QString endpointId = device->paramValue(cloudNotificationsDeviceClassEndpointParamId).toString();
int id = m_awsConnector->sendPushNotification(userId, endpointId, action.param(notifyActionParamTitleId).value().toString(), action.param(notifyActionParamBodyId).value().toString());
m_pendingPushNotifications.insert(id, action.id());
return DeviceManager::DeviceErrorAsync;
return Device::DeviceErrorAsync;
}
void CloudNotifications::pushNotificationEndpointsUpdated(const QList<AWSConnector::PushNotificationsEndpoint> &endpoints)
@ -238,5 +236,5 @@ void CloudNotifications::pushNotificationSent(int id, int status)
{
qCDebug(dcCloud()) << "Push notification sent" << id << status;
ActionId actionId = m_pendingPushNotifications.value(id);
emit actionExecutionFinished(actionId, status == 200 ? DeviceManager::DeviceErrorNoError : DeviceManager::DeviceErrorHardwareNotAvailable);
emit actionExecutionFinished(actionId, status == 200 ? Device::DeviceErrorNoError : Device::DeviceErrorHardwareNotAvailable);
}

View File

@ -21,7 +21,7 @@
#ifndef CLOUDNOTIFICATIONS_H
#define CLOUDNOTIFICATIONS_H
#include "plugin/deviceplugin.h"
#include "devices/deviceplugin.h"
#include "awsconnector.h"
class CloudNotifications : public DevicePlugin
@ -34,11 +34,11 @@ class CloudNotifications : public DevicePlugin
public:
CloudNotifications(AWSConnector *awsConnector, QObject* parent = nullptr);
QJsonObject metaData() const;
PluginMetadata metaData() const;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
Device::DeviceSetupStatus setupDevice(Device *device) override;
void startMonitoringAutoDevices() override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
Device::DeviceError executeAction(Device *device, const Action &action) override;
private slots:
void pushNotificationEndpointsUpdated(const QList<AWSConnector::PushNotificationsEndpoint> &endpoints);

View File

@ -978,19 +978,6 @@ QByteArray DebugServerHandler::createDebugXmlDocument()
writer.writeTextElement("td", NymeaSettings(NymeaSettings::SettingsRoleGlobal).translationsPath());
writer.writeEndElement(); // tr
for (int i = 0; i < NymeaCore::instance()->deviceManager()->pluginSearchDirs().count(); i++) {
writer.writeStartElement("tr");
writer.writeEndElement(); // tr
if (i == 0) {
//: The plugins path description in the server infromation section of the debug interface
writer.writeTextElement("th", tr("Plugin paths"));
} else {
writer.writeTextElement("th", "");
}
writer.writeTextElement("td", QFileInfo(NymeaCore::instance()->deviceManager()->pluginSearchDirs().at(i)).absoluteFilePath());
}
writer.writeEndElement(); // table
// Generate report

View File

@ -0,0 +1,155 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015-2018 Simon Stürz <simon.stuerz@guh.io> *
* Copyright (C) 2014 Michael Zanetti <michael_zanetti@gmx.net> *
* *
* This file is part of nymea. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEVICEMANAGERIMPLEMENTATION_H
#define DEVICEMANAGERIMPLEMENTATION_H
#include "libnymea.h"
#include "devices/device.h"
#include "devices/devicedescriptor.h"
#include "devices/pluginmetadata.h"
#include "types/deviceclass.h"
#include "types/interface.h"
#include "types/event.h"
#include "types/action.h"
#include "types/vendor.h"
#include <QObject>
#include <QTimer>
#include <QLocale>
#include <QPluginLoader>
#include <QTranslator>
#include "hardwaremanager.h"
#include "devices/devicemanager.h"
class Device;
class DevicePlugin;
class DevicePairingInfo;
class HardwareManager;
class Translator;
class DeviceManagerImplementation: public DeviceManager
{
Q_OBJECT
friend class DevicePlugin;
public:
explicit DeviceManagerImplementation(HardwareManager *hardwareManager, const QLocale &locale, QObject *parent = nullptr);
~DeviceManagerImplementation();
static QStringList pluginSearchDirs();
static QList<QJsonObject> pluginsMetadata();
void registerStaticPlugin(DevicePlugin* plugin, const PluginMetadata &metaData);
DevicePlugins plugins() const override;
Device::DeviceError setPluginConfig(const PluginId &pluginId, const ParamList &pluginConfig) override;
Vendors supportedVendors() const override;
Interfaces supportedInterfaces() const override;
DeviceClasses supportedDevices(const VendorId &vendorId = VendorId()) const override;
Devices configuredDevices() const override;
Device* findConfiguredDevice(const DeviceId &id) const override;
Devices findConfiguredDevices(const DeviceClassId &deviceClassId) const override;
Devices findConfiguredDevices(const QString &interface) const override;
Devices findChildDevices(const DeviceId &id) const override;
DeviceClass findDeviceClass(const DeviceClassId &deviceClassId) const override;
Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
Device::DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QString &name, const ParamList &params, const DeviceId id = DeviceId::createDeviceId()) override;
Device::DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QString &name, const DeviceDescriptorId &deviceDescriptorId, const ParamList &params = ParamList(), const DeviceId &deviceId = DeviceId::createDeviceId()) override;
Device::DeviceError reconfigureDevice(const DeviceId &deviceId, const ParamList &params, bool fromDiscoveryOrAuto = false) override;
Device::DeviceError reconfigureDevice(const DeviceId &deviceId, const DeviceDescriptorId &deviceDescriptorId) override;
Device::DeviceError editDevice(const DeviceId &deviceId, const QString &name) override;
Device::DeviceError setDeviceSettings(const DeviceId &deviceId, const ParamList &settings) override;
Device::DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const QString &name, const ParamList &params) override;
Device::DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const QString &name, const DeviceDescriptorId &deviceDescriptorId) override;
Device::DeviceError confirmPairing(const PairingTransactionId &pairingTransactionId, const QString &secret = QString()) override;
Device::DeviceError removeConfiguredDevice(const DeviceId &deviceId) override;
QString translate(const PluginId &pluginId, const QString &string, const QLocale &locale) override;
signals:
void loaded();
public slots:
Device::DeviceError executeAction(const Action &action);
void timeTick();
private slots:
void loadPlugins();
void loadPlugin(DevicePlugin *pluginIface, const PluginMetadata &metaData);
void loadConfiguredDevices();
void storeConfiguredDevices();
void startMonitoringAutoDevices();
void slotDevicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> deviceDescriptors);
void slotDeviceSetupFinished(Device *device, Device::DeviceSetupStatus status);
void slotPairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceSetupStatus status);
void onAutoDevicesAppeared(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> &deviceDescriptors);
void onAutoDeviceDisappeared(const DeviceId &deviceId);
void onLoaded();
void cleanupDeviceStateCache();
// Only connect this to Devices. It will query the sender()
void slotDeviceStateValueChanged(const StateTypeId &stateTypeId, const QVariant &value);
void slotDeviceSettingChanged(const ParamTypeId &paramTypeId, const QVariant &value);
private:
Device::DeviceError addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QString &name, const ParamList &params, const DeviceId id = DeviceId::createDeviceId());
Device::DeviceSetupStatus setupDevice(Device *device);
void postSetupDevice(Device *device);
void storeDeviceStates(Device *device);
void loadDeviceStates(Device *device);
private:
HardwareManager *m_hardwareManager;
QLocale m_locale;
Translator *m_translator = nullptr;
QHash<VendorId, Vendor> m_supportedVendors;
QHash<QString, Interface> m_supportedInterfaces;
QHash<VendorId, QList<DeviceClassId> > m_vendorDeviceMap;
QHash<DeviceClassId, DeviceClass> m_supportedDevices;
QHash<DeviceId, Device*> m_configuredDevices;
QHash<DeviceDescriptorId, DeviceDescriptor> m_discoveredDevices;
QHash<PluginId, DevicePlugin*> m_devicePlugins;
QHash<QUuid, DevicePairingInfo> m_pairingsJustAdd;
QHash<QUuid, DevicePairingInfo> m_pairingsDiscovery;
QList<Device *> m_asyncDeviceReconfiguration;
QList<DevicePlugin *> m_discoveringPlugins;
};
#endif // DEVICEMANAGERIMPLEMENTATION_H

View File

@ -36,7 +36,7 @@
#include "stateevaluator.h"
#include "nymeacore.h"
#include "devicemanager.h"
#include "devices/devicemanager.h"
#include "loggingcategories.h"
#include "nymeasettings.h"

View File

@ -22,13 +22,14 @@
#include "translator.h"
#include "nymeasettings.h"
#include "devicemanagerimplementation.h"
#include "loggingcategories.h"
#include "plugin/deviceplugin.h"
#include "devices/deviceplugin.h"
#include <QCoreApplication>
#include <QDir>
Translator::Translator(DeviceManager *deviceManager):
Translator::Translator(DeviceManagerImplementation *deviceManager):
m_deviceManager(deviceManager)
{
@ -46,7 +47,7 @@ Translator::~Translator()
QString Translator::translate(const PluginId &pluginId, const QString &string, const QLocale &locale)
{
DevicePlugin *plugin = m_deviceManager->plugin(pluginId);
DevicePlugin *plugin = m_deviceManager->plugins().findById(pluginId);
if (!m_translatorContexts.contains(plugin->pluginId()) || !m_translatorContexts.value(plugin->pluginId()).translators.contains(locale.name())) {
loadTranslator(plugin, locale);

View File

@ -29,12 +29,12 @@
#include <QTranslator>
class DevicePlugin;
class DeviceManager;
class DeviceManagerImplementation;
class Translator
{
public:
Translator(DeviceManager *deviceManager);
Translator(DeviceManagerImplementation *deviceManager);
~Translator();
QString translate(const PluginId &pluginId, const QString &string, const QLocale &locale);
@ -43,7 +43,7 @@ private:
void loadTranslator(DevicePlugin *plugin, const QLocale &locale);
private:
DeviceManager *m_deviceManager = nullptr;
DeviceManagerImplementation *m_deviceManager = nullptr;
struct TranslatorContext {
PluginId pluginId;

View File

@ -27,6 +27,7 @@
#include <QDebug>
#include <QTimer>
#include <QMetaObject>
#include <QPointer>
#include "upnpdiscoveryreplyimplementation.h"
#include "network/upnp/upnpdiscovery.h"

View File

@ -35,7 +35,7 @@
#include "actionhandler.h"
#include "nymeacore.h"
#include "devicemanager.h"
#include "devices/devicemanager.h"
#include "types/action.h"
#include "loggingcategories.h"
@ -80,8 +80,8 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap &params)
Action action(actionTypeId, deviceId);
action.setParams(actionParams);
DeviceManager::DeviceError status = NymeaCore::instance()->executeAction(action);
if (status == DeviceManager::DeviceErrorAsync) {
Device::DeviceError status = NymeaCore::instance()->executeAction(action);
if (status == Device::DeviceErrorAsync) {
JsonReply *reply = createAsyncReply("ExecuteAction");
ActionId id = action.id();
connect(reply, &JsonReply::finished, [this, id](){ m_asyncActionExecutions.remove(id); });
@ -99,16 +99,16 @@ JsonReply *ActionHandler::GetActionType(const QVariantMap &params) const
foreach (const DeviceClass &deviceClass, NymeaCore::instance()->deviceManager()->supportedDevices()) {
foreach (const ActionType &actionType, deviceClass.actionTypes()) {
if (actionType.id() == actionTypeId) {
QVariantMap data = statusToReply(DeviceManager::DeviceErrorNoError);
QVariantMap data = statusToReply(Device::DeviceErrorNoError);
data.insert("actionType", JsonTypes::packActionType(actionType, deviceClass.pluginId(), params.value("locale").toLocale()));
return createReply(data);
}
}
}
return createReply(statusToReply(DeviceManager::DeviceErrorActionTypeNotFound));
return createReply(statusToReply(Device::DeviceErrorActionTypeNotFound));
}
void ActionHandler::actionExecuted(const ActionId &id, DeviceManager::DeviceError status)
void ActionHandler::actionExecuted(const ActionId &id, Device::DeviceError status)
{
if (!m_asyncActionExecutions.contains(id)) {
return; // Not the action we are waiting for.

View File

@ -23,7 +23,7 @@
#define ACTIONHANDLER_H
#include "jsonhandler.h"
#include "devicemanager.h"
#include "devices/devicemanager.h"
namespace nymeaserver {
@ -31,7 +31,7 @@ class ActionHandler : public JsonHandler
{
Q_OBJECT
public:
explicit ActionHandler(QObject *parent = 0);
explicit ActionHandler(QObject *parent = nullptr);
QString name() const;
@ -39,7 +39,7 @@ public:
Q_INVOKABLE JsonReply *GetActionType(const QVariantMap &params) const;
private slots:
void actionExecuted(const ActionId &id, DeviceManager::DeviceError status);
void actionExecuted(const ActionId &id, Device::DeviceError status);
private:
QHash<ActionId, JsonReply *> m_asyncActionExecutions;

View File

@ -55,12 +55,12 @@
#include "devicehandler.h"
#include "nymeacore.h"
#include "devicemanager.h"
#include "devices/devicemanager.h"
#include "devices/device.h"
#include "devices/deviceplugin.h"
#include "loggingcategories.h"
#include "types/deviceclass.h"
#include "plugin/device.h"
#include "plugin/deviceplugin.h"
#include "translator.h"
#include "devices/translator.h"
#include <QDebug>
@ -361,8 +361,8 @@ JsonReply *DeviceHandler::GetDiscoveredDevices(const QVariantMap &params) const
ParamList discoveryParams = JsonTypes::unpackParams(params.value("discoveryParams").toList());
DeviceManager::DeviceError status = NymeaCore::instance()->deviceManager()->discoverDevices(deviceClassId, discoveryParams);
if (status == DeviceManager::DeviceErrorAsync ) {
Device::DeviceError status = NymeaCore::instance()->deviceManager()->discoverDevices(deviceClassId, discoveryParams);
if (status == Device::DeviceErrorAsync ) {
JsonReply *reply = createAsyncReply("GetDiscoveredDevices");
connect(reply, &JsonReply::finished, this, [this, deviceClassId](){ m_discoverRequests.remove(deviceClassId); });
m_discoverRequests.insert(deviceClassId, reply);
@ -385,9 +385,9 @@ JsonReply *DeviceHandler::GetPluginConfiguration(const QVariantMap &params) cons
{
QVariantMap returns;
DevicePlugin *plugin = NymeaCore::instance()->deviceManager()->plugin(PluginId(params.value("pluginId").toString()));
DevicePlugin *plugin = NymeaCore::instance()->deviceManager()->plugins().findById(PluginId(params.value("pluginId").toString()));
if (!plugin) {
returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorPluginNotFound));
returns.insert("deviceError", JsonTypes::deviceErrorToString(Device::DeviceErrorPluginNotFound));
return createReply(returns);
}
@ -396,7 +396,7 @@ JsonReply *DeviceHandler::GetPluginConfiguration(const QVariantMap &params) cons
paramVariantList.append(JsonTypes::packParam(param));
}
returns.insert("configuration", paramVariantList);
returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorNoError));
returns.insert("deviceError", JsonTypes::deviceErrorToString(Device::DeviceErrorNoError));
return createReply(returns);
}
@ -405,7 +405,7 @@ JsonReply* DeviceHandler::SetPluginConfiguration(const QVariantMap &params)
QVariantMap returns;
PluginId pluginId = PluginId(params.value("pluginId").toString());
ParamList pluginParams = JsonTypes::unpackParams(params.value("configuration").toList());
DeviceManager::DeviceError result = NymeaCore::instance()->deviceManager()->setPluginConfig(pluginId, pluginParams);
Device::DeviceError result = NymeaCore::instance()->deviceManager()->setPluginConfig(pluginId, pluginParams);
returns.insert("deviceError", JsonTypes::deviceErrorToString(result));
return createReply(returns);
}
@ -417,7 +417,7 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap &params)
ParamList deviceParams = JsonTypes::unpackParams(params.value("deviceParams").toList());
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
DeviceId newDeviceId = DeviceId::createDeviceId();
DeviceManager::DeviceError status;
Device::DeviceError status;
if (deviceDescriptorId.isNull()) {
status = NymeaCore::instance()->deviceManager()->addConfiguredDevice(deviceClass, deviceName, deviceParams, newDeviceId);
} else {
@ -425,13 +425,13 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap &params)
}
QVariantMap returns;
switch (status) {
case DeviceManager::DeviceErrorAsync: {
case Device::DeviceErrorAsync: {
JsonReply *asyncReply = createAsyncReply("AddConfiguredDevice");
connect(asyncReply, &JsonReply::finished, [this, newDeviceId](){ m_asynDeviceAdditions.remove(newDeviceId); });
m_asynDeviceAdditions.insert(newDeviceId, asyncReply);
return asyncReply;
}
case DeviceManager::DeviceErrorNoError:
case Device::DeviceErrorNoError:
returns.insert("deviceId", newDeviceId);
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));
break;
@ -447,7 +447,7 @@ JsonReply *DeviceHandler::PairDevice(const QVariantMap &params)
QString deviceName = params.value("name").toString();
DeviceClass deviceClass = NymeaCore::instance()->deviceManager()->findDeviceClass(deviceClassId);
DeviceManager::DeviceError status;
Device::DeviceError status;
PairingTransactionId pairingTransactionId = PairingTransactionId::createPairingTransactionId();
if (params.contains("deviceDescriptorId")) {
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
@ -459,8 +459,8 @@ JsonReply *DeviceHandler::PairDevice(const QVariantMap &params)
QVariantMap returns;
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));
if (status == DeviceManager::DeviceErrorNoError) {
returns.insert("displayMessage", NymeaCore::instance()->deviceManager()->translator()->translate(deviceClass.pluginId(), deviceClass.pairingInfo(), params.value("locale").toLocale()));
if (status == Device::DeviceErrorNoError) {
returns.insert("displayMessage", NymeaCore::instance()->deviceManager()->translate(deviceClass.pluginId(), deviceClass.pairingInfo(), params.value("locale").toLocale()));
returns.insert("pairingTransactionId", pairingTransactionId.toString());
returns.insert("setupMethod", JsonTypes::setupMethod().at(deviceClass.setupMethod()));
}
@ -471,10 +471,10 @@ JsonReply *DeviceHandler::ConfirmPairing(const QVariantMap &params)
{
PairingTransactionId pairingTransactionId = PairingTransactionId(params.value("pairingTransactionId").toString());
QString secret = params.value("secret").toString();
DeviceManager::DeviceError status = NymeaCore::instance()->deviceManager()->confirmPairing(pairingTransactionId, secret);
Device::DeviceError status = NymeaCore::instance()->deviceManager()->confirmPairing(pairingTransactionId, secret);
JsonReply *reply = nullptr;
if (status == DeviceManager::DeviceErrorAsync) {
if (status == Device::DeviceErrorAsync) {
reply = createAsyncReply("ConfirmPairing");
connect(reply, &JsonReply::finished, [this, pairingTransactionId](){ m_asyncPairingRequests.remove(pairingTransactionId); });
m_asyncPairingRequests.insert(pairingTransactionId, reply);
@ -493,7 +493,7 @@ JsonReply* DeviceHandler::GetConfiguredDevices(const QVariantMap &params) const
if (params.contains("deviceId")) {
Device *device = NymeaCore::instance()->deviceManager()->findConfiguredDevice(DeviceId(params.value("deviceId").toString()));
if (!device) {
returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorDeviceNotFound));
returns.insert("deviceError", JsonTypes::deviceErrorToString(Device::DeviceErrorDeviceNotFound));
return createReply(returns);
} else {
configuredDeviceList.append(JsonTypes::packDevice(device));
@ -513,7 +513,7 @@ JsonReply *DeviceHandler::ReconfigureDevice(const QVariantMap &params)
DeviceId deviceId = DeviceId(params.value("deviceId").toString());
ParamList deviceParams = JsonTypes::unpackParams(params.value("deviceParams").toList());
DeviceManager::DeviceError status;
Device::DeviceError status;
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
if (deviceDescriptorId.isNull()) {
status = NymeaCore::instance()->deviceManager()->reconfigureDevice(deviceId, deviceParams);
@ -521,7 +521,7 @@ JsonReply *DeviceHandler::ReconfigureDevice(const QVariantMap &params)
status = NymeaCore::instance()->deviceManager()->reconfigureDevice(deviceId, deviceDescriptorId);
}
if (status == DeviceManager::DeviceErrorAsync) {
if (status == Device::DeviceErrorAsync) {
JsonReply *asyncReply = createAsyncReply("ReconfigureDevice");
connect(asyncReply, &JsonReply::finished, [this, deviceId](){ m_asynDeviceEditAdditions.remove(deviceId); });
m_asynDeviceEditAdditions.insert(deviceId, asyncReply);
@ -540,7 +540,7 @@ JsonReply *DeviceHandler::EditDevice(const QVariantMap &params)
qCDebug(dcJsonRpc()) << "Edit device" << deviceId << name;
DeviceManager::DeviceError status = NymeaCore::instance()->deviceManager()->editDevice(deviceId, name);
Device::DeviceError status = NymeaCore::instance()->deviceManager()->editDevice(deviceId, name);
QVariantMap returns;
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));
@ -555,7 +555,7 @@ JsonReply* DeviceHandler::RemoveConfiguredDevice(const QVariantMap &params)
// global removePolicy has priority
if (params.contains("removePolicy")) {
RuleEngine::RemovePolicy removePolicy = params.value("removePolicy").toString() == "RemovePolicyCascade" ? RuleEngine::RemovePolicyCascade : RuleEngine::RemovePolicyUpdate;
DeviceManager::DeviceError status = NymeaCore::instance()->removeConfiguredDevice(deviceId, removePolicy);
Device::DeviceError status = NymeaCore::instance()->removeConfiguredDevice(deviceId, removePolicy);
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));
return createReply(returns);
}
@ -567,7 +567,7 @@ JsonReply* DeviceHandler::RemoveConfiguredDevice(const QVariantMap &params)
removePolicyList.insert(ruleId, policy);
}
QPair<DeviceManager::DeviceError, QList<RuleId> > status = NymeaCore::instance()->removeConfiguredDevice(deviceId, removePolicyList);
QPair<Device::DeviceError, QList<RuleId> > status = NymeaCore::instance()->removeConfiguredDevice(deviceId, removePolicyList);
returns.insert("deviceError", JsonTypes::deviceErrorToString(status.first));
if (!status.second.isEmpty()) {
@ -586,7 +586,7 @@ JsonReply *DeviceHandler::SetDeviceSettings(const QVariantMap &params)
QVariantMap returns;
DeviceId deviceId = DeviceId(params.value("deviceId").toString());
ParamList settings = JsonTypes::unpackParams(params.value("settings").toList());
DeviceManager::DeviceError status = NymeaCore::instance()->deviceManager()->setDeviceSettings(deviceId, settings);
Device::DeviceError status = NymeaCore::instance()->deviceManager()->setDeviceSettings(deviceId, settings);
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));
return createReply(returns);
}
@ -636,16 +636,16 @@ JsonReply* DeviceHandler::GetStateValue(const QVariantMap &params) const
Device *device = NymeaCore::instance()->deviceManager()->findConfiguredDevice(DeviceId(params.value("deviceId").toString()));
if (!device) {
returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorDeviceNotFound));
returns.insert("deviceError", JsonTypes::deviceErrorToString(Device::DeviceErrorDeviceNotFound));
return createReply(returns);
}
StateTypeId stateTypeId = StateTypeId(params.value("stateTypeId").toString());
if (!device->hasState(stateTypeId)) {
returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorStateTypeNotFound));
returns.insert("deviceError", JsonTypes::deviceErrorToString(Device::DeviceErrorStateTypeNotFound));
return createReply(returns);
}
returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorNoError));
returns.insert("deviceError", JsonTypes::deviceErrorToString(Device::DeviceErrorNoError));
returns.insert("value", device->state(stateTypeId).value());
return createReply(returns);
}
@ -656,11 +656,11 @@ JsonReply *DeviceHandler::GetStateValues(const QVariantMap &params) const
Device *device = NymeaCore::instance()->deviceManager()->findConfiguredDevice(DeviceId(params.value("deviceId").toString()));
if (!device) {
returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorDeviceNotFound));
returns.insert("deviceError", JsonTypes::deviceErrorToString(Device::DeviceErrorDeviceNotFound));
return createReply(returns);
}
returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorNoError));
returns.insert("deviceError", JsonTypes::deviceErrorToString(Device::DeviceErrorNoError));
returns.insert("values", JsonTypes::packDeviceStates(device));
return createReply(returns);
}
@ -733,13 +733,13 @@ void DeviceHandler::devicesDiscovered(const DeviceClassId &deviceClassId, const
QVariantMap returns;
returns.insert("deviceDescriptors", JsonTypes::packDeviceDescriptors(deviceDescriptors));
returns.insert("deviceError", JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorNoError));
returns.insert("deviceError", JsonTypes::deviceErrorToString(Device::DeviceErrorNoError));
reply->setData(returns);
reply->finished();
}
void DeviceHandler::deviceSetupFinished(Device *device, DeviceManager::DeviceError status)
void DeviceHandler::deviceSetupFinished(Device *device, Device::DeviceError status)
{
qCDebug(dcJsonRpc) << "Got a device setup finished" << device->name() << device->id();
if (!m_asynDeviceAdditions.contains(device->id())) {
@ -751,14 +751,14 @@ void DeviceHandler::deviceSetupFinished(Device *device, DeviceManager::DeviceErr
QVariantMap returns;
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));
if(status == DeviceManager::DeviceErrorNoError) {
if(status == Device::DeviceErrorNoError) {
returns.insert("deviceId", device->id());
}
reply->setData(returns);
reply->finished();
}
void DeviceHandler::deviceReconfigurationFinished(Device *device, DeviceManager::DeviceError status)
void DeviceHandler::deviceReconfigurationFinished(Device *device, Device::DeviceError status)
{
qCDebug(dcJsonRpc) << "Got async device reconfiguration finished";
if (!m_asynDeviceEditAdditions.contains(device->id())) {
@ -772,7 +772,7 @@ void DeviceHandler::deviceReconfigurationFinished(Device *device, DeviceManager:
reply->finished();
}
void DeviceHandler::pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceError status, const DeviceId &deviceId)
void DeviceHandler::pairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceError status, const DeviceId &deviceId)
{
qCDebug(dcJsonRpc) << "Got pairing finished";
JsonReply *reply = m_asyncPairingRequests.take(pairingTransactionId);
@ -780,7 +780,7 @@ void DeviceHandler::pairingFinished(const PairingTransactionId &pairingTransacti
return;
}
if (status != DeviceManager::DeviceErrorNoError) {
if (status != Device::DeviceErrorNoError) {
QVariantMap returns;
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));
reply->setData(returns);

View File

@ -23,7 +23,7 @@
#define DEVICEHANDLER_H
#include "jsonhandler.h"
#include "devicemanager.h"
#include "devices/devicemanager.h"
namespace nymeaserver {
@ -80,11 +80,11 @@ private slots:
void devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> deviceDescriptors);
void deviceSetupFinished(Device *device, DeviceManager::DeviceError status);
void deviceSetupFinished(Device *device, Device::DeviceError status);
void deviceReconfigurationFinished(Device *device, DeviceManager::DeviceError status);
void deviceReconfigurationFinished(Device *device, Device::DeviceError status);
void pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceError status, const DeviceId &deviceId);
void pairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceError status, const DeviceId &deviceId);
private:
// A cache for async replies

View File

@ -87,13 +87,13 @@ JsonReply* EventHandler::GetEventType(const QVariantMap &params) const
foreach (const DeviceClass &deviceClass, NymeaCore::instance()->deviceManager()->supportedDevices()) {
foreach (const EventType &eventType, deviceClass.eventTypes()) {
if (eventType.id() == eventTypeId) {
QVariantMap data = statusToReply(DeviceManager::DeviceErrorNoError);
QVariantMap data = statusToReply(Device::DeviceErrorNoError);
data.insert("eventType", JsonTypes::packEventType(eventType, deviceClass.pluginId(), params.value("locale").toLocale()));
return createReply(data);
}
}
}
return createReply(statusToReply(DeviceManager::DeviceErrorEventTypeNotFound));
return createReply(statusToReply(Device::DeviceErrorEventTypeNotFound));
}
}

View File

@ -173,9 +173,9 @@ JsonReply* JsonHandler::createAsyncReply(const QString &method) const
/*! Returns the formated error map for the given \a status.
*
* \sa DeviceManager::DeviceError
* \sa Device::DeviceError
*/
QVariantMap JsonHandler::statusToReply(DeviceManager::DeviceError status) const
QVariantMap JsonHandler::statusToReply(Device::DeviceError status) const
{
QVariantMap returns;
returns.insert("deviceError", JsonTypes::deviceErrorToString(status));

View File

@ -108,7 +108,7 @@ protected:
JsonReply *createReply(const QVariantMap &data) const;
JsonReply *createAsyncReply(const QString &method) const;
QVariantMap statusToReply(DeviceManager::DeviceError status) const;
QVariantMap statusToReply(Device::DeviceError status) const;
QVariantMap statusToReply(RuleEngine::RuleError status) const;
QVariantMap statusToReply(Logging::LoggingError status) const;
QVariantMap statusToReply(NymeaConfiguration::ConfigurationError status) const;

View File

@ -40,12 +40,12 @@
#include "jsontypes.h"
#include "jsonhandler.h"
#include "nymeacore.h"
#include "devicemanager.h"
#include "plugin/deviceplugin.h"
#include "devices/devicemanager.h"
#include "devices/deviceplugin.h"
#include "devices/device.h"
#include "types/deviceclass.h"
#include "plugin/device.h"
#include "rule.h"
#include "ruleengine.h"
#include "ruleengine/rule.h"
#include "ruleengine/ruleengine.h"
#include "loggingcategories.h"
#include "platform/platform.h"

View File

@ -24,7 +24,7 @@
#include "jsonhandler.h"
#include "transportinterface.h"
#include "usermanager.h"
#include "usermanager/usermanager.h"
#include "types/deviceclass.h"
#include "types/action.h"

View File

@ -50,14 +50,13 @@
#include "jsontypes.h"
#include "plugin/device.h"
#include "devicemanager.h"
#include "devices/device.h"
#include "devices/devicemanager.h"
#include "devices/deviceplugin.h"
#include "nymeacore.h"
#include "ruleengine.h"
#include "ruleengine/ruleengine.h"
#include "loggingcategories.h"
#include "logging/logvaluetool.h"
#include "translator.h"
#include "plugin/deviceplugin.h"
#include <QStringList>
#include <QJsonDocument>
@ -140,7 +139,7 @@ void JsonTypes::init()
s_createMethod = enumToStrings(DeviceClass::staticMetaObject, "CreateMethod");
s_setupMethod = enumToStrings(DeviceClass::staticMetaObject, "SetupMethod");
s_removePolicy = enumToStrings(RuleEngine::staticMetaObject, "RemovePolicy");
s_deviceError = enumToStrings(DeviceManager::staticMetaObject, "DeviceError");
s_deviceError = enumToStrings(Device::staticMetaObject, "DeviceError");
s_ruleError = enumToStrings(RuleEngine::staticMetaObject, "RuleError");
s_loggingError = enumToStrings(Logging::staticMetaObject, "LoggingError");
s_loggingSource = enumToStrings(Logging::staticMetaObject, "LoggingSource");
@ -512,7 +511,7 @@ QVariantMap JsonTypes::packEventType(const EventType &eventType, const PluginId
QVariantMap variant;
variant.insert("id", eventType.id().toString());
variant.insert("name", eventType.name());
variant.insert("displayName", NymeaCore::instance()->deviceManager()->translator()->translate(pluginId, eventType.displayName(), locale));
variant.insert("displayName", NymeaCore::instance()->deviceManager()->translate(pluginId, eventType.displayName(), locale));
variant.insert("index", eventType.index());
QVariantList paramTypes;
@ -562,7 +561,7 @@ QVariantMap JsonTypes::packActionType(const ActionType &actionType, const Plugin
QVariantMap variantMap;
variantMap.insert("id", actionType.id().toString());
variantMap.insert("name", actionType.name());
variantMap.insert("displayName", NymeaCore::instance()->deviceManager()->translator()->translate(pluginId, actionType.displayName(), locale));
variantMap.insert("displayName", NymeaCore::instance()->deviceManager()->translate(pluginId, actionType.displayName(), locale));
variantMap.insert("index", actionType.index());
QVariantList paramTypes;
foreach (const ParamType &paramType, actionType.paramTypes())
@ -642,7 +641,7 @@ QVariantMap JsonTypes::packStateType(const StateType &stateType, const PluginId
QVariantMap variantMap;
variantMap.insert("id", stateType.id().toString());
variantMap.insert("name", stateType.name());
variantMap.insert("displayName", NymeaCore::instance()->deviceManager()->translator()->translate(pluginId, stateType.displayName(), locale));
variantMap.insert("displayName", NymeaCore::instance()->deviceManager()->translate(pluginId, stateType.displayName(), locale));
variantMap.insert("index", stateType.index());
variantMap.insert("type", basicTypeToString(stateType.type()));
variantMap.insert("defaultValue", stateType.defaultValue());
@ -736,7 +735,7 @@ QVariantMap JsonTypes::packParamType(const ParamType &paramType, const PluginId
QVariantMap variantMap;
variantMap.insert("id", paramType.id().toString());
variantMap.insert("name", paramType.name());
variantMap.insert("displayName", NymeaCore::instance()->deviceManager()->translator()->translate(pluginId, paramType.displayName(), locale));
variantMap.insert("displayName", NymeaCore::instance()->deviceManager()->translate(pluginId, paramType.displayName(), locale));
variantMap.insert("type", basicTypeToString(paramType.type()));
variantMap.insert("index", paramType.index());
@ -777,7 +776,7 @@ QVariantMap JsonTypes::packVendor(const Vendor &vendor, const QLocale &locale)
QVariantMap variantMap;
variantMap.insert("id", vendor.id().toString());
variantMap.insert("name", vendor.name());
variantMap.insert("displayName", NymeaCore::instance()->deviceManager()->translator()->translate(plugin->pluginId(), vendor.displayName(), locale));
variantMap.insert("displayName", NymeaCore::instance()->deviceManager()->translate(plugin->pluginId(), vendor.displayName(), locale));
return variantMap;
}
@ -787,7 +786,7 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass, const QLo
QVariantMap variant;
variant.insert("id", deviceClass.id().toString());
variant.insert("name", deviceClass.name());
variant.insert("displayName", NymeaCore::instance()->deviceManager()->translator()->translate(deviceClass.pluginId(), deviceClass.displayName(), locale));
variant.insert("displayName", NymeaCore::instance()->deviceManager()->translate(deviceClass.pluginId(), deviceClass.displayName(), locale));
variant.insert("vendorId", deviceClass.vendorId().toString());
variant.insert("pluginId", deviceClass.pluginId().toString());
variant.insert("interfaces", deviceClass.interfaces());
@ -833,7 +832,7 @@ QVariantMap JsonTypes::packPlugin(DevicePlugin *plugin, const QLocale &locale)
QVariantMap pluginMap;
pluginMap.insert("id", plugin->pluginId().toString());
pluginMap.insert("name", plugin->pluginName());
pluginMap.insert("displayName", NymeaCore::instance()->deviceManager()->translator()->translate(plugin->pluginId(), plugin->pluginDisplayName(), locale));
pluginMap.insert("displayName", NymeaCore::instance()->deviceManager()->translate(plugin->pluginId(), plugin->pluginDisplayName(), locale));
QVariantList params;
foreach (const ParamType &param, plugin->configurationDescription())

View File

@ -23,12 +23,12 @@
#ifndef JSONTYPES_H
#define JSONTYPES_H
#include "plugin/devicedescriptor.h"
#include "rule.h"
#include "devicemanager.h"
#include "ruleengine.h"
#include "devices/devicedescriptor.h"
#include "devices/devicemanager.h"
#include "ruleengine/rule.h"
#include "ruleengine/ruleengine.h"
#include "nymeaconfiguration.h"
#include "usermanager.h"
#include "usermanager/usermanager.h"
#include "types/deviceclass.h"
#include "types/event.h"
@ -128,7 +128,7 @@ public:
DECLARE_TYPE(unit, "Unit", Types, Unit)
DECLARE_TYPE(createMethod, "CreateMethod", DeviceClass, CreateMethod)
DECLARE_TYPE(setupMethod, "SetupMethod", DeviceClass, SetupMethod)
DECLARE_TYPE(deviceError, "DeviceError", DeviceManager, DeviceError)
DECLARE_TYPE(deviceError, "DeviceError", Device, DeviceError)
DECLARE_TYPE(removePolicy, "RemovePolicy", RuleEngine, RemovePolicy)
DECLARE_TYPE(ruleError, "RuleError", RuleEngine, RuleError)
DECLARE_TYPE(loggingError, "LoggingError", Logging, LoggingError)

View File

@ -54,7 +54,7 @@
#include "ruleshandler.h"
#include "nymeacore.h"
#include "ruleengine.h"
#include "ruleengine/ruleengine.h"
#include "loggingcategories.h"
#include <QDebug>

View File

@ -67,13 +67,13 @@ JsonReply* StateHandler::GetStateType(const QVariantMap &params) const
foreach (const DeviceClass &deviceClass, NymeaCore::instance()->deviceManager()->supportedDevices()) {
foreach (const StateType &stateType, deviceClass.stateTypes()) {
if (stateType.id() == stateTypeId) {
QVariantMap data = statusToReply(DeviceManager::DeviceErrorNoError);
QVariantMap data = statusToReply(Device::DeviceErrorNoError);
data.insert("stateType", JsonTypes::packStateType(stateType, deviceClass.pluginId(), params.value("locale").toLocale()));
return createReply(data);
}
}
}
return createReply(statusToReply(DeviceManager::DeviceErrorStateTypeNotFound));
return createReply(statusToReply(Device::DeviceErrorStateTypeNotFound));
}
}

View File

@ -16,9 +16,11 @@ RESOURCES += $$top_srcdir/icons.qrc \
HEADERS += nymeacore.h \
ruleengine.h \
rule.h \
stateevaluator.h \
devices/devicemanagerimplementation.h \
devices/translator.h \
devices/stateevaluator.h \
ruleengine/ruleengine.h \
ruleengine/rule.h \
transportinterface.h \
nymeaconfiguration.h \
servermanager.h \
@ -67,13 +69,13 @@ HEADERS += nymeacore.h \
networkmanager/networksettings.h \
networkmanager/networkconnection.h \
networkmanager/wirednetworkdevice.h \
usermanager.h \
tokeninfo.h \
usermanager/usermanager.h \
usermanager/tokeninfo.h \
usermanager/pushbuttondbusservice.h \
certificategenerator.h \
cloud/awsconnector.h \
cloud/cloudmanager.h \
cloud/cloudnotifications.h \
pushbuttondbusservice.h \
hardwaremanagerimplementation.h \
hardware/plugintimermanagerimplementation.h \
hardware/radio433/radio433brennenstuhl.h \
@ -98,9 +100,11 @@ HEADERS += nymeacore.h \
jsonrpc/systemhandler.h
SOURCES += nymeacore.cpp \
ruleengine.cpp \
rule.cpp \
stateevaluator.cpp \
devices/devicemanagerimplementation.cpp \
devices/translator.cpp \
devices/stateevaluator.cpp \
ruleengine/ruleengine.cpp \
ruleengine/rule.cpp \
transportinterface.cpp \
nymeaconfiguration.cpp \
servermanager.cpp \
@ -147,13 +151,13 @@ SOURCES += nymeacore.cpp \
networkmanager/networksettings.cpp \
networkmanager/networkconnection.cpp \
networkmanager/wirednetworkdevice.cpp \
usermanager.cpp \
tokeninfo.cpp \
usermanager/usermanager.cpp \
usermanager/tokeninfo.cpp \
usermanager/pushbuttondbusservice.cpp \
certificategenerator.cpp \
cloud/awsconnector.cpp \
cloud/cloudmanager.cpp \
cloud/cloudnotifications.cpp \
pushbuttondbusservice.cpp \
hardwaremanagerimplementation.cpp \
hardware/plugintimermanagerimplementation.cpp \
hardware/radio433/radio433brennenstuhl.cpp \

View File

@ -26,7 +26,7 @@
#include "logfilter.h"
#include "types/event.h"
#include "types/action.h"
#include "rule.h"
#include "ruleengine/rule.h"
#include <QObject>
#include <QSqlDatabase>

View File

@ -50,9 +50,9 @@
This signal is emitted when the \l{ParamList}{Params} of a \a device have been changed.
*/
/*! \fn void nymeaserver::NymeaCore::actionExecuted(const ActionId &id, DeviceManager::DeviceError status);
/*! \fn void nymeaserver::NymeaCore::actionExecuted(const ActionId &id, Device::DeviceError status);
This signal is emitted when the \l{Action} with the given \a id is finished.
The \a status of the \l{Action} execution will be described as \l{DeviceManager::DeviceError}{DeviceError}.
The \a status of the \l{Action} execution will be described as \l{Device::DeviceError}{DeviceError}.
*/
/*! \fn void nymeaserver::NymeaCore::devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> deviceDescriptors);
@ -61,19 +61,19 @@
\sa DeviceManager::discoverDevices()
*/
/*! \fn void nymeaserver::NymeaCore::deviceSetupFinished(Device *device, DeviceManager::DeviceError status);
/*! \fn void nymeaserver::NymeaCore::deviceSetupFinished(Device *device, Device::DeviceError status);
This signal is emitted when the setup of a \a device is finished. The \a status parameter describes the
\l{DeviceManager::DeviceError}{DeviceError} that occurred.
\l{Device::DeviceError}{DeviceError} that occurred.
*/
/*! \fn void nymeaserver::NymeaCore::deviceReconfigurationFinished(Device *device, DeviceManager::DeviceError status);
/*! \fn void nymeaserver::NymeaCore::deviceReconfigurationFinished(Device *device, Device::DeviceError status);
This signal is emitted when the edit request of a \a device is finished. The \a status of the edit request will be
described as \l{DeviceManager::DeviceError}{DeviceError}.
described as \l{Device::DeviceError}{DeviceError}.
*/
/*! \fn void nymeaserver::NymeaCore::pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceError status, const DeviceId &deviceId);
/*! \fn void nymeaserver::NymeaCore::pairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceError status, const DeviceId &deviceId);
The DeviceManager will emit a this Signal when the pairing of a \l{Device} with the \a deviceId and \a pairingTransactionId is finished.
The \a status of the pairing will be described as \l{DeviceManager::DeviceError}{DeviceError}.
The \a status of the pairing will be described as \l{Device::DeviceError}{DeviceError}.
*/
/*! \fn void nymeaserver::NymeaCore::ruleRemoved(const RuleId &ruleId);
@ -108,14 +108,14 @@
#include "loggingcategories.h"
#include "platform/platform.h"
#include "jsonrpc/jsonrpcserver.h"
#include "ruleengine.h"
#include "ruleengine/ruleengine.h"
#include "networkmanager/networkmanager.h"
#include "nymeasettings.h"
#include "tagging/tagsstorage.h"
#include "platform/platform.h"
#include "devicemanager.h"
#include "plugin/device.h"
#include "devices/devicemanagerimplementation.h"
#include "devices/device.h"
#include "cloud/cloudnotifications.h"
#include "cloud/cloudtransport.h"
@ -167,7 +167,7 @@ void NymeaCore::init() {
m_hardwareManager = new HardwareManagerImplementation(m_platform, m_serverManager->mqttBroker(), this);
qCDebug(dcApplication) << "Creating Device Manager (locale:" << m_configuration->locale() << ")";
m_deviceManager = new DeviceManager(m_hardwareManager, m_configuration->locale(), this);
m_deviceManager = new DeviceManagerImplementation(m_hardwareManager, m_configuration->locale(), this);
qCDebug(dcApplication) << "Creating Rule Engine";
m_ruleEngine = new RuleEngine(this);
@ -192,27 +192,27 @@ void NymeaCore::init() {
connect(m_configuration, &NymeaConfiguration::serverNameChanged, m_serverManager, &ServerManager::setServerName);
connect(m_deviceManager, &DeviceManager::pluginConfigChanged, this, &NymeaCore::pluginConfigChanged);
connect(m_deviceManager, &DeviceManager::eventTriggered, this, &NymeaCore::gotEvent);
connect(m_deviceManager, &DeviceManager::deviceStateChanged, this, &NymeaCore::deviceStateChanged);
connect(m_deviceManager, &DeviceManager::deviceAdded, this, &NymeaCore::deviceAdded);
connect(m_deviceManager, &DeviceManager::deviceChanged, this, &NymeaCore::deviceChanged);
connect(m_deviceManager, &DeviceManager::deviceSettingChanged, this, &NymeaCore::deviceSettingChanged);
connect(m_deviceManager, &DeviceManager::deviceRemoved, this, &NymeaCore::deviceRemoved);
connect(m_deviceManager, &DeviceManager::deviceDisappeared, this, &NymeaCore::onDeviceDisappeared);
connect(m_deviceManager, &DeviceManager::actionExecutionFinished, this, &NymeaCore::actionExecutionFinished);
connect(m_deviceManager, &DeviceManager::devicesDiscovered, this, &NymeaCore::devicesDiscovered);
connect(m_deviceManager, &DeviceManager::deviceSetupFinished, this, &NymeaCore::deviceSetupFinished);
connect(m_deviceManager, &DeviceManager::deviceReconfigurationFinished, this, &NymeaCore::deviceReconfigurationFinished);
connect(m_deviceManager, &DeviceManager::pairingFinished, this, &NymeaCore::pairingFinished);
connect(m_deviceManager, &DeviceManager::loaded, this, &NymeaCore::deviceManagerLoaded);
connect(m_deviceManager, &DeviceManagerImplementation::pluginConfigChanged, this, &NymeaCore::pluginConfigChanged);
connect(m_deviceManager, &DeviceManagerImplementation::eventTriggered, this, &NymeaCore::gotEvent);
connect(m_deviceManager, &DeviceManagerImplementation::deviceStateChanged, this, &NymeaCore::deviceStateChanged);
connect(m_deviceManager, &DeviceManagerImplementation::deviceAdded, this, &NymeaCore::deviceAdded);
connect(m_deviceManager, &DeviceManagerImplementation::deviceChanged, this, &NymeaCore::deviceChanged);
connect(m_deviceManager, &DeviceManagerImplementation::deviceSettingChanged, this, &NymeaCore::deviceSettingChanged);
connect(m_deviceManager, &DeviceManagerImplementation::deviceRemoved, this, &NymeaCore::deviceRemoved);
connect(m_deviceManager, &DeviceManagerImplementation::deviceDisappeared, this, &NymeaCore::onDeviceDisappeared);
connect(m_deviceManager, &DeviceManagerImplementation::actionExecutionFinished, this, &NymeaCore::actionExecutionFinished);
connect(m_deviceManager, &DeviceManagerImplementation::devicesDiscovered, this, &NymeaCore::devicesDiscovered);
connect(m_deviceManager, &DeviceManagerImplementation::deviceSetupFinished, this, &NymeaCore::deviceSetupFinished);
connect(m_deviceManager, &DeviceManagerImplementation::deviceReconfigurationFinished, this, &NymeaCore::deviceReconfigurationFinished);
connect(m_deviceManager, &DeviceManagerImplementation::pairingFinished, this, &NymeaCore::pairingFinished);
connect(m_deviceManager, &DeviceManagerImplementation::loaded, this, &NymeaCore::deviceManagerLoaded);
connect(m_ruleEngine, &RuleEngine::ruleAdded, this, &NymeaCore::ruleAdded);
connect(m_ruleEngine, &RuleEngine::ruleRemoved, this, &NymeaCore::ruleRemoved);
connect(m_ruleEngine, &RuleEngine::ruleConfigurationChanged, this, &NymeaCore::ruleConfigurationChanged);
connect(m_timeManager, &TimeManager::dateTimeChanged, this, &NymeaCore::onDateTimeChanged);
connect(m_timeManager, &TimeManager::tick, m_deviceManager, &DeviceManager::timeTick);
connect(m_timeManager, &TimeManager::tick, m_deviceManager, &DeviceManagerImplementation::timeTick);
m_logger->logSystemEvent(m_timeManager->currentDateTime(), true);
}
@ -262,24 +262,24 @@ void NymeaCore::destroy()
}
/*! Removes a configured \l{Device} with the given \a deviceId and \a removePolicyList. */
QPair<DeviceManager::DeviceError, QList<RuleId> > NymeaCore::removeConfiguredDevice(const DeviceId &deviceId, const QHash<RuleId, RuleEngine::RemovePolicy> &removePolicyList)
QPair<Device::DeviceError, QList<RuleId> > NymeaCore::removeConfiguredDevice(const DeviceId &deviceId, const QHash<RuleId, RuleEngine::RemovePolicy> &removePolicyList)
{
Device *device = m_deviceManager->findConfiguredDevice(deviceId);
if (!device) {
return QPair<DeviceManager::DeviceError, QList<RuleId> > (DeviceManager::DeviceErrorDeviceNotFound, QList<RuleId>());
return QPair<Device::DeviceError, QList<RuleId> > (Device::DeviceErrorDeviceNotFound, QList<RuleId>());
}
// Check if this is a child device
if (!device->parentId().isNull()) {
qCWarning(dcDeviceManager) << "The device is a child of" << device->parentId().toString() << ". Please remove the parent device.";
return QPair<DeviceManager::DeviceError, QList<RuleId> > (DeviceManager::DeviceErrorDeviceIsChild, QList<RuleId>());
return QPair<Device::DeviceError, QList<RuleId> > (Device::DeviceErrorDeviceIsChild, QList<RuleId>());
}
// FIXME: Let's remove this for now. It will come back with more fine grained control, presumably introducing a RemoveMethod flag in the DeviceClass
// if (device->autoCreated()) {
// qCWarning(dcDeviceManager) << "This device has been auto-created and cannot be deleted manually.";
// return QPair<DeviceManager::DeviceError, QList<RuleId> >(DeviceManager::DeviceErrorCreationMethodNotSupported, {});
// return QPair<Device::DeviceError, QList<RuleId> >(Device::DeviceErrorCreationMethodNotSupported, {});
// }
// Check if this device has child devices
@ -326,7 +326,7 @@ QPair<DeviceManager::DeviceError, QList<RuleId> > NymeaCore::removeConfiguredDev
if (!unhandledRules.isEmpty()) {
qCWarning(dcDeviceManager) << "There are unhandled rules which depend on this device:\n" << unhandledRules;
return QPair<DeviceManager::DeviceError, QList<RuleId> > (DeviceManager::DeviceErrorDeviceInRule, unhandledRules);
return QPair<Device::DeviceError, QList<RuleId> > (Device::DeviceErrorDeviceInRule, unhandledRules);
}
// Update the rules...
@ -342,41 +342,41 @@ QPair<DeviceManager::DeviceError, QList<RuleId> > NymeaCore::removeConfiguredDev
// remove the child devices
foreach (Device *d, childDevices) {
DeviceManager::DeviceError removeError = m_deviceManager->removeConfiguredDevice(d->id());
if (removeError == DeviceManager::DeviceErrorNoError) {
Device::DeviceError removeError = m_deviceManager->removeConfiguredDevice(d->id());
if (removeError == Device::DeviceErrorNoError) {
m_logger->removeDeviceLogs(d->id());
}
}
// delete the devices
DeviceManager::DeviceError removeError = m_deviceManager->removeConfiguredDevice(deviceId);
if (removeError == DeviceManager::DeviceErrorNoError) {
Device::DeviceError removeError = m_deviceManager->removeConfiguredDevice(deviceId);
if (removeError == Device::DeviceErrorNoError) {
m_logger->removeDeviceLogs(deviceId);
}
return QPair<DeviceManager::DeviceError, QList<RuleId> > (DeviceManager::DeviceErrorNoError, QList<RuleId>());
return QPair<Device::DeviceError, QList<RuleId> > (Device::DeviceErrorNoError, QList<RuleId>());
}
/*! Removes a configured \l{Device} with the given \a deviceId and \a removePolicy. */
DeviceManager::DeviceError NymeaCore::removeConfiguredDevice(const DeviceId &deviceId, const RuleEngine::RemovePolicy &removePolicy)
Device::DeviceError NymeaCore::removeConfiguredDevice(const DeviceId &deviceId, const RuleEngine::RemovePolicy &removePolicy)
{
Device *device = m_deviceManager->findConfiguredDevice(deviceId);
if (!device) {
return DeviceManager::DeviceErrorDeviceNotFound;
return Device::DeviceErrorDeviceNotFound;
}
// Check if this is a child device
if (!device->parentId().isNull()) {
qCWarning(dcDeviceManager) << "The device is a child of" << device->parentId().toString() << ". Please remove the parent device.";
return DeviceManager::DeviceErrorDeviceIsChild;
return Device::DeviceErrorDeviceIsChild;
}
// FIXME: Let's remove this for now. It will come back with more fine grained control, presumably introducing a RemoveMethod flag in the DeviceClass
// if (device->autoCreated()) {
// qCWarning(dcDeviceManager) << "This device has been auto-created and cannot be deleted manually.";
// return DeviceManager::DeviceErrorCreationMethodNotSupported;
// return Device::DeviceErrorCreationMethodNotSupported;
// }
// Check if this device has child devices
@ -417,15 +417,15 @@ DeviceManager::DeviceError NymeaCore::removeConfiguredDevice(const DeviceId &dev
// remove the child devices
foreach (Device *d, childDevices) {
DeviceManager::DeviceError removeError = m_deviceManager->removeConfiguredDevice(d->id());
if (removeError == DeviceManager::DeviceErrorNoError) {
Device::DeviceError removeError = m_deviceManager->removeConfiguredDevice(d->id());
if (removeError == Device::DeviceErrorNoError) {
m_logger->removeDeviceLogs(d->id());
}
}
// delete the devices
DeviceManager::DeviceError removeError = m_deviceManager->removeConfiguredDevice(deviceId);
if (removeError == DeviceManager::DeviceErrorNoError) {
Device::DeviceError removeError = m_deviceManager->removeConfiguredDevice(deviceId);
if (removeError == Device::DeviceErrorNoError) {
m_logger->removeDeviceLogs(deviceId);
}
@ -434,12 +434,12 @@ DeviceManager::DeviceError NymeaCore::removeConfiguredDevice(const DeviceId &dev
/*! Calls the metheod DeviceManager::executeAction(\a action).
* \sa DeviceManager::executeAction(), */
DeviceManager::DeviceError NymeaCore::executeAction(const Action &action)
Device::DeviceError NymeaCore::executeAction(const Action &action)
{
DeviceManager::DeviceError ret = m_deviceManager->executeAction(action);
if (ret == DeviceManager::DeviceErrorNoError) {
Device::DeviceError ret = m_deviceManager->executeAction(action);
if (ret == Device::DeviceErrorNoError) {
m_logger->logAction(action);
} else if (ret == DeviceManager::DeviceErrorAsync) {
} else if (ret == Device::DeviceErrorAsync) {
m_pendingActions.insert(action.id(), action);
} else {
m_logger->logAction(action, Logging::LoggingLevelAlert, ret);
@ -534,25 +534,25 @@ void NymeaCore::executeRuleActions(const QList<RuleAction> ruleActions)
foreach (const Action &action, actions) {
qCDebug(dcRuleEngine) << "Executing action" << action.actionTypeId() << action.params();
DeviceManager::DeviceError status = executeAction(action);
Device::DeviceError status = executeAction(action);
switch(status) {
case DeviceManager::DeviceErrorNoError:
case Device::DeviceErrorNoError:
break;
case DeviceManager::DeviceErrorSetupFailed:
case Device::DeviceErrorSetupFailed:
qCWarning(dcRuleEngine) << "Error executing action. Device setup failed.";
break;
case DeviceManager::DeviceErrorAsync:
case Device::DeviceErrorAsync:
qCDebug(dcRuleEngine) << "Executing asynchronous action.";
break;
case DeviceManager::DeviceErrorInvalidParameter:
case Device::DeviceErrorInvalidParameter:
qCWarning(dcRuleEngine) << "Error executing action. Invalid action parameter.";
break;
default:
qCWarning(dcRuleEngine) << "Error executing action:" << status;
}
// if (status != DeviceManager::DeviceErrorAsync)
// m_logger->logAction(action, status == DeviceManager::DeviceErrorNoError ? Logging::LoggingLevelInfo : Logging::LoggingLevelAlert, status);
// if (status != Device::DeviceErrorAsync)
// m_logger->logAction(action, status == Device::DeviceErrorNoError ? Logging::LoggingLevelInfo : Logging::LoggingLevelAlert, status);
}
}
@ -790,11 +790,11 @@ RestServer *NymeaCore::restServer() const
return m_serverManager->restServer();
}
void NymeaCore::actionExecutionFinished(const ActionId &id, DeviceManager::DeviceError status)
void NymeaCore::actionExecutionFinished(const ActionId &id, Device::DeviceError status)
{
emit actionExecuted(id, status);
Action action = m_pendingActions.take(id);
m_logger->logAction(action, status == DeviceManager::DeviceErrorNoError ? Logging::LoggingLevelInfo : Logging::LoggingLevelAlert, status);
m_logger->logAction(action, status == Device::DeviceErrorNoError ? Logging::LoggingLevelInfo : Logging::LoggingLevelAlert, status);
}
void NymeaCore::onDeviceDisappeared(const DeviceId &deviceId)
@ -838,15 +838,15 @@ void NymeaCore::onDeviceDisappeared(const DeviceId &deviceId)
// remove the child devices
foreach (Device *d, childDevices) {
DeviceManager::DeviceError removeError = m_deviceManager->removeConfiguredDevice(d->id());
if (removeError == DeviceManager::DeviceErrorNoError) {
Device::DeviceError removeError = m_deviceManager->removeConfiguredDevice(d->id());
if (removeError == Device::DeviceErrorNoError) {
m_logger->removeDeviceLogs(d->id());
}
}
// delete the device
DeviceManager::DeviceError removeError = m_deviceManager->removeConfiguredDevice(deviceId);
if (removeError == DeviceManager::DeviceErrorNoError) {
Device::DeviceError removeError = m_deviceManager->removeConfiguredDevice(deviceId);
if (removeError == Device::DeviceErrorNoError) {
m_logger->removeDeviceLogs(deviceId);
}
}

View File

@ -22,15 +22,16 @@
#ifndef NYMEACORE_H
#define NYMEACORE_H
#include "rule.h"
#include "types/event.h"
#include "types/deviceclass.h"
#include "plugin/deviceplugin.h"
#include "plugin/devicedescriptor.h"
#include "devices/deviceplugin.h"
#include "devices/devicedescriptor.h"
#include "devices/devicemanagerimplementation.h"
#include "ruleengine/rule.h"
#include "ruleengine/ruleengine.h"
#include "logging/logengine.h"
#include "devicemanager.h"
#include "ruleengine.h"
#include "servermanager.h"
#include "cloud/cloudmanager.h"
@ -67,10 +68,10 @@ public:
void destroy();
// Device handling
QPair<DeviceManager::DeviceError, QList<RuleId> >removeConfiguredDevice(const DeviceId &deviceId, const QHash<RuleId, RuleEngine::RemovePolicy> &removePolicyList);
DeviceManager::DeviceError removeConfiguredDevice(const DeviceId &deviceId, const RuleEngine::RemovePolicy &removePolicy);
QPair<Device::DeviceError, QList<RuleId> >removeConfiguredDevice(const DeviceId &deviceId, const QHash<RuleId, RuleEngine::RemovePolicy> &removePolicyList);
Device::DeviceError removeConfiguredDevice(const DeviceId &deviceId, const RuleEngine::RemovePolicy &removePolicy);
DeviceManager::DeviceError executeAction(const Action &action);
Device::DeviceError executeAction(const Action &action);
void executeRuleActions(const QList<RuleAction> ruleActions);
@ -104,12 +105,12 @@ signals:
void deviceAdded(Device *device);
void deviceChanged(Device *device);
void deviceSettingChanged(const DeviceId deviceId, const ParamTypeId &settingParamTypeId, const QVariant &value);
void actionExecuted(const ActionId &id, DeviceManager::DeviceError status);
void actionExecuted(const ActionId &id, Device::DeviceError status);
void devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> deviceDescriptors);
void deviceSetupFinished(Device *device, DeviceManager::DeviceError status);
void deviceReconfigurationFinished(Device *device, DeviceManager::DeviceError status);
void pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceError status, const DeviceId &deviceId);
void deviceSetupFinished(Device *device, Device::DeviceError status);
void deviceReconfigurationFinished(Device *device, Device::DeviceError status);
void pairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceError status, const DeviceId &deviceId);
void ruleRemoved(const RuleId &ruleId);
void ruleAdded(const Rule &rule);
@ -124,7 +125,7 @@ private:
NymeaConfiguration *m_configuration;
ServerManager *m_serverManager;
DeviceManager *m_deviceManager;
DeviceManagerImplementation *m_deviceManager;
RuleEngine *m_ruleEngine;
LogEngine *m_logger;
TimeManager *m_timeManager;
@ -143,7 +144,7 @@ private:
private slots:
void gotEvent(const Event &event);
void onDateTimeChanged(const QDateTime &dateTime);
void actionExecutionFinished(const ActionId &id, DeviceManager::DeviceError status);
void actionExecutionFinished(const ActionId &id, Device::DeviceError status);
void onDeviceDisappeared(const DeviceId &deviceId);
void deviceManagerLoaded();

View File

@ -25,7 +25,7 @@
#include "types/state.h"
#include "types/ruleaction.h"
#include "types/eventdescriptor.h"
#include "stateevaluator.h"
#include "devices/stateevaluator.h"
#include "time/timedescriptor.h"
#include <QUuid>

View File

@ -110,8 +110,8 @@
#include "types/eventdescriptor.h"
#include "types/paramdescriptor.h"
#include "nymeasettings.h"
#include "devicemanager.h"
#include "plugin/device.h"
#include "devices/devicemanager.h"
#include "devices/device.h"
#include <QDebug>
#include <QStringList>

View File

@ -25,7 +25,7 @@
#include "rule.h"
#include "types/event.h"
#include "types/deviceclass.h"
#include "stateevaluator.h"
#include "devices/stateevaluator.h"
#include <QObject>
#include <QList>

View File

@ -74,12 +74,12 @@ HttpReply *DeviceClassesResource::proccessRequest(const HttpRequest &request, co
DeviceClassId deviceClassId = DeviceClassId(urlTokens.at(3));
if (deviceClassId.isNull()) {
qCWarning(dcRest) << "Could not parse DeviceClassId:" << urlTokens.at(3);
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorDeviceClassNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorDeviceClassNotFound);
}
m_deviceClass = NymeaCore::instance()->deviceManager()->findDeviceClass(deviceClassId);
if (!m_deviceClass.isValid()) {
qCWarning(dcRest) << "DeviceClassId" << deviceClassId.toString() << "not found";
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorDeviceClassNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorDeviceClassNotFound);
}
}
@ -108,7 +108,7 @@ HttpReply *DeviceClassesResource::proccessGetRequest(const HttpRequest &request,
vendorId = VendorId(request.urlQuery().queryItemValue("vendorId"));
if (vendorId.isNull()) {
qCWarning(dcRest) << "Could not parse VendorId:" << request.urlQuery().queryItemValue("vendorId");
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorVendorNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorVendorNotFound);
}
}
}
@ -128,7 +128,7 @@ HttpReply *DeviceClassesResource::proccessGetRequest(const HttpRequest &request,
ActionTypeId actionTypeId = ActionTypeId(urlTokens.at(5));
if (actionTypeId.isNull()) {
qCWarning(dcRest) << "Could not parse ActionTypeId:" << urlTokens.at(5);
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorActionTypeNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorActionTypeNotFound);
}
return getActionType(actionTypeId);
}
@ -142,7 +142,7 @@ HttpReply *DeviceClassesResource::proccessGetRequest(const HttpRequest &request,
StateTypeId stateTypeId = StateTypeId(urlTokens.at(5));
if (stateTypeId.isNull()) {
qCWarning(dcRest) << "Could not parse StateTypeId:" << urlTokens.at(5);
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorStateTypeNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorStateTypeNotFound);
}
return getStateType(stateTypeId);
}
@ -156,7 +156,7 @@ HttpReply *DeviceClassesResource::proccessGetRequest(const HttpRequest &request,
EventTypeId eventTypeId = EventTypeId(urlTokens.at(5));
if (eventTypeId.isNull()) {
qCWarning(dcRest) << "Could not parse EventTypeId:" << urlTokens.at(5);
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorEventTypeNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorEventTypeNotFound);
}
return getEventType(eventTypeId);
}
@ -209,7 +209,7 @@ HttpReply *DeviceClassesResource::getActionType(const ActionTypeId &actionTypeId
return reply;
}
}
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorActionTypeNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorActionTypeNotFound);
}
HttpReply *DeviceClassesResource::getStateTypes()
@ -233,7 +233,7 @@ HttpReply *DeviceClassesResource::getStateType(const StateTypeId &stateTypeId)
return reply;
}
}
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorStateTypeNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorStateTypeNotFound);
}
HttpReply *DeviceClassesResource::getEventTypes()
@ -257,7 +257,7 @@ HttpReply *DeviceClassesResource::getEventType(const EventTypeId &eventTypeId)
return reply;
}
}
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorEventTypeNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorEventTypeNotFound);
}
HttpReply *DeviceClassesResource::getDiscoverdDevices(const ParamList &discoveryParams)
@ -265,15 +265,15 @@ HttpReply *DeviceClassesResource::getDiscoverdDevices(const ParamList &discovery
qCDebug(dcRest) << "Discover devices for DeviceClass" << m_deviceClass.id();
qCDebug(dcRest) << discoveryParams;
DeviceManager::DeviceError status = NymeaCore::instance()->deviceManager()->discoverDevices(m_deviceClass.id(), discoveryParams);
Device::DeviceError status = NymeaCore::instance()->deviceManager()->discoverDevices(m_deviceClass.id(), discoveryParams);
if (status == DeviceManager::DeviceErrorAsync) {
if (status == Device::DeviceErrorAsync) {
HttpReply *reply = createAsyncReply();
m_discoverRequests.insert(m_deviceClass.id(), reply);
return reply;
}
if (status != DeviceManager::DeviceErrorNoError)
if (status != Device::DeviceErrorNoError)
return createDeviceErrorReply(HttpReply::InternalServerError, status);
return createSuccessReply();

View File

@ -23,6 +23,7 @@
#include <QObject>
#include <QHash>
#include <QPointer>
#include "jsonrpc/jsontypes.h"
#include "restresource.h"
@ -33,7 +34,7 @@ namespace nymeaserver {
class HttpRequest;
class DeviceClassesResource : public RestResource
class DeviceClassesResource: public RestResource
{
Q_OBJECT
public:
@ -69,7 +70,6 @@ private:
private slots:
void devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> deviceDescriptors);
};
}

View File

@ -41,7 +41,6 @@
#include "servers/httprequest.h"
#include "jsonrpc/jsontypes.h"
#include "nymeacore.h"
#include "translator.h"
#include <QJsonDocument>
@ -80,12 +79,12 @@ HttpReply *DevicesResource::proccessRequest(const HttpRequest &request, const QS
DeviceId deviceId = DeviceId(urlTokens.at(3));
if (deviceId.isNull()) {
qCWarning(dcRest) << "Could not parse DeviceId:" << urlTokens.at(3);
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorDeviceNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorDeviceNotFound);
}
m_device = NymeaCore::instance()->deviceManager()->findConfiguredDevice(deviceId);
if (!m_device) {
qCWarning(dcRest) << "Could find any device with DeviceId:" << urlTokens.at(3);
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorDeviceNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorDeviceNotFound);
}
}
@ -135,12 +134,12 @@ HttpReply *DevicesResource::proccessGetRequest(const HttpRequest &request, const
StateTypeId stateTypeId = StateTypeId(urlTokens.at(5));
if (stateTypeId.isNull()) {
qCWarning(dcRest) << "Could not parse StateTypeId:" << urlTokens.at(5);
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorStateTypeNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorStateTypeNotFound);
}
if (!m_device->hasState(stateTypeId)){
qCWarning(dcRest) << "This device has no StateTypeId:" << urlTokens.at(5);
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorStateTypeNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorStateTypeNotFound);
}
return getDeviceStateValue(m_device, stateTypeId);
}
@ -210,7 +209,7 @@ HttpReply *DevicesResource::proccessPostRequest(const HttpRequest &request, cons
ActionTypeId actionTypeId = ActionTypeId(urlTokens.at(5));
if (actionTypeId.isNull()) {
qCWarning(dcRest) << "Could not parse ActionTypeId:" << urlTokens.at(5);
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorActionTypeNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorActionTypeNotFound);
}
bool found = false;
DeviceClass deviceClass = NymeaCore::instance()->deviceManager()->findDeviceClass(m_device->deviceClassId());
@ -222,7 +221,7 @@ HttpReply *DevicesResource::proccessPostRequest(const HttpRequest &request, cons
}
if (!found) {
qCWarning(dcRest) << "Could not find ActionTypeId:" << actionTypeId.toString();
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorActionTypeNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorActionTypeNotFound);
}
return executeAction(m_device, actionTypeId, request.payload());
@ -284,7 +283,7 @@ HttpReply *DevicesResource::removeDevice(Device *device, const QVariantMap &para
// global removePolicy has priority
if (params.contains("removePolicy")) {
RuleEngine::RemovePolicy removePolicy = params.value("removePolicy").toString() == "RemovePolicyCascade" ? RuleEngine::RemovePolicyCascade : RuleEngine::RemovePolicyUpdate;
DeviceManager::DeviceError result = NymeaCore::instance()->removeConfiguredDevice(device->id(), removePolicy);
Device::DeviceError result = NymeaCore::instance()->removeConfiguredDevice(device->id(), removePolicy);
return createDeviceErrorReply(HttpReply::Ok, result);
}
@ -295,7 +294,7 @@ HttpReply *DevicesResource::removeDevice(Device *device, const QVariantMap &para
removePolicyList.insert(ruleId, policy);
}
QPair<DeviceManager::DeviceError, QList<RuleId> > status = NymeaCore::instance()->removeConfiguredDevice(device->id(), removePolicyList);
QPair<Device::DeviceError, QList<RuleId> > status = NymeaCore::instance()->removeConfiguredDevice(device->id(), removePolicyList);
// if there are offending rules
if (!status.second.isEmpty()) {
@ -314,7 +313,7 @@ HttpReply *DevicesResource::removeDevice(Device *device, const QVariantMap &para
return reply;
}
if (status.first == DeviceManager::DeviceErrorNoError)
if (status.first == Device::DeviceErrorNoError)
return createDeviceErrorReply(HttpReply::Ok, status.first);
return createDeviceErrorReply(HttpReply::BadRequest, status.first);
@ -338,14 +337,14 @@ HttpReply *DevicesResource::executeAction(Device *device, const ActionTypeId &ac
Action action(actionTypeId, device->id());
action.setParams(actionParams);
DeviceManager::DeviceError status = NymeaCore::instance()->executeAction(action);
if (status == DeviceManager::DeviceErrorAsync) {
Device::DeviceError status = NymeaCore::instance()->executeAction(action);
if (status == Device::DeviceErrorAsync) {
HttpReply *reply = createAsyncReply();
m_asyncActionExecutions.insert(action.id(), reply);
return reply;
}
if (status != DeviceManager::DeviceErrorNoError)
if (status != Device::DeviceErrorNoError)
return createDeviceErrorReply(HttpReply::InternalServerError, status);
return createDeviceErrorReply(HttpReply::Ok, status);
@ -361,14 +360,14 @@ HttpReply *DevicesResource::addConfiguredDevice(const QByteArray &payload) const
DeviceClassId deviceClassId(params.value("deviceClassId").toString());
if (deviceClassId.isNull())
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorDeviceClassNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorDeviceClassNotFound);
QString deviceName = params.value("name").toString();
DeviceId newDeviceId = DeviceId::createDeviceId();
ParamList deviceParams = JsonTypes::unpackParams(params.value("deviceParams").toList());
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
DeviceManager::DeviceError status;
Device::DeviceError status;
if (deviceDescriptorId.isNull()) {
qCDebug(dcRest) << "Adding device" << deviceName << "with" << deviceParams;
status = NymeaCore::instance()->deviceManager()->addConfiguredDevice(deviceClassId, deviceName, deviceParams, newDeviceId);
@ -376,14 +375,14 @@ HttpReply *DevicesResource::addConfiguredDevice(const QByteArray &payload) const
qCDebug(dcRest) << "Adding discovered device" << deviceName << "with DeviceDescriptorId" << deviceDescriptorId.toString();
status = NymeaCore::instance()->deviceManager()->addConfiguredDevice(deviceClassId, deviceName, deviceDescriptorId, deviceParams, newDeviceId);
}
if (status == DeviceManager::DeviceErrorAsync) {
if (status == Device::DeviceErrorAsync) {
HttpReply *reply = createAsyncReply();
qCDebug(dcRest) << "Device setup async reply";
m_asyncDeviceAdditions.insert(newDeviceId, reply);
return reply;
}
if (status != DeviceManager::DeviceErrorNoError)
if (status != Device::DeviceErrorNoError)
return createDeviceErrorReply(HttpReply::InternalServerError, status);
QVariant result = JsonTypes::packDevice(NymeaCore::instance()->deviceManager()->findConfiguredDevice(newDeviceId));
@ -401,9 +400,9 @@ HttpReply *DevicesResource::editDevice(const QByteArray &payload) const
QVariantMap params = verification.second.toMap();
QString name = params.value("name").toString();
DeviceManager::DeviceError status = NymeaCore::instance()->deviceManager()->editDevice(m_device->id(), name);
Device::DeviceError status = NymeaCore::instance()->deviceManager()->editDevice(m_device->id(), name);
if (status != DeviceManager::DeviceErrorNoError)
if (status != Device::DeviceErrorNoError)
return createDeviceErrorReply(HttpReply::BadRequest, status);
return createDeviceErrorReply(HttpReply::Ok, status);
@ -422,14 +421,14 @@ HttpReply *DevicesResource::pairDevice(const QByteArray &payload) const
if (deviceClassId.isNull()) {
qCWarning(dcRest) << "Could not find deviceClassId" << params.value("deviceClassId").toString();
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorDeviceClassNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorDeviceClassNotFound);
}
QString deviceName = params.value("name").toString();
qCDebug(dcRest) << "Pair device" << deviceName << "with deviceClassId" << deviceClassId.toString();
DeviceManager::DeviceError status;
Device::DeviceError status;
PairingTransactionId pairingTransactionId = PairingTransactionId::createPairingTransactionId();
if (params.contains("deviceDescriptorId")) {
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
@ -439,11 +438,11 @@ HttpReply *DevicesResource::pairDevice(const QByteArray &payload) const
status = NymeaCore::instance()->deviceManager()->pairDevice(pairingTransactionId, deviceClassId, deviceName, deviceParams);
}
if (status != DeviceManager::DeviceErrorNoError)
if (status != Device::DeviceErrorNoError)
return createDeviceErrorReply(HttpReply::BadRequest, status);
QVariantMap returns;
returns.insert("displayMessage", NymeaCore::instance()->deviceManager()->translator()->translate(deviceClass.pluginId(), deviceClass.pairingInfo(), NymeaCore::instance()->configuration()->locale()));
returns.insert("displayMessage", NymeaCore::instance()->deviceManager()->translate(deviceClass.pluginId(), deviceClass.pairingInfo(), NymeaCore::instance()->configuration()->locale()));
returns.insert("pairingTransactionId", pairingTransactionId.toString());
returns.insert("setupMethod", JsonTypes::setupMethod().at(deviceClass.setupMethod()));
HttpReply *reply = createSuccessReply();
@ -462,19 +461,19 @@ HttpReply *DevicesResource::confirmPairDevice(const QByteArray &payload) const
PairingTransactionId pairingTransactionId = PairingTransactionId(params.value("pairingTransactionId").toString());
QString secret = params.value("secret").toString();
DeviceManager::DeviceError status = NymeaCore::instance()->deviceManager()->confirmPairing(pairingTransactionId, secret);
Device::DeviceError status = NymeaCore::instance()->deviceManager()->confirmPairing(pairingTransactionId, secret);
if (status == DeviceManager::DeviceErrorAsync) {
if (status == Device::DeviceErrorAsync) {
HttpReply *reply = createAsyncReply();
qCDebug(dcRest) << "Confirm pairing async reply";
m_asyncPairingRequests.insert(pairingTransactionId, reply);
return reply;
}
if (status != DeviceManager::DeviceErrorNoError)
if (status != Device::DeviceErrorNoError)
return createDeviceErrorReply(HttpReply::InternalServerError, status);
return createDeviceErrorReply(HttpReply::Ok, DeviceManager::DeviceErrorNoError);
return createDeviceErrorReply(HttpReply::Ok, Device::DeviceErrorNoError);
}
HttpReply *DevicesResource::reconfigureDevice(Device *device, const QByteArray &payload) const
@ -487,7 +486,7 @@ HttpReply *DevicesResource::reconfigureDevice(Device *device, const QByteArray &
QVariantMap params = verification.second.toMap();
ParamList deviceParams = JsonTypes::unpackParams(params.value("deviceParams").toList());
DeviceManager::DeviceError status;
Device::DeviceError status;
DeviceDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
if (deviceDescriptorId.isNull()) {
qCDebug(dcRest) << "Reconfigure device with params:" << deviceParams;
@ -497,20 +496,20 @@ HttpReply *DevicesResource::reconfigureDevice(Device *device, const QByteArray &
status = NymeaCore::instance()->deviceManager()->reconfigureDevice(device->id(), deviceDescriptorId);
}
if (status == DeviceManager::DeviceErrorAsync) {
if (status == Device::DeviceErrorAsync) {
HttpReply *reply = createAsyncReply();
qCDebug(dcRest) << "Device reconfiguration async reply";
m_asyncReconfigureDevice.insert(device, reply);
return reply;
}
if (status != DeviceManager::DeviceErrorNoError)
if (status != Device::DeviceErrorNoError)
return createDeviceErrorReply(HttpReply::InternalServerError, status);
return createDeviceErrorReply(HttpReply::Ok, DeviceManager::DeviceErrorNoError);
return createDeviceErrorReply(HttpReply::Ok, Device::DeviceErrorNoError);
}
void DevicesResource::actionExecuted(const ActionId &actionId, DeviceManager::DeviceError status)
void DevicesResource::actionExecuted(const ActionId &actionId, Device::DeviceError status)
{
if (!m_asyncActionExecutions.contains(actionId))
return; // Not the action we are waiting for.
@ -525,7 +524,7 @@ void DevicesResource::actionExecuted(const ActionId &actionId, DeviceManager::De
HttpReply *reply = m_asyncActionExecutions.take(actionId);
reply->setHeader(HttpReply::ContentTypeHeader, "application/json; charset=\"utf-8\";");
if (status == DeviceManager::DeviceErrorNoError) {
if (status == Device::DeviceErrorNoError) {
qCDebug(dcRest) << "Action execution finished successfully";
reply->setHttpStatusCode(HttpReply::Ok);
reply->setPayload(QJsonDocument::fromVariant(response).toJson());
@ -540,7 +539,7 @@ void DevicesResource::actionExecuted(const ActionId &actionId, DeviceManager::De
reply->finished();
}
void DevicesResource::deviceSetupFinished(Device *device, DeviceManager::DeviceError status)
void DevicesResource::deviceSetupFinished(Device *device, Device::DeviceError status)
{
if (!m_asyncDeviceAdditions.contains(device->id()))
return; // Not the device we are waiting for.
@ -555,7 +554,7 @@ void DevicesResource::deviceSetupFinished(Device *device, DeviceManager::DeviceE
HttpReply *reply = m_asyncDeviceAdditions.take(device->id());
reply->setHeader(HttpReply::ContentTypeHeader, "application/json; charset=\"utf-8\";");
if (status == DeviceManager::DeviceErrorNoError) {
if (status == Device::DeviceErrorNoError) {
qCDebug(dcRest) << "Device setup finished successfully";
reply->setHttpStatusCode(HttpReply::Ok);
reply->setPayload(QJsonDocument::fromVariant(response).toJson());
@ -571,7 +570,7 @@ void DevicesResource::deviceSetupFinished(Device *device, DeviceManager::DeviceE
reply->finished();
}
void DevicesResource::deviceReconfigurationFinished(Device *device, DeviceManager::DeviceError status)
void DevicesResource::deviceReconfigurationFinished(Device *device, Device::DeviceError status)
{
if (!m_asyncReconfigureDevice.contains(device))
return; // Not the device we are waiting for.
@ -586,7 +585,7 @@ void DevicesResource::deviceReconfigurationFinished(Device *device, DeviceManage
HttpReply *reply = m_asyncReconfigureDevice.take(device);
reply->setHeader(HttpReply::ContentTypeHeader, "application/json; charset=\"utf-8\";");
if (status == DeviceManager::DeviceErrorNoError) {
if (status == Device::DeviceErrorNoError) {
qCDebug(dcRest) << "Device reconfiguration finished successfully";
reply->setHttpStatusCode(HttpReply::Ok);
reply->setPayload(QJsonDocument::fromVariant(response).toJson());
@ -599,7 +598,7 @@ void DevicesResource::deviceReconfigurationFinished(Device *device, DeviceManage
reply->finished();
}
void DevicesResource::pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceError status, const DeviceId &deviceId)
void DevicesResource::pairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceError status, const DeviceId &deviceId)
{
if (!m_asyncPairingRequests.contains(pairingTransactionId))
return; // Not the device pairing we are waiting for.
@ -613,7 +612,7 @@ void DevicesResource::pairingFinished(const PairingTransactionId &pairingTransac
}
HttpReply *reply = m_asyncPairingRequests.take(pairingTransactionId);
if (status != DeviceManager::DeviceErrorNoError) {
if (status != Device::DeviceErrorNoError) {
qCDebug(dcRest) << "Pairing device finished with error.";
reply->setHeader(HttpReply::ContentTypeHeader, "application/json; charset=\"utf-8\";");
reply->setHttpStatusCode(HttpReply::InternalServerError);

View File

@ -23,6 +23,7 @@
#include <QObject>
#include <QHash>
#include <QPointer>
#include "jsonrpc/jsontypes.h"
#include "restresource.h"
@ -36,7 +37,7 @@ class DevicesResource: public RestResource
{
Q_OBJECT
public:
explicit DevicesResource(QObject *parent = 0);
explicit DevicesResource(QObject *parent = nullptr);
QString name() const override;
@ -77,10 +78,10 @@ private:
HttpReply *reconfigureDevice(Device *device, const QByteArray &payload) const;
private slots:
void actionExecuted(const ActionId &actionId, DeviceManager::DeviceError status);
void deviceSetupFinished(Device *device, DeviceManager::DeviceError status);
void deviceReconfigurationFinished(Device *device, DeviceManager::DeviceError status);
void pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceError status, const DeviceId &deviceId);
void actionExecuted(const ActionId &actionId, Device::DeviceError status);
void deviceSetupFinished(Device *device, Device::DeviceError status);
void deviceReconfigurationFinished(Device *device, Device::DeviceError status);
void pairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceError status, const DeviceId &deviceId);
};
}

View File

@ -74,7 +74,7 @@ HttpReply *PluginsResource::proccessRequest(const HttpRequest &request, const QS
m_pluginId = PluginId(urlTokens.at(3));
if (m_pluginId.isNull()) {
qCWarning(dcRest) << "Could not parse PluginId:" << urlTokens.at(3);
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorPluginNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorPluginNotFound);
}
}
@ -154,7 +154,7 @@ HttpReply *PluginsResource::getPlugin(const PluginId &pluginId) const
return reply;
}
}
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorPluginNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorPluginNotFound);
}
HttpReply *PluginsResource::getPluginConfiguration(const PluginId &pluginId) const
@ -164,7 +164,7 @@ HttpReply *PluginsResource::getPluginConfiguration(const PluginId &pluginId) con
DevicePlugin *plugin = 0;
plugin = findPlugin(pluginId);
if (!plugin)
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorPluginNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorPluginNotFound);
QVariantList configurationParamsList;
foreach (const Param &param, plugin->configuration()) {
@ -182,7 +182,7 @@ HttpReply *PluginsResource::setPluginConfiguration(const PluginId &pluginId, con
DevicePlugin *plugin = 0;
plugin = findPlugin(pluginId);
if (!plugin)
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorPluginNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorPluginNotFound);
qCDebug(dcRest) << "Set configuration of plugin with id" << pluginId.toString();
@ -193,9 +193,9 @@ HttpReply *PluginsResource::setPluginConfiguration(const PluginId &pluginId, con
QVariantList configuration = verification.second.toList();
ParamList pluginParams = JsonTypes::unpackParams(configuration);
qCDebug(dcRest) << pluginParams;
DeviceManager::DeviceError result = NymeaCore::instance()->deviceManager()->setPluginConfig(pluginId, pluginParams);
Device::DeviceError result = NymeaCore::instance()->deviceManager()->setPluginConfig(pluginId, pluginParams);
if (result != DeviceManager::DeviceErrorNoError)
if (result != Device::DeviceErrorNoError)
return createDeviceErrorReply(HttpReply::BadRequest, result);
return createDeviceErrorReply(HttpReply::Ok, result);

View File

@ -60,7 +60,7 @@
#include "restresource.h"
#include "servers/httprequest.h"
#include "loggingcategories.h"
#include "devicemanager.h"
#include "devices/devicemanager.h"
#include <QJsonDocument>
#include <QVariant>
@ -107,7 +107,7 @@ HttpReply *RestResource::createErrorReply(const HttpReply::HttpStatusCode &statu
}
/*! Returns the pointer to a new created error \l{HttpReply} initialized with the given \a statusCode, \l{HttpReply::TypeSync} and the \a deviceError. */
HttpReply *RestResource::createDeviceErrorReply(const HttpReply::HttpStatusCode &statusCode, const DeviceManager::DeviceError &deviceError)
HttpReply *RestResource::createDeviceErrorReply(const HttpReply::HttpStatusCode &statusCode, const Device::DeviceError &deviceError)
{
HttpReply *reply = new HttpReply(statusCode, HttpReply::TypeSync);
QVariantMap response;

View File

@ -46,7 +46,7 @@ public:
static HttpReply *createSuccessReply();
static HttpReply *createCorsSuccessReply();
static HttpReply *createErrorReply(const HttpReply::HttpStatusCode &statusCode);
static HttpReply *createDeviceErrorReply(const HttpReply::HttpStatusCode &statusCode, const DeviceManager::DeviceError &deviceError);
static HttpReply *createDeviceErrorReply(const HttpReply::HttpStatusCode &statusCode, const Device::DeviceError &deviceError);
static HttpReply *createRuleErrorReply(const HttpReply::HttpStatusCode &statusCode, const RuleEngine::RuleError &ruleError);
static HttpReply *createLoggingErrorReply(const HttpReply::HttpStatusCode &statusCode, const Logging::LoggingError &loggingError);
static HttpReply *createAsyncReply();

View File

@ -72,7 +72,7 @@ HttpReply *VendorsResource::proccessRequest(const HttpRequest &request, const QS
m_vendorId = VendorId(urlTokens.at(3));
if (m_vendorId.isNull()) {
qCWarning(dcRest) << "Could not parse VendorId:" << urlTokens.at(3);
return createDeviceErrorReply(HttpReply::BadRequest, DeviceManager::DeviceErrorVendorNotFound);
return createDeviceErrorReply(HttpReply::BadRequest, Device::DeviceErrorVendorNotFound);
}
}
@ -129,7 +129,7 @@ HttpReply *VendorsResource::getVendor(const VendorId &vendorId) const
return reply;
}
}
return createDeviceErrorReply(HttpReply::NotFound, DeviceManager::DeviceErrorVendorNotFound);
return createDeviceErrorReply(HttpReply::NotFound, Device::DeviceErrorVendorNotFound);
}
}

View File

@ -19,8 +19,8 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "tagsstorage.h"
#include "devicemanager.h"
#include "ruleengine.h"
#include "devices/devicemanager.h"
#include "ruleengine/ruleengine.h"
#include "nymeasettings.h"
namespace nymeaserver {

View File

@ -1,211 +0,0 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015-2018 Simon Stürz <simon.stuerz@guh.io> *
* Copyright (C) 2014 Michael Zanetti <michael_zanetti@gmx.net> *
* *
* This file is part of nymea. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEVICEMANAGER_H
#define DEVICEMANAGER_H
#include "libnymea.h"
#include "plugin/device.h"
#include "plugin/devicedescriptor.h"
#include "types/deviceclass.h"
#include "types/interface.h"
#include "types/event.h"
#include "types/action.h"
#include "types/vendor.h"
#include <QObject>
#include <QTimer>
#include <QLocale>
#include <QPluginLoader>
#include <QTranslator>
#include "hardwaremanager.h"
class Device;
class DevicePlugin;
class DevicePairingInfo;
class HardwareManager;
class Translator;
class LIBNYMEA_EXPORT DeviceManager : public QObject
{
Q_OBJECT
friend class DevicePlugin;
public:
enum DeviceError {
DeviceErrorNoError,
DeviceErrorPluginNotFound,
DeviceErrorVendorNotFound,
DeviceErrorDeviceNotFound,
DeviceErrorDeviceClassNotFound,
DeviceErrorActionTypeNotFound,
DeviceErrorStateTypeNotFound,
DeviceErrorEventTypeNotFound,
DeviceErrorDeviceDescriptorNotFound,
DeviceErrorMissingParameter,
DeviceErrorInvalidParameter,
DeviceErrorSetupFailed,
DeviceErrorDuplicateUuid,
DeviceErrorCreationMethodNotSupported,
DeviceErrorSetupMethodNotSupported,
DeviceErrorHardwareNotAvailable,
DeviceErrorHardwareFailure,
DeviceErrorAuthentificationFailure,
DeviceErrorAsync,
DeviceErrorDeviceInUse,
DeviceErrorDeviceInRule,
DeviceErrorDeviceIsChild,
DeviceErrorPairingTransactionIdNotFound,
DeviceErrorParameterNotWritable
};
Q_ENUM(DeviceError)
enum DeviceSetupStatus {
DeviceSetupStatusSuccess,
DeviceSetupStatusFailure,
DeviceSetupStatusAsync
};
Q_ENUM(DeviceSetupStatus)
explicit DeviceManager(HardwareManager *hardwareManager, const QLocale &locale, QObject *parent = nullptr);
~DeviceManager();
static QStringList pluginSearchDirs();
static QList<QJsonObject> pluginsMetadata();
void registerStaticPlugin(DevicePlugin* plugin, const QJsonObject &metaData);
HardwareManager *hardwareManager() const;
QList<DevicePlugin*> plugins() const;
DevicePlugin* plugin(const PluginId &id) const;
DeviceError setPluginConfig(const PluginId &pluginId, const ParamList &pluginConfig);
QList<Vendor> supportedVendors() const;
Interfaces supportedInterfaces() const;
Interface findInterface(const QString &name);
QList<DeviceClass> supportedDevices(const VendorId &vendorId = VendorId()) const;
DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params);
QList<Device*> configuredDevices() const;
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QString &name, const ParamList &params, const DeviceId id = DeviceId::createDeviceId());
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QString &name, const DeviceDescriptorId &deviceDescriptorId, const ParamList &params = ParamList(), const DeviceId &deviceId = DeviceId::createDeviceId());
DeviceError reconfigureDevice(const DeviceId &deviceId, const ParamList &params, bool fromDiscoveryOrAuto = false);
DeviceError reconfigureDevice(const DeviceId &deviceId, const DeviceDescriptorId &deviceDescriptorId);
DeviceError editDevice(const DeviceId &deviceId, const QString &name);
DeviceError setDeviceSettings(const DeviceId &deviceId, const ParamList &settings);
DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const QString &name, const ParamList &params);
DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const QString &name, const DeviceDescriptorId &deviceDescriptorId);
DeviceError confirmPairing(const PairingTransactionId &pairingTransactionId, const QString &secret = QString());
DeviceError removeConfiguredDevice(const DeviceId &deviceId);
Device* findConfiguredDevice(const DeviceId &id) const;
QList<Device *> findConfiguredDevices(const DeviceClassId &deviceClassId) const;
QList<Device *> findConfiguredDevices(const QString &interface) const;
QList<Device *> findChildDevices(const DeviceId &id) const;
DeviceClass findDeviceClass(const DeviceClassId &deviceClassId) const;
DeviceError verifyParams(const QList<ParamType> paramTypes, ParamList &params, bool requireAll = true);
DeviceError verifyParam(const QList<ParamType> paramTypes, const Param &param);
DeviceError verifyParam(const ParamType &paramType, const Param &param);
Translator* translator() const;
signals:
void loaded();
void pluginConfigChanged(const PluginId &id, const ParamList &config);
void eventTriggered(const Event &event);
void deviceStateChanged(Device *device, const StateTypeId &stateTypeId, const QVariant &value);
void deviceRemoved(const DeviceId &deviceId);
void deviceDisappeared(const DeviceId &deviceId);
void deviceAdded(Device *device);
void deviceChanged(Device *device);
void deviceSettingChanged(const DeviceId deviceId, const ParamTypeId &settingParamTypeId, const QVariant &value);
void devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> &devices);
void deviceSetupFinished(Device *device, DeviceError status);
void deviceReconfigurationFinished(Device *device, DeviceError status);
void pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceError status, const DeviceId &deviceId = DeviceId());
void actionExecutionFinished(const ActionId &actionId, DeviceManager::DeviceError status);
public slots:
DeviceError executeAction(const Action &action);
void timeTick();
private slots:
void loadPlugins();
void loadPlugin(DevicePlugin *pluginIface);
void loadConfiguredDevices();
void storeConfiguredDevices();
void startMonitoringAutoDevices();
void slotDevicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> deviceDescriptors);
void slotDeviceSetupFinished(Device *device, DeviceManager::DeviceSetupStatus status);
void slotPairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceSetupStatus status);
void onAutoDevicesAppeared(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> &deviceDescriptors);
void onAutoDeviceDisappeared(const DeviceId &deviceId);
void onLoaded();
void cleanupDeviceStateCache();
// Only connect this to Devices. It will query the sender()
void slotDeviceStateValueChanged(const StateTypeId &stateTypeId, const QVariant &value);
void slotDeviceSettingChanged(const ParamTypeId &paramTypeId, const QVariant &value);
private:
bool verifyPluginMetadata(const QJsonObject &data);
DeviceError addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QString &name, const ParamList &params, const DeviceId id = DeviceId::createDeviceId());
DeviceSetupStatus setupDevice(Device *device);
void postSetupDevice(Device *device);
void storeDeviceStates(Device *device);
void loadDeviceStates(Device *device);
private:
HardwareManager *m_hardwareManager;
QLocale m_locale;
Translator *m_translator = nullptr;
QHash<VendorId, Vendor> m_supportedVendors;
QHash<QString, Interface> m_supportedInterfaces;
QHash<VendorId, QList<DeviceClassId> > m_vendorDeviceMap;
QHash<DeviceClassId, DeviceClass> m_supportedDevices;
QHash<DeviceId, Device*> m_configuredDevices;
QHash<DeviceDescriptorId, DeviceDescriptor> m_discoveredDevices;
QHash<PluginId, DevicePlugin*> m_devicePlugins;
QHash<QUuid, DevicePairingInfo> m_pairingsJustAdd;
QHash<QUuid, DevicePairingInfo> m_pairingsDiscovery;
QList<Device *> m_asyncDeviceReconfiguration;
QList<DevicePlugin *> m_discoveringPlugins;
};
Q_DECLARE_METATYPE(DeviceManager::DeviceError)
Q_DECLARE_METATYPE(DeviceManager::DeviceSetupStatus)
#endif // DEVICEMANAGER_H

View File

@ -34,32 +34,99 @@
\sa DeviceClass, DeviceDescriptor
*/
/*! \enum Device::DeviceError
This enum type specifies the errors that can happen when working with \l{Device}{Devices}.
\value DeviceErrorNoError
No Error. Everything went fine.
\value DeviceErrorPluginNotFound
Couldn't find the Plugin for the given id.
\value DeviceErrorVendorNotFound
Couldn't find the Vendor for the given id.
\value DeviceErrorDeviceNotFound
Couldn't find a \l{Device} for the given id.
\value DeviceErrorDeviceClassNotFound
Couldn't find a \l{DeviceClass} for the given id.
\value DeviceErrorActionTypeNotFound
Couldn't find the \l{ActionType} for the given id.
\value DeviceErrorStateTypeNotFound
Couldn't find the \l{StateType} for the given id.
\value DeviceErrorEventTypeNotFound
Couldn't find the \l{EventType} for the given id.
\value DeviceErrorDeviceDescriptorNotFound
Couldn't find the \l{DeviceDescriptor} for the given id.
\value DeviceErrorMissingParameter
Parameters do not comply to the template.
\value DeviceErrorInvalidParameter
One of the given parameter is not valid.
\value DeviceErrorSetupFailed
Error setting up the \l{Device}. It will not be functional.
\value DeviceErrorDuplicateUuid
Error setting up the \l{Device}. The given DeviceId already exists.
\value DeviceErrorCreationMethodNotSupported
Error setting up the \l{Device}. This \l{DeviceClass}{CreateMethod} is not supported for this \l{Device}.
\value DeviceErrorSetupMethodNotSupported
Error setting up the \l{Device}. This \l{DeviceClass}{SetupMethod} is not supported for this \l{Device}.
\value DeviceErrorHardwareNotAvailable
The Hardware of the \l{Device} is not available.
\value DeviceErrorHardwareFailure
The Hardware of the \l{Device} has an error.
\value DeviceErrorAsync
The response of the \l{Device} will be asynchronously.
\value DeviceErrorDeviceInUse
The \l{Device} is currently bussy.
\value DeviceErrorPairingTransactionIdNotFound
Couldn't find the PairingTransactionId for the given id.
\value DeviceErrorAuthentificationFailure
The device could not authentificate with something.
\value DeviceErrorDeviceIsChild
The device is a child device and can not be deleted directly.
\value DeviceErrorDeviceInRule
The device is in a rule and can not be deleted withou \l{nymeaserver::RuleEngine::RemovePolicy}.
\value DeviceErrorParameterNotWritable
One of the given device params is not writable.
*/
/*! \enum Device::DeviceSetupStatus
This enum type specifies the setup status of a \l{Device}.
\value DeviceSetupStatusSuccess
No Error. Everything went fine.
\value DeviceSetupStatusFailure
Something went wrong during the setup.
\value DeviceSetupStatusAsync
The status of the \l{Device} setup will be emitted asynchronous.
*/
/*! \fn void Device::stateValueChanged(const StateTypeId &stateTypeId, const QVariant &value)
This signal is emitted when the \l{State} with the given \a stateTypeId changed.
The \a value parameter describes the new value of the State.
*/
#include "device.h"
#include "deviceplugin.h"
#include "types/event.h"
#include "loggingcategories.h"
#include <QDebug>
/*! Construct an Device with the given \a pluginId, \a id, \a deviceClassId and \a parent. */
Device::Device(const PluginId &pluginId, const DeviceId &id, const DeviceClassId &deviceClassId, QObject *parent):
Device::Device(DevicePlugin *plugin, const DeviceClass &deviceClass, const DeviceId &id, QObject *parent):
QObject(parent),
m_id(id),
m_deviceClassId(deviceClassId),
m_pluginId(pluginId)
m_deviceClass(deviceClass),
m_plugin(plugin),
m_id(id)
{
}
/*! Construct an Device with the given \a pluginId, \a deviceClassId and \a parent. A new DeviceId will be created for this Device. */
Device::Device(const PluginId &pluginId, const DeviceClassId &deviceClassId, QObject *parent):
Device::Device(DevicePlugin *plugin, const DeviceClass &deviceClass, QObject *parent):
QObject(parent),
m_id(DeviceId::createDeviceId()),
m_deviceClassId(deviceClassId),
m_pluginId(pluginId)
m_deviceClass(deviceClass),
m_plugin(plugin),
m_id(DeviceId::createDeviceId())
{
}
@ -78,13 +145,13 @@ DeviceId Device::id() const
/*! Returns the deviceClassId of the associated \l{DeviceClass}. */
DeviceClassId Device::deviceClassId() const
{
return m_deviceClassId;
return m_deviceClass.id();
}
/*! Returns the id of the \l{DevicePlugin} this Device is managed by. */
PluginId Device::pluginId() const
{
return m_pluginId;
return m_plugin->pluginId();
}
/*! Returns the name of this Device. This is visible to the user. */
@ -314,6 +381,25 @@ Device *Devices::findById(const DeviceId &id)
return nullptr;
}
/*! Find a certain device by its \a params. All parameters must
match or the device will not be found. Be prepared for nullptrs.
*/
Device *Devices::findByParams(const ParamList &params) const
{
foreach (Device *device, *this) {
bool matching = true;
foreach (const Param &param, params) {
if (device->paramValue(param.paramTypeId()) != param.value()) {
matching = false;
}
}
if (matching) {
return device;
}
}
return nullptr;
}
QDebug operator<<(QDebug dbg, Device *device)
{
dbg.nospace() << "Device(" << device->name();

View File

@ -35,17 +35,58 @@
#include <QUuid>
#include <QVariant>
class DevicePlugin;
class LIBNYMEA_EXPORT Device: public QObject
{
Q_OBJECT
friend class DeviceManager;
friend class DeviceManagerImplementation;
public:
enum DeviceError {
DeviceErrorNoError,
DeviceErrorPluginNotFound,
DeviceErrorVendorNotFound,
DeviceErrorDeviceNotFound,
DeviceErrorDeviceClassNotFound,
DeviceErrorActionTypeNotFound,
DeviceErrorStateTypeNotFound,
DeviceErrorEventTypeNotFound,
DeviceErrorDeviceDescriptorNotFound,
DeviceErrorMissingParameter,
DeviceErrorInvalidParameter,
DeviceErrorSetupFailed,
DeviceErrorDuplicateUuid,
DeviceErrorCreationMethodNotSupported,
DeviceErrorSetupMethodNotSupported,
DeviceErrorHardwareNotAvailable,
DeviceErrorHardwareFailure,
DeviceErrorAuthentificationFailure,
DeviceErrorAsync,
DeviceErrorDeviceInUse,
DeviceErrorDeviceInRule,
DeviceErrorDeviceIsChild,
DeviceErrorPairingTransactionIdNotFound,
DeviceErrorParameterNotWritable
};
Q_ENUM(DeviceError)
enum DeviceSetupStatus {
DeviceSetupStatusSuccess,
DeviceSetupStatusFailure,
DeviceSetupStatusAsync
};
Q_ENUM(DeviceSetupStatus)
DeviceId id() const;
DeviceClassId deviceClassId() const;
PluginId pluginId() const;
DeviceClass deviceClass() const;
DevicePlugin* plugin();
QString name() const;
void setName(const QString &name);
@ -84,17 +125,18 @@ signals:
void nameChanged();
private:
Device(const PluginId &pluginId, const DeviceId &id, const DeviceClassId &deviceClassId, QObject *parent = nullptr);
Device(const PluginId &pluginId, const DeviceClassId &deviceClassId, QObject *parent = nullptr);
Device(DevicePlugin *plugin, const DeviceClass &deviceClass, const DeviceId &id, QObject *parent = nullptr);
Device(DevicePlugin *plugin, const DeviceClass &deviceClass, QObject *parent = nullptr);
void setupCompleted();
void setSetupComplete(const bool &complete);
private:
DeviceClass m_deviceClass;
DevicePlugin* m_plugin = nullptr;
DeviceId m_id;
DeviceId m_parentId;
DeviceClassId m_deviceClassId;
PluginId m_pluginId;
QString m_name;
ParamList m_params;
ParamList m_settings;
@ -111,8 +153,12 @@ public:
Devices() = default;
Devices(const QList<Device *> &other);
Device* findById(const DeviceId &id);
Device* findByParams(const ParamList &params) const;
Devices filterByParam(const ParamTypeId &paramTypeId, const QVariant &value = QVariant());
Devices filterByDeviceClassId(const DeviceClassId &deviceClassId);
};
Q_DECLARE_METATYPE(Device::DeviceError)
Q_DECLARE_METATYPE(Device::DeviceSetupStatus)
#endif

View File

@ -0,0 +1,41 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Michael Zanetti <michael.zanetti@nymea.io> *
* *
* This file is part of nymea. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicemanager.h"
/*!
\class DeviceManager
\brief The main entry point when interacting with \l{Device}{Devices}
\ingroup devices
\inmodule libnymea
The DeviceManager hold s all information about supported and configured Devices in the system.
It is also responsible for loading Plugins and managing common hardware resources between
\l{DevicePlugin}{device plugins}.
*/
DeviceManager::DeviceManager(QObject *parent) : QObject(parent)
{
}

View File

@ -0,0 +1,91 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Michael Zanetti <michael.zanetti@nymea.io> *
* *
* This file is part of nymea. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEVICEMANAGER_H
#define DEVICEMANAGER_H
#include <QObject>
#include "device.h"
#include "deviceplugin.h"
#include "types/interface.h"
#include "types/vendor.h"
class DeviceManager : public QObject
{
Q_OBJECT
public:
explicit DeviceManager(QObject *parent = nullptr);
virtual ~DeviceManager() = default;
virtual DevicePlugins plugins() const = 0;
virtual Device::DeviceError setPluginConfig(const PluginId &pluginId, const ParamList &pluginConfig) = 0;
virtual Vendors supportedVendors() const = 0;
virtual Interfaces supportedInterfaces() const = 0;
virtual DeviceClasses supportedDevices(const VendorId &vendorId = VendorId()) const = 0;
virtual DeviceClass findDeviceClass(const DeviceClassId &deviceClassId) const = 0;
virtual Devices configuredDevices() const = 0;
virtual Device* findConfiguredDevice(const DeviceId &id) const = 0;
virtual Devices findConfiguredDevices(const DeviceClassId &deviceClassId) const = 0;
virtual Devices findConfiguredDevices(const QString &interface) const = 0;
virtual Devices findChildDevices(const DeviceId &id) const = 0;
virtual Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) = 0;
virtual Device::DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QString &name, const ParamList &params, const DeviceId id = DeviceId::createDeviceId()) = 0;
virtual Device::DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QString &name, const DeviceDescriptorId &deviceDescriptorId, const ParamList &params = ParamList(), const DeviceId &deviceId = DeviceId::createDeviceId()) = 0;
virtual Device::DeviceError reconfigureDevice(const DeviceId &deviceId, const ParamList &params, bool fromDiscoveryOrAuto = false) = 0;
virtual Device::DeviceError reconfigureDevice(const DeviceId &deviceId, const DeviceDescriptorId &deviceDescriptorId) = 0;
virtual Device::DeviceError editDevice(const DeviceId &deviceId, const QString &name) = 0;
virtual Device::DeviceError setDeviceSettings(const DeviceId &deviceId, const ParamList &settings) = 0;
virtual Device::DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const QString &name, const ParamList &params) = 0;
virtual Device::DeviceError pairDevice(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const QString &name, const DeviceDescriptorId &deviceDescriptorId) = 0;
virtual Device::DeviceError confirmPairing(const PairingTransactionId &pairingTransactionId, const QString &secret = QString()) = 0;
virtual Device::DeviceError removeConfiguredDevice(const DeviceId &deviceId) = 0;
virtual QString translate(const PluginId &pluginId, const QString &string, const QLocale &locale) = 0;
signals:
void pluginConfigChanged(const PluginId &id, const ParamList &config);
void eventTriggered(const Event &event);
void deviceStateChanged(Device *device, const StateTypeId &stateTypeId, const QVariant &value);
void deviceRemoved(const DeviceId &deviceId);
void deviceDisappeared(const DeviceId &deviceId);
void deviceAdded(Device *device);
void deviceChanged(Device *device);
void deviceSettingChanged(const DeviceId deviceId, const ParamTypeId &settingParamTypeId, const QVariant &value);
void devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> &devices);
void deviceSetupFinished(Device *device, Device::DeviceError status);
void deviceReconfigurationFinished(Device *device, Device::DeviceError status);
void pairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceError status, const DeviceId &deviceId = DeviceId());
void actionExecutionFinished(const ActionId &actionId, Device::DeviceError status);
};
#endif // DEVICEMANAGER_H

View File

@ -0,0 +1,380 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015-2018 Simon Stürz <simon.stuerz@guh.io> *
* Copyright (C) 2014 Michael Zanetti <michael_zanetti@gmx.net> *
* *
* This file is part of nymea. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*!
\class DevicePlugin
\brief This is the base class interface for device plugins.
\ingroup devices
\inmodule libnymea
*/
/*! \fn void DevicePlugin::devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> &devices);
Emit this signal when the discovery of a \a deviceClassId of this DevicePlugin is finished. The \a devices parameter describes the
list of \l{DeviceDescriptor}{DeviceDescriptors} of all discovered \l{Device}{Devices}.
Note: During a discovery a plugin should always return the full result set. So even if a device is already known to the system and
a later discovery finds the device again, it should be included in the result set but the DeviceDescriptor's deviceId should be set
to the device ID.
\sa discoverDevices()
*/
/*! \fn void DevicePlugin::pairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceSetupStatus status);
This signal is emitted when the pairing of a \a pairingTransactionId is finished.
The \a status of the will be described as \l{Device::DeviceError}{DeviceError}.
\sa confirmPairing()
*/
/*! \fn void DevicePlugin::deviceSetupFinished(Device *device, Device::DeviceSetupStatus status);
This signal is emitted when the setup of a \a device in this DevicePlugin is finished. The \a status parameter describes the
\l{Device::DeviceError}{DeviceError} that occurred.
*/
/*! \fn void DevicePlugin::configValueChanged(const ParamTypeId &paramTypeId, const QVariant &value);
This signal is emitted when the \l{Param} with a certain \a paramTypeId of a \l{Device} configuration changed the \a value.
*/
/*! \fn void DevicePlugin::actionExecutionFinished(const ActionId &id, Device::DeviceError status)
This signal is to be emitted when you previously have returned \l{DeviceManager}{DeviceErrorAsync}
in a call of executeAction(). The \a id refers to the executed \l{Action}. The \a status of the \l{Action}
execution will be described as \l{Device::DeviceError}{DeviceError}.
*/
/*! \fn void DevicePlugin::autoDevicesAppeared(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> &deviceDescriptors)
This signal is emitted when a new \l{Device} of certain \a deviceClassId appeared. The description of the \l{Device}{Devices}
will be in \a deviceDescriptors. This signal can only emitted from devices with the \l{DeviceClass}{CreateMethodAuto}.
*/
/*! \fn void DevicePlugin::autoDeviceDisappeared(const DeviceId &id)
Emit this signal when a device with the given \a id and which was created by \l{DevicePlugin::autoDevicesAppeared} has been removed from the system.
Be careful with this, as this will completely remove the device from the system and with it all the associated rules. Only
emit this if you are sure that a device will never come back. This signal should not be emitted for child auto devices
when the parent who created them is removed. The system will automatically remove all child devices in such a case.
*/
/*! \fn void DevicePlugin::emitEvent(const Event &event)
To produce a new event in the system, create a new \l{Event} and emit it with \a event.
Usually events are emitted in response to incoming data or other other events happening. Find a configured
\l{Device} from the \l{DeviceManager} and get its \l{EventType}{EventTypes}, then
create a \l{Event} complying to that \l{EventType} and emit it here.
*/
/*! \fn void DevicePlugin::init()
This will be called after constructing the DevicePlugin. Override this to do any
initialisation work you need to do.
*/
#include "deviceplugin.h"
#include "devicemanager.h"
#include "deviceutils.h"
#include "loggingcategories.h"
#include "nymeasettings.h"
#include "hardware/radio433/radio433.h"
#include "network/upnp/upnpdiscovery.h"
#include <QDebug>
#include <QFileInfo>
#include <QFile>
#include <QDir>
#include <QCoreApplication>
#include <QJsonArray>
#include <QJsonDocument>
/*! DevicePlugin constructor. DevicePlugins will be instantiated by the DeviceManager, its \a parent. */
DevicePlugin::DevicePlugin(QObject *parent):
QObject(parent)
{
}
/*! Virtual destructor... */
DevicePlugin::~DevicePlugin()
{
}
/*! Returns the name of this DevicePlugin. */
QString DevicePlugin::pluginName() const
{
return m_metaData.pluginName();
}
/*! Returns the displayName of this DevicePlugin, to be shown to the user, translated. */
QString DevicePlugin::pluginDisplayName() const
{
return m_metaData.pluginDisplayName();
}
/*! Returns the id of this DevicePlugin.
* When implementing a plugin, generate a new uuid and return it here. Always return the
* same uuid and don't change it or configurations can't be matched any more. */
PluginId DevicePlugin::pluginId() const
{
return m_metaData.pluginId();
}
/*! Returns the list of \l{Vendor}{Vendors} supported by this DevicePlugin. */
Vendors DevicePlugin::supportedVendors() const
{
return m_metaData.vendors();
}
/*! Return a list of \l{DeviceClass}{DeviceClasses} describing all the devices supported by this plugin.
If a DeviceClass has an invalid parameter it will be ignored.
*/
DeviceClasses DevicePlugin::supportedDevices() const
{
return m_metaData.deviceClasses();
}
/*! Override this if your plugin supports Device with DeviceClass::CreationMethodAuto.
This will be called at startup, after the configured devices have been loaded.
This is the earliest time you should start emitting autoDevicesAppeared(). If you
are monitoring some hardware/service for devices to appear, start monitoring now.
If you are building the devices based on a static list, you may emit
autoDevicesAppeard() in here.
*/
void DevicePlugin::startMonitoringAutoDevices()
{
}
/*! Reimplement this if you support a DeviceClass with createMethod \l{DeviceManager}{CreateMethodDiscovery}.
This will be called to discover Devices for the given \a deviceClassId with the given \a params. This will always
be an async operation. Return \l{DeviceManager}{DeviceErrorAsync} or \l{DeviceManager}{DeviceErrorNoError}
if the discovery has been started successfully. Return an appropriate error otherwise.
Once devices are discovered, emit devicesDiscovered().
*/
Device::DeviceError DevicePlugin::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{
Q_UNUSED(deviceClassId)
Q_UNUSED(params)
return Device::DeviceErrorCreationMethodNotSupported;
}
/*! This will be called when a new device is created. The plugin has the chance to do some setup.
Return \l{DeviceManager}{DeviceSetupStatusFailure} if something bad happened during the setup in which case the \a device
will be disabled. Return \l{DeviceManager}{DeviceSetupStatusSuccess} if everything went well. If you can't tell yet and
need more time to set up the \a device (note: you should never block in this method) you can
return \l{DeviceManager}{DeviceSetupStatusAsync}. In that case the \l{DeviceManager} will wait for you to emit
\l{DevicePlugin}{deviceSetupFinished} to report the status.
*/
Device::DeviceSetupStatus DevicePlugin::setupDevice(Device *device)
{
Q_UNUSED(device)
return Device::DeviceSetupStatusSuccess;
}
/*! This will be called when a new \a device was added successfully and the device setup is finished.*/
void DevicePlugin::postSetupDevice(Device *device)
{
Q_UNUSED(device)
}
/*! This will be called when a \a device removed. The plugin has the chance to do some teardown.
The device is still valid during this call, but already removed from the system.
The device will be deleted as soon as this method returns.
*/
void DevicePlugin::deviceRemoved(Device *device)
{
Q_UNUSED(device)
}
/*! This method will be called for \l{Device}{Devices} with the \l{DeviceClass::SetupMethodDisplayPin} right after the paring request
with the given \a pairingTransactionId for the given \a deviceDescriptor.
*/
Device::DeviceError DevicePlugin::displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor)
{
Q_UNUSED(pairingTransactionId)
Q_UNUSED(deviceDescriptor)
qCWarning(dcDeviceManager) << "Plugin does not implement the display pin setup method.";
return Device::DeviceErrorNoError;
}
/*! Confirms the pairing of a \a deviceClassId with the given \a pairingTransactionId and \a params.
Returns \l{Device::DeviceError}{DeviceError} to inform about the result. The optional paramerter
\a secret contains for example the pin for \l{Device}{Devices} with the setup method \l{DeviceClass::SetupMethodDisplayPin}.
*/
Device::DeviceSetupStatus DevicePlugin::confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret = QString())
{
Q_UNUSED(pairingTransactionId)
Q_UNUSED(deviceClassId)
Q_UNUSED(params)
Q_UNUSED(secret)
qCWarning(dcDeviceManager) << "Plugin does not implement pairing.";
return Device::DeviceSetupStatusFailure;
}
/*! This will be called to actually execute actions on the hardware. The \{Device} and
the \{Action} are contained in the \a device and \a action parameters.
Return the appropriate \l{Device::DeviceError}{DeviceError}.
It is possible to execute actions asynchronously. You never should do anything blocking for
a long time (e.g. wait on a network reply from the internet) but instead return
Device::DeviceErrorAsync and continue processing in an async manner. Once
you have the reply ready, emit actionExecutionFinished() with the appropriate parameters.
\sa actionExecutionFinished()
*/
Device::DeviceError DevicePlugin::executeAction(Device *device, const Action &action)
{
Q_UNUSED(device)
Q_UNUSED(action)
return Device::DeviceErrorNoError;
}
/*! Returns the configuration description of this DevicePlugin as a list of \l{ParamType}{ParamTypes}. */
ParamTypes DevicePlugin::configurationDescription() const
{
return m_metaData.pluginSettings();
}
/*! This will be called when the DeviceManager initializes the plugin and set up the things behind the scenes.
When implementing a new plugin, use \l{DevicePlugin::init()} instead in order to do initialisation work.
The \l{DevicePlugin::init()} method will be called once the plugin configuration has been loaded. */
void DevicePlugin::initPlugin(const PluginMetadata &metadata, DeviceManager *deviceManager, HardwareManager *hardwareManager)
{
m_metaData = metadata;
m_deviceManager = deviceManager;
m_hardwareManager = hardwareManager;
}
/*! Returns a map containing the plugin configuration.
When implementing a new plugin, override this and fill in the empty configuration if your plugin requires any.
*/
ParamList DevicePlugin::configuration() const
{
return m_config;
}
/*! Use this to retrieve the values for your parameters. Values might not be set
at the time when your plugin is loaded, but will be set soon after. Listen to
configurationValueChanged() to know when something changes.
When implementing a new plugin, specify in configurationDescription() what you want to see here.
Returns the config value of a \l{Param} with the given \a paramTypeId of this DevicePlugin.
*/
QVariant DevicePlugin::configValue(const ParamTypeId &paramTypeId) const
{
return m_config.paramValue(paramTypeId);
}
/*! Will be called by the DeviceManager to set a plugin's \a configuration. */
Device::DeviceError DevicePlugin::setConfiguration(const ParamList &configuration)
{
foreach (const Param &param, configuration) {
qCDebug(dcDeviceManager()) << "* Set plugin configuration" << param;
Device::DeviceError result = setConfigValue(param.paramTypeId(), param.value());
if (result != Device::DeviceErrorNoError)
return result;
}
return Device::DeviceErrorNoError;
}
/*! Can be called in the DevicePlugin to set a plugin's \l{Param} with the given \a paramTypeId and \a value. */
Device::DeviceError DevicePlugin::setConfigValue(const ParamTypeId &paramTypeId, const QVariant &value)
{
bool found = false;
foreach (const ParamType &paramType, configurationDescription()) {
if (paramType.id() == paramTypeId) {
found = true;
Device::DeviceError result = DeviceUtils::verifyParam(paramType, Param(paramTypeId, value));
if (result != Device::DeviceErrorNoError)
return result;
break;
}
}
if (!found) {
qCWarning(dcDeviceManager()) << QString("Could not find plugin parameter with the id %1.").arg(paramTypeId.toString());
return Device::DeviceErrorInvalidParameter;
}
if (m_config.hasParam(paramTypeId)) {
if (!m_config.setParamValue(paramTypeId, value)) {
qCWarning(dcDeviceManager()) << "Could not set param value" << value << "for param with id" << paramTypeId.toString();
return Device::DeviceErrorInvalidParameter;
}
} else {
m_config.append(Param(paramTypeId, value));
}
emit configValueChanged(paramTypeId, value);
return Device::DeviceErrorNoError;
}
bool DevicePlugin::isBuiltIn() const
{
return m_metaData.isBuiltIn();
}
/*! Returns a list of all configured devices belonging to this plugin. */
Devices DevicePlugin::myDevices() const
{
QList<Device*> ret;
foreach (Device *device, m_deviceManager->configuredDevices()) {
if (device->pluginId() == pluginId()) {
ret.append(device);
}
}
return ret;
}
/*! Returns the pointer to the main \l{HardwareManager} of this server. */
HardwareManager *DevicePlugin::hardwareManager() const
{
return m_hardwareManager;
}
void DevicePlugin::setMetaData(const PluginMetadata &metaData)
{
m_metaData = metaData;
}
DevicePlugins::DevicePlugins()
{
}
DevicePlugins::DevicePlugins(const QList<DevicePlugin *> &other): QList<DevicePlugin *>(other)
{
}
DevicePlugin *DevicePlugins::findById(const PluginId &id) const
{
foreach (DevicePlugin *plugin, *this) {
if (plugin->pluginId() == id) {
return plugin;
}
}
return nullptr;
}

View File

@ -24,21 +24,23 @@
#ifndef DEVICEPLUGIN_H
#define DEVICEPLUGIN_H
#include "devicemanager.h"
#include "libnymea.h"
#include "typeutils.h"
#include "device.h"
#include "devicedescriptor.h"
#include "pluginmetadata.h"
#include "types/deviceclass.h"
#include "types/event.h"
#include "types/action.h"
#include "types/vendor.h"
#include "types/param.h"
#include "types/interface.h"
#include "hardwaremanager.h"
#include <QObject>
#include <QMetaEnum>
#include <QJsonObject>
#include <QMetaObject>
#include <QTranslator>
#include <QPair>
@ -50,6 +52,7 @@ class LIBNYMEA_EXPORT DevicePlugin: public QObject
Q_OBJECT
friend class DeviceManager;
friend class DeviceManagerImplementation;
public:
DevicePlugin(QObject *parent = nullptr);
@ -60,50 +63,47 @@ public:
PluginId pluginId() const;
QString pluginName() const;
QString pluginDisplayName() const;
QList<Vendor> supportedVendors() const;
QList<DeviceClass> supportedDevices() const;
Vendors supportedVendors() const;
DeviceClasses supportedDevices() const;
virtual void startMonitoringAutoDevices();
virtual DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params);
virtual Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params);
virtual DeviceManager::DeviceSetupStatus setupDevice(Device *device);
virtual Device::DeviceSetupStatus setupDevice(Device *device);
virtual void postSetupDevice(Device *device);
virtual void deviceRemoved(Device *device);
virtual DeviceManager::DeviceError displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor);
virtual DeviceManager::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret);
virtual Device::DeviceError displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor);
virtual Device::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret);
virtual DeviceManager::DeviceError executeAction(Device *device, const Action &action);
virtual Device::DeviceError executeAction(Device *device, const Action &action);
// Configuration
ParamTypes configurationDescription() const;
DeviceManager::DeviceError setConfiguration(const ParamList &configuration);
Device::DeviceError setConfiguration(const ParamList &configuration);
ParamList configuration() const;
QVariant configValue(const ParamTypeId &paramTypeId) const;
DeviceManager::DeviceError setConfigValue(const ParamTypeId &paramTypeId, const QVariant &value);
Device::DeviceError setConfigValue(const ParamTypeId &paramTypeId, const QVariant &value);
bool isBuiltIn() const;
signals:
void emitEvent(const Event &event);
void devicesDiscovered(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> &deviceDescriptors);
void deviceSetupFinished(Device *device, DeviceManager::DeviceSetupStatus status);
void pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceManager::DeviceSetupStatus status);
void actionExecutionFinished(const ActionId &id, DeviceManager::DeviceError status);
void deviceSetupFinished(Device *device, Device::DeviceSetupStatus status);
void pairingFinished(const PairingTransactionId &pairingTransactionId, Device::DeviceSetupStatus status);
void actionExecutionFinished(const ActionId &id, Device::DeviceError status);
void configValueChanged(const ParamTypeId &paramTypeId, const QVariant &value);
void autoDevicesAppeared(const DeviceClassId &deviceClassId, const QList<DeviceDescriptor> &deviceDescriptors);
void autoDeviceDisappeared(const DeviceId &deviceId);
protected:
DeviceManager *deviceManager() const;
Devices myDevices() const;
HardwareManager *hardwareManager() const;
Device* findDeviceByParams(const ParamList &params) const;
private:
void setMetaData(const QJsonObject &metaData);
void loadMetaData();
void initPlugin(DeviceManager *deviceManager);
void setMetaData(const PluginMetadata &metaData);
void initPlugin(const PluginMetadata &metadata, DeviceManager *deviceManager, HardwareManager *hardwareManager);
QPair<bool, QList<ParamType> > parseParamTypes(const QJsonArray &array) const;
@ -114,25 +114,22 @@ private:
QPair<bool, Types::Unit> loadAndVerifyUnit(const QString &unitString) const;
QPair<bool, Types::InputType> loadAndVerifyInputType(const QString &inputType) const;
// FIXME: This is expensive because it will open all the files.
// Once DeviceManager is in libnymea-core this should probably be there too.
// I didn't want to add even more dependencies on the devicemanager into here, so reading the list here for now.
static Interfaces allInterfaces();
static Interface loadInterface(const QString &name);
static Interface mergeInterfaces(const Interface &iface1, const Interface &iface2);
static QStringList generateInterfaceParentList(const QString &interface);
DeviceManager *m_deviceManager = nullptr;
HardwareManager *m_hardwareManager = nullptr;
QList<ParamType> m_configurationDescription;
PluginMetadata m_metaData;
ParamList m_config;
QJsonObject m_metaData;
mutable QList<DeviceClass> m_supportedDevices;
};
Q_DECLARE_INTERFACE(DevicePlugin, "io.nymea.DevicePlugin")
class LIBNYMEA_EXPORT DevicePlugins: public QList<DevicePlugin*>
{
public:
DevicePlugins();
DevicePlugins(const QList<DevicePlugin*> &other);
DevicePlugin* findById(const PluginId &id) const;
};
#endif // DEVICEPLUGIN_H

View File

@ -0,0 +1,307 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Michael Zanetti <michael.zanetti@nymea.io> *
* *
* This file is part of nymea. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "deviceutils.h"
#include "loggingcategories.h"
#include <QDir>
#include <QFileInfo>
#include <QJsonParseError>
DeviceUtils::DeviceUtils()
{
}
/*! Verify if the given \a params matches the given \a paramTypes. Ith \a requireAll
* is true, all \l{ParamList}{Params} has to be valid. Returns \l{Device::DeviceError} to inform about the result.*/
Device::DeviceError DeviceUtils::verifyParams(const QList<ParamType> paramTypes, ParamList &params, bool requireAll)
{
foreach (const Param &param, params) {
Device::DeviceError result = verifyParam(paramTypes, param);
if (result != Device::DeviceErrorNoError) {
return result;
}
}
if (!requireAll) {
return Device::DeviceErrorNoError;
}
foreach (const ParamType &paramType, paramTypes) {
bool found = false;
foreach (const Param &param, params) {
if (paramType.id() == param.paramTypeId()) {
found = true;
}
}
// This paramType has a default value... lets fill in that one.
if (!paramType.defaultValue().isNull() && !found) {
found = true;
params.append(Param(paramType.id(), paramType.defaultValue()));
}
if (!found) {
qCWarning(dcDevice) << "Missing parameter:" << paramType.name();
return Device::DeviceErrorMissingParameter;
}
}
return Device::DeviceErrorNoError;
}
/*! Verify if the given \a param matches one of the given \a paramTypes. Returns \l{Device::DeviceError} to inform about the result.*/
Device::DeviceError DeviceUtils::verifyParam(const QList<ParamType> paramTypes, const Param &param)
{
foreach (const ParamType &paramType, paramTypes) {
if (paramType.id() == param.paramTypeId()) {
return verifyParam(paramType, param);
}
}
qCWarning(dcDevice) << "Invalid parameter" << param.paramTypeId().toString() << "in parameter list";
return Device::DeviceErrorInvalidParameter;
}
/*! Verify if the given \a param matches the given \a paramType. Returns \l{Device::DeviceError} to inform about the result.*/
Device::DeviceError DeviceUtils::verifyParam(const ParamType &paramType, const Param &param)
{
if (paramType.id() != param.paramTypeId()) {
qCWarning(dcDevice) << "Parameter id" << param.paramTypeId().toString() << "does not match with ParamType id" << paramType.id().toString();
return Device::DeviceErrorInvalidParameter;
}
if (!param.value().canConvert(static_cast<int>(paramType.type()))) {
qCWarning(dcDevice) << "Wrong parameter type for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Expected:" << QVariant::typeToName(static_cast<int>(paramType.type()));
return Device::DeviceErrorInvalidParameter;
}
if (!param.value().convert(static_cast<int>(paramType.type()))) {
qCWarning(dcDevice) << "Could not convert value of param" << param.paramTypeId().toString() << " to:" << QVariant::typeToName(static_cast<int>(paramType.type())) << " Got:" << param.value();
return Device::DeviceErrorInvalidParameter;
}
if (paramType.type() == QVariant::Int) {
if (paramType.maxValue().isValid() && param.value().toInt() > paramType.maxValue().toInt()) {
qCWarning(dcDevice) << "Value out of range for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Max:" << paramType.maxValue();
return Device::DeviceErrorInvalidParameter;
}
if (paramType.minValue().isValid() && param.value().toInt() < paramType.minValue().toInt()) {
qCWarning(dcDevice) << "Value out of range for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Min:" << paramType.minValue();
return Device::DeviceErrorInvalidParameter;
}
} else if (paramType.type() == QVariant::UInt) {
if (paramType.maxValue().isValid() && param.value().toUInt() > paramType.maxValue().toUInt()) {
qCWarning(dcDevice) << "Value out of range for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Max:" << paramType.maxValue();
return Device::DeviceErrorInvalidParameter;
}
if (paramType.minValue().isValid() && param.value().toUInt() < paramType.minValue().toUInt()) {
qCWarning(dcDevice) << "Value out of range for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Min:" << paramType.minValue();
return Device::DeviceErrorInvalidParameter;
}
} else if (paramType.type() == QVariant::Double) {
if (paramType.maxValue().isValid() && param.value().toDouble() > paramType.maxValue().toDouble()) {
qCWarning(dcDevice) << "Value out of range for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Max:" << paramType.maxValue();
return Device::DeviceErrorInvalidParameter;
}
if (paramType.minValue().isValid() && param.value().toDouble() < paramType.minValue().toDouble()) {
qCWarning(dcDevice) << "Value out of range for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Min:" << paramType.minValue();
return Device::DeviceErrorInvalidParameter;
}
} else {
if (paramType.maxValue().isValid() && param.value() > paramType.maxValue()) {
qCWarning(dcDevice) << "Value out of range for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Max:" << paramType.maxValue();
return Device::DeviceErrorInvalidParameter;
}
if (paramType.minValue().isValid() && param.value() < paramType.minValue()) {
qCWarning(dcDevice) << "Value out of range for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Min:" << paramType.minValue();
return Device::DeviceErrorInvalidParameter;
}
}
if (!paramType.allowedValues().isEmpty() && !paramType.allowedValues().contains(param.value())) {
QStringList allowedValues;
foreach (const QVariant &value, paramType.allowedValues()) {
allowedValues.append(value.toString());
}
qCWarning(dcDevice) << "Value not in allowed values for param" << param.paramTypeId().toString() << " Got:" << param.value() << " Allowed:" << allowedValues.join(",");
return Device::DeviceErrorInvalidParameter;
}
return Device::DeviceErrorNoError;
}
Interfaces DeviceUtils::allInterfaces()
{
Interfaces ret;
QDir dir(":/interfaces/");
foreach (const QFileInfo &ifaceFile, dir.entryInfoList()) {
ret.append(loadInterface(ifaceFile.baseName()));
}
return ret;
}
Interface DeviceUtils::loadInterface(const QString &name)
{
Interface iface;
QFile f(QString(":/interfaces/%1.json").arg(name));
if (!f.open(QFile::ReadOnly)) {
qCWarning(dcDeviceManager()) << "Failed to load interface" << name;
return iface;
}
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(f.readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qCWarning(dcDeviceManager) << "Cannot load interface definition for interface" << name << ":" << error.errorString();
return iface;
}
QVariantMap content = jsonDoc.toVariant().toMap();
if (content.contains("extends")) {
if (!content.value("extends").toString().isEmpty()) {
iface = loadInterface(content.value("extends").toString());
} else if (content.value("extends").toList().count() > 0) {
foreach (const QVariant &extendedIface, content.value("extends").toList()) {
Interface tmp = loadInterface(extendedIface.toString());
iface = mergeInterfaces(iface, tmp);
}
}
}
StateTypes stateTypes;
ActionTypes actionTypes;
EventTypes eventTypes;
foreach (const QVariant &stateVariant, content.value("states").toList()) {
StateType stateType(StateTypeId::fromUuid(QUuid()));
stateType.setName(stateVariant.toMap().value("name").toString());
stateType.setType(QVariant::nameToType(stateVariant.toMap().value("type").toByteArray()));
stateType.setPossibleValues(stateVariant.toMap().value("allowedValues").toList());
stateType.setMinValue(stateVariant.toMap().value("minValue"));
stateType.setMaxValue(stateVariant.toMap().value("maxValue"));
stateTypes.append(stateType);
EventType stateChangeEventType(EventTypeId::fromUuid(QUuid()));
stateChangeEventType.setName(stateType.name());
ParamType stateChangeEventParamType;
stateChangeEventParamType.setName(stateType.name());
stateChangeEventParamType.setType(stateType.type());
stateChangeEventParamType.setAllowedValues(stateType.possibleValues());
stateChangeEventParamType.setMinValue(stateType.minValue());
stateChangeEventParamType.setMaxValue(stateType.maxValue());
stateChangeEventType.setParamTypes(ParamTypes() << stateChangeEventParamType);
eventTypes.append(stateChangeEventType);
if (stateVariant.toMap().value("writable", false).toBool()) {
ActionType stateChangeActionType(ActionTypeId::fromUuid(QUuid()));
stateChangeActionType.setName(stateType.name());
stateChangeActionType.setParamTypes(ParamTypes() << stateChangeEventParamType);
actionTypes.append(stateChangeActionType);
}
}
foreach (const QVariant &actionVariant, content.value("actions").toList()) {
ActionType actionType(ActionTypeId::fromUuid(QUuid()));
actionType.setName(actionVariant.toMap().value("name").toString());
ParamTypes paramTypes;
foreach (const QVariant &actionParamVariant, actionVariant.toMap().value("params").toList()) {
ParamType paramType;
paramType.setName(actionParamVariant.toMap().value("name").toString());
paramType.setType(QVariant::nameToType(actionParamVariant.toMap().value("type").toByteArray()));
paramType.setAllowedValues(actionParamVariant.toMap().value("allowedValues").toList());
paramType.setMinValue(actionParamVariant.toMap().value("min"));
paramTypes.append(paramType);
}
actionType.setParamTypes(paramTypes);
actionTypes.append(actionType);
}
foreach (const QVariant &eventVariant, content.value("events").toList()) {
EventType eventType(EventTypeId::fromUuid(QUuid()));
eventType.setName(eventVariant.toMap().value("name").toString());
ParamTypes paramTypes;
foreach (const QVariant &eventParamVariant, eventVariant.toMap().value("params").toList()) {
ParamType paramType;
paramType.setName(eventParamVariant.toMap().value("name").toString());
paramType.setType(QVariant::nameToType(eventParamVariant.toMap().value("type").toByteArray()));
paramType.setAllowedValues(eventParamVariant.toMap().value("allowedValues").toList());
paramType.setMinValue(eventParamVariant.toMap().value("minValue"));
paramType.setMaxValue(eventParamVariant.toMap().value("maxValue"));
paramTypes.append(paramType);
}
eventType.setParamTypes(paramTypes);
eventTypes.append(eventType);
}
return Interface(name, iface.actionTypes() << actionTypes, iface.eventTypes() << eventTypes, iface.stateTypes() << stateTypes);
}
Interface DeviceUtils::mergeInterfaces(const Interface &iface1, const Interface &iface2)
{
EventTypes eventTypes = iface1.eventTypes();
foreach (const EventType &et, iface2.eventTypes()) {
if (eventTypes.findByName(et.name()).name().isEmpty()) {
eventTypes.append(et);
}
}
StateTypes stateTypes = iface1.stateTypes();
foreach (const StateType &st, iface2.stateTypes()) {
if (stateTypes.findByName(st.name()).name().isEmpty()) {
stateTypes.append(st);
}
}
ActionTypes actionTypes = iface1.actionTypes();
foreach (const ActionType &at, iface2.actionTypes()) {
if (actionTypes.findByName(at.name()).name().isEmpty()) {
actionTypes.append(at);
}
}
return Interface(QString(), actionTypes, eventTypes, stateTypes);
}
QStringList DeviceUtils::generateInterfaceParentList(const QString &interface)
{
QFile f(QString(":/interfaces/%1.json").arg(interface));
if (!f.open(QFile::ReadOnly)) {
qCWarning(dcDeviceManager()) << "Failed to load interface" << interface;
return QStringList();
}
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(f.readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qCWarning(dcDeviceManager) << "Cannot load interface definition for interface" << interface << ":" << error.errorString();
return QStringList();
}
QStringList ret = {interface};
QVariantMap content = jsonDoc.toVariant().toMap();
if (content.contains("extends")) {
if (!content.value("extends").toString().isEmpty()) {
ret << generateInterfaceParentList(content.value("extends").toString());
} else if (content.value("extends").toList().count() > 0) {
foreach (const QVariant &extendedIface, content.value("extends").toList()) {
ret << generateInterfaceParentList(extendedIface.toString());
}
}
}
return ret;
}

View File

@ -0,0 +1,48 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Michael Zanetti <michael.zanetti@nymea.io> *
* *
* This file is part of nymea. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEVICEUTILS_H
#define DEVICEUTILS_H
#include "device.h"
#include "pluginmetadata.h"
#include "types/paramtype.h"
#include "types/interface.h"
class DeviceUtils
{
public:
DeviceUtils();
static Device::DeviceError verifyParams(const QList<ParamType> paramTypes, ParamList &params, bool requireAll = true);
static Device::DeviceError verifyParam(const QList<ParamType> paramTypes, const Param &param);
static Device::DeviceError verifyParam(const ParamType &paramType, const Param &param);
static Interfaces allInterfaces();
static Interface loadInterface(const QString &name);
static Interface mergeInterfaces(const Interface &iface1, const Interface &iface2);
static QStringList generateInterfaceParentList(const QString &interface);
};
#endif // DEVICEUTILS_H

View File

@ -0,0 +1,687 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Michael Zanetti <michael.zanetti@nymea.io> *
* *
* This file is part of nymea. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "pluginmetadata.h"
#include "deviceutils.h"
#include "loggingcategories.h"
#include "types/interface.h"
#include <QJsonObject>
#include <QJsonArray>
#include <QMetaObject>
#include <QMetaEnum>
PluginMetadata::PluginMetadata()
{
}
PluginMetadata::PluginMetadata(const QJsonObject &jsonObject, bool isBuiltIn): m_isBuiltIn(isBuiltIn)
{
parse(jsonObject);
}
bool PluginMetadata::isValid() const
{
return m_isValid;
}
PluginId PluginMetadata::pluginId() const
{
return m_pluginId;
}
QString PluginMetadata::pluginName() const
{
return m_pluginName;
}
QString PluginMetadata::pluginDisplayName() const
{
return m_pluginDisplayName;
}
bool PluginMetadata::isBuiltIn() const
{
return m_isBuiltIn;
}
ParamTypes PluginMetadata::pluginSettings() const
{
return m_pluginSettings;
}
Vendors PluginMetadata::vendors() const
{
return m_vendors;
}
DeviceClasses PluginMetadata::deviceClasses() const
{
return m_deviceClasses;
}
void PluginMetadata::parse(const QJsonObject &jsonObject)
{
// General plugin info
QStringList pluginMandatoryJsonProperties = QStringList() << "id" << "name" << "displayName" << "vendors";
QStringList pluginJsonProperties = QStringList() << "id" << "name" << "displayName" << "vendors" << "paramTypes" << "builtIn";
QPair<QStringList, QStringList> verificationResult = verifyFields(pluginJsonProperties, pluginMandatoryJsonProperties, jsonObject);
if (!verificationResult.first.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping plugin because of missing fields:" << verificationResult.first.join(", ") << endl << jsonObject;
return;
}
if (!verificationResult.second.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping plugin because of unknown fields:" << verificationResult.second.join(", ") << endl << jsonObject;
return;
}
m_pluginId = jsonObject.value("id").toString();
m_pluginName = jsonObject.value("name").toString();
m_pluginDisplayName = jsonObject.value("displayName").toString();
// Mandatory fields available... All the rest will be skipped if not valid, but it won't invalidate the entire meta data
m_isValid = true;
// parse plugin configuration params
if (jsonObject.contains("paramTypes")) {
QPair<bool, QList<ParamType> > paramVerification = parseParamTypes(jsonObject.value("paramTypes").toArray());
if (paramVerification.first) {
m_pluginSettings = paramVerification.second;
}
}
// Load vendors
foreach (const QJsonValue &vendorJson, jsonObject.value("vendors").toArray()) {
bool broken = false;
QJsonObject vendorObject = vendorJson.toObject();
QStringList vendorMandatoryJsonProperties = QStringList() << "id" << "name" << "displayName" << "deviceClasses";
QStringList vendorJsonProperties = QStringList() << "id" << "name" << "displayName" << "deviceClasses";
QPair<QStringList, QStringList> verificationResult = verifyFields(vendorJsonProperties, vendorMandatoryJsonProperties, vendorObject);
// Check mandatory fields
if (!verificationResult.first.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping vendor because of missing fields:" << verificationResult.first.join(", ") << endl << vendorObject;
broken = true;
break;
}
// Check if there are any unknown fields
if (!verificationResult.second.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping vendor because of unknown fields:" << verificationResult.second.join(", ") << endl << vendorObject;
broken = true;
break;
}
VendorId vendorId = VendorId(vendorObject.value("id").toString());
Vendor vendor(vendorId, vendorObject.value("name").toString());
vendor.setDisplayName(vendorObject.value("displayName").toString());
m_vendors.append(vendor);
// Load deviceclasses of this vendor
foreach (const QJsonValue &deviceClassJson, vendorJson.toObject().value("deviceClasses").toArray()) {
QJsonObject deviceClassObject = deviceClassJson.toObject();
/*! Returns a list of all valid JSON properties a DeviceClass JSON definition can have. */
QStringList deviceClassProperties = QStringList() << "id" << "name" << "displayName" << "createMethods" << "setupMethod"
<< "interfaces" << "pairingInfo" << "discoveryParamTypes" << "discoveryParamTypes"
<< "paramTypes" << "settingsTypes" << "stateTypes" << "actionTypes" << "eventTypes";
QStringList mandatoryDeviceClassProperties = QStringList() << "id" << "name" << "displayName";
QPair<QStringList, QStringList> verificationResult = verifyFields(deviceClassProperties, mandatoryDeviceClassProperties, deviceClassObject);
// Check mandatory fields
if (!verificationResult.first.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping device class because of missing fields:" << verificationResult.first.join(", ") << endl << deviceClassObject;
broken = true;
break;
}
// Check if there are any unknown fields
if (!verificationResult.second.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping device class because of unknown fields:" << verificationResult.second.join(", ") << endl << deviceClassObject;
broken = true;
break;
}
DeviceClass deviceClass(pluginId(), vendorId, deviceClassObject.value("id").toString());
deviceClass.setName(deviceClassObject.value("name").toString());
deviceClass.setDisplayName(deviceClassObject.value("displayName").toString());
// Read create methods
DeviceClass::CreateMethods createMethods;
if (!deviceClassObject.contains("createMethods")) {
// Default if not specified
createMethods |= DeviceClass::CreateMethodUser;
} else {
foreach (const QJsonValue &createMethodValue, deviceClassObject.value("createMethods").toArray()) {
if (createMethodValue.toString().toLower() == "discovery") {
createMethods |= DeviceClass::CreateMethodDiscovery;
} else if (createMethodValue.toString().toLower() == "auto") {
createMethods |= DeviceClass::CreateMethodAuto;
} else if (createMethodValue.toString().toLower() == "user") {
createMethods |= DeviceClass::CreateMethodUser;
} else {
qCWarning(dcDevice()) << "Unknown createMehtod" << createMethodValue.toString() << "in deviceClass "
<< deviceClass.name() << ". Falling back to CreateMethodUser.";
createMethods |= DeviceClass::CreateMethodUser;
}
}
}
deviceClass.setCreateMethods(createMethods);
// Read params
QPair<bool, QList<ParamType> > paramTypesVerification = parseParamTypes(deviceClassObject.value("paramTypes").toArray());
if (!paramTypesVerification.first) {
broken = true;
break;
} else {
deviceClass.setParamTypes(paramTypesVerification.second);
}
// Read settings
QPair<bool, QList<ParamType> > settingsTypesVerification = parseParamTypes(deviceClassObject.value("settingsTypes").toArray());
if (!settingsTypesVerification.first) {
broken = true;
break;
} else {
deviceClass.setSettingsTypes(settingsTypesVerification.second);
}
// Read discover params
QPair<bool, QList<ParamType> > discoveryParamVerification = parseParamTypes(deviceClassObject.value("discoveryParamTypes").toArray());
if (!discoveryParamVerification.first) {
broken = true;
break;
} else {
deviceClass.setDiscoveryParamTypes(discoveryParamVerification.second);
}
// Read setup method
DeviceClass::SetupMethod setupMethod = DeviceClass::SetupMethodJustAdd;
if (deviceClassObject.contains("setupMethod")) {
QString setupMethodString = deviceClassObject.value("setupMethod").toString();
if (setupMethodString.toLower() == "pushbutton") {
setupMethod = DeviceClass::SetupMethodPushButton;
} else if (setupMethodString.toLower() == "displaypin") {
setupMethod = DeviceClass::SetupMethodDisplayPin;
} else if (setupMethodString.toLower() == "enterpin") {
setupMethod = DeviceClass::SetupMethodEnterPin;
} else if (setupMethodString.toLower() == "justadd") {
setupMethod = DeviceClass::SetupMethodJustAdd;
} else {
qCWarning(dcDevice()) << "Unknown setupMehtod" << setupMethod << "in deviceClass"
<< deviceClass.name() << ". Falling back to SetupMethodJustAdd.";
setupMethod = DeviceClass::SetupMethodJustAdd;
}
}
deviceClass.setSetupMethod(setupMethod);
// Read pairing info
deviceClass.setPairingInfo(deviceClassObject.value("pairingInfo").toString());
QList<ActionType> actionTypes;
QList<StateType> stateTypes;
QList<EventType> eventTypes;
// Read StateTypes
int index = 0;
foreach (const QJsonValue &stateTypesJson, deviceClassObject.value("stateTypes").toArray()) {
QJsonObject st = stateTypesJson.toObject();
bool writableState = false;
QPair<QStringList, QStringList> verificationResult = verifyFields(StateType::typeProperties(), StateType::mandatoryTypeProperties(), st);
// Check mandatory fields
if (!verificationResult.first.isEmpty()) {
qCWarning(dcDevice()) << "Skipping device class" << deviceClass.name() << "because of missing" << verificationResult.first.join(", ") << "in stateType" << st;
broken = true;
break;
}
// Check if there are any unknown fields
if (!verificationResult.second.isEmpty()) {
qCWarning(dcDevice()) << "Skipping device class" << deviceClass.name() << "because of unknown properties" << verificationResult.second.join(", ") << "in stateType" << st;
broken = true;
break;
}
// If this is a writable stateType, there must be also the displayNameAction property
if (st.contains("writable") && st.value("writable").toBool()) {
writableState = true;
if (!st.contains("displayNameAction")) {
qCWarning(dcDevice()) << "Skipping device class" << deviceClass.name() << ". The state is writable, but does not define the displayNameAction property" << st;
broken = true;
break;
}
}
QVariant::Type t = QVariant::nameToType(st.value("type").toString().toLatin1().data());
if (t == QVariant::Invalid) {
qCWarning(dcDevice()) << "Invalid StateType type:" << st.value("type").toString();
broken = true;
break;
}
StateType stateType(st.value("id").toString());
stateType.setName(st.value("name").toString());
stateType.setDisplayName(st.value("displayName").toString());
stateType.setIndex(index++);
stateType.setType(t);
QPair<bool, Types::Unit> unitVerification = loadAndVerifyUnit(st.value("unit").toString());
if (!unitVerification.first) {
broken = true;
break;
} else {
stateType.setUnit(unitVerification.second);
}
stateType.setDefaultValue(st.value("defaultValue").toVariant());
if (st.contains("minValue"))
stateType.setMinValue(st.value("minValue").toVariant());
if (st.contains("maxValue"))
stateType.setMaxValue(st.value("maxValue").toVariant());
if (st.contains("possibleValues")) {
QVariantList possibleValues;
foreach (const QJsonValue &possibleValueJson, st.value("possibleValues").toArray()) {
possibleValues.append(possibleValueJson.toVariant());
}
stateType.setPossibleValues(possibleValues);
if (!stateType.possibleValues().contains(stateType.defaultValue())) {
qCWarning(dcDevice()) << QString("\"%1\" plugin:").arg(pluginName()).toLatin1().data() << QString("The given default value \"%1\" is not in the possible values of the stateType \"%2\".")
.arg(stateType.defaultValue().toString()).arg(stateType.name()).toLatin1().data();
broken = true;
break;
}
}
if (st.contains("cached")) {
stateType.setCached(st.value("cached").toBool());
}
stateTypes.append(stateType);
// Events for state changed
EventType eventType(EventTypeId(stateType.id().toString()));
eventType.setName(st.value("name").toString());
eventType.setDisplayName(st.value("displayNameEvent").toString());
ParamType paramType(ParamTypeId(stateType.id().toString()), st.value("name").toString(), stateType.type());
paramType.setDisplayName(st.value("displayName").toString());
paramType.setAllowedValues(stateType.possibleValues());
paramType.setDefaultValue(stateType.defaultValue());
paramType.setMinValue(stateType.minValue());
paramType.setMaxValue(stateType.maxValue());
paramType.setUnit(stateType.unit());
eventType.setParamTypes(QList<ParamType>() << paramType);
eventType.setIndex(stateType.index());
eventTypes.append(eventType);
// ActionTypes for writeable StateTypes
if (writableState) {
ActionType actionType(ActionTypeId(stateType.id().toString()));
actionType.setName(stateType.name());
actionType.setDisplayName(st.value("displayNameAction").toString());
actionType.setIndex(stateType.index());
actionType.setParamTypes(QList<ParamType>() << paramType);
actionTypes.append(actionType);
}
}
deviceClass.setStateTypes(stateTypes);
// ActionTypes
index = 0;
foreach (const QJsonValue &actionTypesJson, deviceClassObject.value("actionTypes").toArray()) {
QJsonObject at = actionTypesJson.toObject();
QPair<QStringList, QStringList> verificationResult = verifyFields(ActionType::typeProperties(), ActionType::mandatoryTypeProperties(), at);
// Check mandatory fields
if (!verificationResult.first.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping device class" << deviceClass.name() << "because of missing" << verificationResult.first.join(", ") << "in action type:" << endl << at;
broken = true;
break;
}
// Check if there are any unknown fields
if (!verificationResult.second.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping device class" << deviceClass.name() << "because of unknown fields:" << verificationResult.second.join(", ") << "in action type:" << endl << at;
broken = true;
break;
}
ActionType actionType(at.value("id").toString());
actionType.setName(at.value("name").toString());
actionType.setDisplayName(at.value("displayName").toString());
actionType.setIndex(index++);
QPair<bool, QList<ParamType> > paramVerification = parseParamTypes(at.value("paramTypes").toArray());
if (!paramVerification.first) {
broken = true;
break;
} else {
actionType.setParamTypes(paramVerification.second);
}
actionTypes.append(actionType);
}
deviceClass.setActionTypes(actionTypes);
// EventTypes
index = 0;
foreach (const QJsonValue &eventTypesJson, deviceClassObject.value("eventTypes").toArray()) {
QJsonObject et = eventTypesJson.toObject();
QPair<QStringList, QStringList> verificationResult = verifyFields(EventType::typeProperties(), EventType::mandatoryTypeProperties(), et);
// Check mandatory fields
if (!verificationResult.first.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping device class" << deviceClass.name() << "because of missing" << verificationResult.first.join(", ") << "in event type:" << endl << et;
broken = true;
break;
}
// Check if there are any unknown fields
if (!verificationResult.second.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Skipping device class" << deviceClass.name() << "because of unknown fields:" << verificationResult.second.join(", ") << "in event type:" << endl << et;
broken = true;
break;
}
EventType eventType(et.value("id").toString());
eventType.setName(et.value("name").toString());
eventType.setDisplayName(et.value("displayName").toString());
eventType.setIndex(index++);
QPair<bool, QList<ParamType> > paramVerification = parseParamTypes(et.value("paramTypes").toArray());
if (!paramVerification.first) {
broken = true;
break;
} else {
eventType.setParamTypes(paramVerification.second);
}
eventTypes.append(eventType);
}
deviceClass.setEventTypes(eventTypes);
// Read interfaces
QStringList interfaces;
foreach (const QJsonValue &value, deviceClassObject.value("interfaces").toArray()) {
Interface iface = DeviceUtils::loadInterface(value.toString());
StateTypes stateTypes(deviceClass.stateTypes());
ActionTypes actionTypes(deviceClass.actionTypes());
EventTypes eventTypes(deviceClass.eventTypes());
bool valid = true;
foreach (const StateType &ifaceStateType, iface.stateTypes()) {
StateType stateType = stateTypes.findByName(ifaceStateType.name());
if (stateType.id().isNull()) {
qCWarning(dcDevice()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but doesn't implement state" << ifaceStateType.name();
valid = false;
continue;
}
if (ifaceStateType.type() != stateType.type()) {
qCWarning(dcDevice()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateType.name() << "has not matching type" << stateType.type() << "!=" << ifaceStateType.type();
valid = false;
continue;
}
if (ifaceStateType.minValue().isValid() && !ifaceStateType.minValue().isNull()) {
if (ifaceStateType.minValue().toString() == "any") {
if (stateType.minValue().isNull()) {
qCWarning(dcDevice()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateType.name() << "has no minimum value defined.";
valid = false;
continue;
}
} else if (ifaceStateType.minValue() != stateType.minValue()) {
qCWarning(dcDevice()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateType.name() << "has not matching minimum value:" << ifaceStateType.minValue() << "!=" << stateType.minValue();
valid = false;
continue;
}
}
if (ifaceStateType.maxValue().isValid() && !ifaceStateType.maxValue().isNull()) {
if (ifaceStateType.maxValue().toString() == "any") {
if (stateType.maxValue().isNull()) {
qCWarning(dcDevice()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateType.name() << "has no maximum value defined.";
valid = false;
continue;
}
} else if (ifaceStateType.maxValue() != stateType.maxValue()) {
qCWarning(dcDevice()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateType.name() << "has not matching maximum value:" << ifaceStateType.maxValue() << "!=" << stateType.minValue();
valid = false;
continue;
}
}
if (!ifaceStateType.possibleValues().isEmpty() && ifaceStateType.possibleValues() != stateType.possibleValues()) {
qCWarning(dcDevice()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateType.name() << "has not matching allowed values" << ifaceStateType.possibleValues() << "!=" << stateType.possibleValues();
valid = false;
continue;
}
}
foreach (const ActionType &ifaceActionType, iface.actionTypes()) {
ActionType actionType = actionTypes.findByName(ifaceActionType.name());
if (actionType.id().isNull()) {
qCWarning(dcDevice) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but doesn't implement action" << ifaceActionType.name();
valid = false;
}
foreach (const ParamType &ifaceActionParamType, ifaceActionType.paramTypes()) {
ParamType paramType = actionType.paramTypes().findByName(ifaceActionParamType.name());
if (!paramType.isValid()) {
qCWarning(dcDevice) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but doesn't implement action param" << ifaceActionType.name() << ":" << ifaceActionParamType.name();
valid = false;
} else {
if (paramType.type() != ifaceActionParamType.type()) {
qCWarning(dcDevice()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but param" << paramType.name() << "is of wrong type:" << QVariant::typeToName(paramType.type()) << "expected:" << QVariant::typeToName(ifaceActionParamType.type());
valid = false;
}
}
}
}
foreach (const EventType &ifaceEventType, iface.eventTypes()) {
EventType eventType = eventTypes.findByName(ifaceEventType.name());
if (!eventType.isValid()) {
qCWarning(dcDevice) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but doesn't implement event" << ifaceEventType.name();
valid = false;
}
foreach (const ParamType &ifaceEventParamType, ifaceEventType.paramTypes()) {
ParamType paramType = eventType.paramTypes().findByName(ifaceEventParamType.name());
if (!paramType.isValid()) {
qCWarning(dcDevice) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but doesn't implement event param" << ifaceEventType.name() << ":" << ifaceEventParamType.name();
valid = false;
} else {
if (paramType.type() != ifaceEventParamType.type()) {
qCWarning(dcDevice()) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but param" << paramType.name() << "is of wrong type:" << QVariant::typeToName(paramType.type()) << "expected:" << QVariant::typeToName(ifaceEventParamType.type());
valid = false;
}
}
}
}
if (valid) {
interfaces.append(DeviceUtils::generateInterfaceParentList(value.toString()));
}
}
interfaces.removeDuplicates();
deviceClass.setInterfaces(interfaces);
if (!broken) {
m_deviceClasses.append(deviceClass);
} else {
qCWarning(dcDevice()) << "Skipping device class" << deviceClass.name();
}
}
}
}
QPair<bool, Types::Unit> PluginMetadata::loadAndVerifyUnit(const QString &unitString)
{
if (unitString.isEmpty())
return QPair<bool, Types::Unit>(true, Types::UnitNone);
QMetaObject metaObject = Types::staticMetaObject;
int enumIndex = metaObject.indexOfEnumerator(QString("Unit").toLatin1().data());
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
int enumValue = -1;
for (int i = 0; i < metaEnum.keyCount(); i++) {
if (QString(metaEnum.valueToKey(metaEnum.value(i))) == QString("Unit" + unitString)) {
enumValue = metaEnum.value(i);
break;
}
}
// inform the plugin developer about the error in the plugin json file
if (enumValue == -1) {
qCWarning(dcDeviceManager()) << QString("\"%1\" plugin:").arg(pluginName()).toLatin1().data() << QString("Invalid unit type \"%1\" in json file.").arg(unitString).toLatin1().data();
return QPair<bool, Types::Unit>(false, Types::UnitNone);
}
return QPair<bool, Types::Unit>(true, (Types::Unit)enumValue);
}
QPair<QStringList, QStringList> PluginMetadata::verifyFields(const QStringList &possibleFields, const QStringList &mandatoryFields, const QJsonObject &value)
{
QStringList missingFields;
QStringList unknownFields;
// Check if we have an unknown field
foreach (const QString &property, value.keys()) {
if (!possibleFields.contains(property)) {
unknownFields << property;
}
}
// Check if a mandatory field is missing
foreach (const QString &field, mandatoryFields) {
if (!value.contains(field)) {
missingFields << field;
}
}
return QPair<QStringList, QStringList>(missingFields, unknownFields);
}
QPair<bool, ParamTypes> PluginMetadata::parseParamTypes(const QJsonArray &array)
{
int index = 0;
QList<ParamType> paramTypes;
foreach (const QJsonValue &paramTypesJson, array) {
QJsonObject pt = paramTypesJson.toObject();
QPair<QStringList, QStringList> verificationResult = verifyFields(ParamType::typeProperties(), ParamType::mandatoryTypeProperties(), pt);
// Check mandatory fields
if (!verificationResult.first.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Error parsing ParamType: missing fields:" << verificationResult.first.join(", ") << endl << pt;
return QPair<bool, QList<ParamType> >(false, QList<ParamType>());
}
// Check if there are any unknown fields
if (!verificationResult.second.isEmpty()) {
qCWarning(dcDevice()) << pluginName() << "Error parsing ParamType: unknown fields:" << verificationResult.second.join(", ") << endl << pt;
return QPair<bool, QList<ParamType> >(false, QList<ParamType>());
}
// Check type
QVariant::Type t = QVariant::nameToType(pt.value("type").toString().toLatin1().data());
if (t == QVariant::Invalid) {
qCWarning(dcDevice()) << pluginName() << QString("Invalid type %1 for param %2 in json file.")
.arg(pt.value("type").toString())
.arg(pt.value("name").toString()).toLatin1().data();
return QPair<bool, QList<ParamType> >(false, QList<ParamType>());
}
ParamType paramType(ParamTypeId(pt.value("id").toString()), pt.value("name").toString(), t, pt.value("defaultValue").toVariant());
paramType.setDisplayName(pt.value("displayName").toString());
// Set allowed values
QVariantList allowedValues;
foreach (const QJsonValue &allowedTypesJson, pt.value("allowedValues").toArray()) {
allowedValues.append(allowedTypesJson.toVariant());
}
// Set the input type if there is any
if (pt.contains("inputType")) {
QPair<bool, Types::InputType> inputTypeVerification = loadAndVerifyInputType(pt.value("inputType").toString());
if (!inputTypeVerification.first) {
qCWarning(dcDevice()) << pluginName() << QString("Invalid inputType for paramType") << pt;
return QPair<bool, QList<ParamType> >(false, QList<ParamType>());
} else {
paramType.setInputType(inputTypeVerification.second);
}
}
// set the unit if there is any
if (pt.contains("unit")) {
QPair<bool, Types::Unit> unitVerification = loadAndVerifyUnit(pt.value("unit").toString());
if (!unitVerification.first) {
qCWarning(dcDevice()) << pluginName() << QString("Invalid unit type for paramType") << pt;
return QPair<bool, QList<ParamType> >(false, QList<ParamType>());
} else {
paramType.setUnit(unitVerification.second);
}
}
// set readOnly if given (default false)
if (pt.contains("readOnly"))
paramType.setReadOnly(pt.value("readOnly").toBool());
paramType.setAllowedValues(allowedValues);
paramType.setLimits(pt.value("minValue").toVariant(), pt.value("maxValue").toVariant());
paramType.setIndex(index++);
paramTypes.append(paramType);
}
return QPair<bool, QList<ParamType> >(true, paramTypes);
}
QPair<bool, Types::InputType> PluginMetadata::loadAndVerifyInputType(const QString &inputType)
{
if (inputType.isEmpty())
return QPair<bool, Types::InputType>(true, Types::InputTypeNone);
QMetaObject metaObject = Types::staticMetaObject;
int enumIndex = metaObject.indexOfEnumerator(QString("InputType").toLatin1().data());
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
int enumValue = -1;
for (int i = 0; i < metaEnum.keyCount(); i++) {
if (QString(metaEnum.valueToKey(metaEnum.value(i))) == QString("InputType" + inputType)) {
enumValue = metaEnum.value(i);
break;
}
}
// inform the plugin developer about the error in the plugin json file
if (enumValue == -1) {
qCWarning(dcDeviceManager()) << QString("\"%1\" plugin:").arg(pluginName()).toLatin1().data() << QString("Invalid inputType \"%1\" in json file.").arg(inputType).toLatin1().data();
return QPair<bool, Types::InputType>(false, Types::InputTypeNone);
}
return QPair<bool, Types::InputType>(true, (Types::InputType)enumValue);
}

View File

@ -0,0 +1,66 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Michael Zanetti <michael.zanetti@nymea.io> *
* *
* This file is part of nymea. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef PLUGINMETADATA_H
#define PLUGINMETADATA_H
#include "types/paramtype.h"
#include "types/deviceclass.h"
class PluginMetadata
{
public:
PluginMetadata();
PluginMetadata(const QJsonObject &jsonObject, bool isBuiltIn = false);
bool isValid() const;
PluginId pluginId() const;
QString pluginName() const;
QString pluginDisplayName() const;
bool isBuiltIn() const;
ParamTypes pluginSettings() const;
Vendors vendors() const;
DeviceClasses deviceClasses() const;
private:
void parse(const QJsonObject &jsonObject);
QPair<bool, ParamTypes> parseParamTypes(const QJsonArray &array);
QPair<QStringList, QStringList> verifyFields(const QStringList &possibleFields, const QStringList &mandatoryFields, const QJsonObject &value);
QPair<bool, Types::Unit> loadAndVerifyUnit(const QString &unitString);
QPair<bool, Types::InputType> loadAndVerifyInputType(const QString &inputType);
private:
bool m_isValid = false;
bool m_isBuiltIn = false;
PluginId m_pluginId;
QString m_pluginName;
QString m_pluginDisplayName;
ParamTypes m_pluginSettings;
Vendors m_vendors;
DeviceClasses m_deviceClasses;
};
#endif // PLUGINMETADATA_H

View File

@ -8,17 +8,20 @@ DEFINES += LIBNYMEA_LIBRARY
QMAKE_LFLAGS += -fPIC
HEADERS += devicemanager.h \
HEADERS += \
devices/devicemanager.h \
devices/deviceutils.h \
devices/pluginmetadata.h \
libnymea.h \
platform/package.h \
platform/repository.h \
typeutils.h \
loggingcategories.h \
nymeasettings.h \
plugin/device.h \
plugin/deviceplugin.h \
plugin/devicedescriptor.h \
plugin/devicepairinginfo.h \
devices/device.h \
devices/deviceplugin.h \
devices/devicedescriptor.h \
devices/devicepairinginfo.h \
hardware/gpio.h \
hardware/gpiomonitor.h \
hardware/pwm.h \
@ -66,20 +69,22 @@ HEADERS += devicemanager.h \
nymeadbusservice.h \
network/mqtt/mqttprovider.h \
network/mqtt/mqttchannel.h \
translator.h \
platform/platformsystemcontroller.h \
platform/platformupdatecontroller.h \
platform/platformzeroconfcontroller.h \
SOURCES += devicemanager.cpp \
SOURCES += \
devices/devicemanager.cpp \
devices/deviceutils.cpp \
devices/pluginmetadata.cpp \
loggingcategories.cpp \
nymeasettings.cpp \
platform/package.cpp \
platform/repository.cpp \
plugin/device.cpp \
plugin/deviceplugin.cpp \
plugin/devicedescriptor.cpp \
plugin/devicepairinginfo.cpp \
devices/device.cpp \
devices/deviceplugin.cpp \
devices/devicedescriptor.cpp \
devices/devicepairinginfo.cpp \
hardware/gpio.cpp \
hardware/gpiomonitor.cpp \
hardware/pwm.cpp \
@ -127,7 +132,6 @@ SOURCES += devicemanager.cpp \
nymeadbusservice.cpp \
network/mqtt/mqttprovider.cpp \
network/mqtt/mqttchannel.cpp \
translator.cpp \
platform/platformsystemcontroller.cpp \
platform/platformupdatecontroller.cpp \
platform/platformzeroconfcontroller.cpp \
@ -139,12 +143,12 @@ RESOURCES += \
## Install instructions
# install plugininfo python script for libnymea-dev
generateplugininfo.files = plugin/nymea-generateplugininfo
generateplugininfo.files = devices/nymea-generateplugininfo
generateplugininfo.path = $$[QT_INSTALL_PREFIX]/bin
INSTALLS += generateplugininfo
# install plugin.pri for external plugins
pluginpri.files = plugin/plugin.pri
pluginpri.files = devices/plugin.pri
pluginpri.path = $$[QT_INSTALL_PREFIX]/include/nymea/
INSTALLS += pluginpri

View File

@ -23,6 +23,7 @@
#include "loggingcategories.h"
Q_LOGGING_CATEGORY(dcApplication, "Application")
Q_LOGGING_CATEGORY(dcDevice, "Device")
Q_LOGGING_CATEGORY(dcDeviceManager, "DeviceManager")
Q_LOGGING_CATEGORY(dcSystem, "System")
Q_LOGGING_CATEGORY(dcPlatform, "Platform")

View File

@ -28,6 +28,7 @@
// Core / libnymea
Q_DECLARE_LOGGING_CATEGORY(dcApplication)
Q_DECLARE_LOGGING_CATEGORY(dcDevice)
Q_DECLARE_LOGGING_CATEGORY(dcDeviceManager)
Q_DECLARE_LOGGING_CATEGORY(dcSystem)
Q_DECLARE_LOGGING_CATEGORY(dcPlatform)

View File

@ -32,7 +32,6 @@
#include <QUrl>
#include "libnymea.h"
#include "devicemanager.h"
#include "hardwareresource.h"
#include "upnpdiscoveryreply.h"
#include "upnpdevicedescriptor.h"

File diff suppressed because it is too large Load Diff

View File

@ -314,22 +314,27 @@ bool DeviceClass::operator==(const DeviceClass &deviceClass) const
return m_id == deviceClass.id();
}
/*! Returns a list of all valid JSON properties a DeviceClass JSON definition can have. */
QStringList DeviceClass::typeProperties()
{
return QStringList() << "id" << "name" << "displayName" << "createMethods" << "setupMethod"
<< "interfaces" << "pairingInfo" << "discoveryParamTypes" << "discoveryParamTypes"
<< "paramTypes" << "settingsTypes" << "stateTypes" << "actionTypes" << "eventTypes";
}
/*! Returns a list of mandatory JSON properties a DeviceClass JSON definition must have. */
QStringList DeviceClass::mandatoryTypeProperties()
{
return QStringList() << "id" << "name" << "displayName";
}
QDebug operator<<(QDebug &dbg, const DeviceClass &deviceClass)
{
dbg << "DeviceClass ID:" << deviceClass.id() << "Name:" << deviceClass.name();
return dbg;
}
DeviceClasses::DeviceClasses()
{
}
DeviceClasses::DeviceClasses(const QList<DeviceClass> &other): QList<DeviceClass> (other)
{
}
DeviceClass DeviceClasses::findById(const DeviceClassId &id) const
{
foreach (const DeviceClass &deviceClass, *this) {
if (deviceClass.id() == id) {
return deviceClass;
}
}
return DeviceClass();
}

View File

@ -107,9 +107,6 @@ public:
bool operator==(const DeviceClass &device) const;
static QStringList typeProperties();
static QStringList mandatoryTypeProperties();
private:
DeviceClassId m_id;
VendorId m_vendorId;
@ -132,4 +129,12 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(DeviceClass::CreateMethods)
QDebug operator<<(QDebug &dbg, const DeviceClass &deviceClass);
class LIBNYMEA_EXPORT DeviceClasses: public QList<DeviceClass>
{
public:
DeviceClasses();
DeviceClasses(const QList<DeviceClass> &other);
DeviceClass findById(const DeviceClassId &id) const;
};
#endif

View File

@ -47,7 +47,7 @@ private:
StateTypes m_stateTypes;
};
class Interfaces: public QList<Interface>
class LIBNYMEA_EXPORT Interfaces: public QList<Interface>
{
public:
Interfaces() = default;

View File

@ -97,6 +97,18 @@ QDebug operator<<(QDebug dbg, const ParamList &params)
\sa Param,
*/
/*! Constructs an empty ParamList. */
ParamList::ParamList()
{
}
/*! Constructs a ParamList from a QList<Param>. */
ParamList::ParamList(const QList<Param> &other): QList<Param>(other)
{
}
/*! Returns true if this ParamList contains a Param with the given \a paramTypeId. */
bool ParamList::hasParam(const ParamTypeId &paramTypeId) const
{

View File

@ -53,6 +53,8 @@ QDebug operator<<(QDebug dbg, const Param &param);
class LIBNYMEA_EXPORT ParamList: public QList<Param>
{
public:
ParamList();
ParamList(const QList<Param> &other);
bool hasParam(const ParamTypeId &paramTypeId) const;
QVariant paramValue(const ParamTypeId &paramTypeId) const;
bool setParamValue(const ParamTypeId &paramTypeId, const QVariant &value);

View File

@ -251,11 +251,8 @@ QDebug operator<<(QDebug dbg, const QList<ParamType> &paramTypes)
return dbg.space();
}
ParamTypes::ParamTypes(const QList<ParamType> &other)
ParamTypes::ParamTypes(const QList<ParamType> &other): QList<ParamType>(other)
{
foreach (const ParamType &pt, other) {
append(pt);
}
}
ParamType ParamTypes::findByName(const QString &name)

View File

@ -79,3 +79,23 @@ bool Vendor::operator==(const Vendor &other) const
{
return m_id == other.id();
}
Vendors::Vendors()
{
}
Vendors::Vendors(const QList<Vendor> &other): QList<Vendor>(other)
{
}
Vendor Vendors::findById(const VendorId &vendorId) const
{
foreach (const Vendor &vendor, *this) {
if (vendor.id() == vendorId) {
return vendor;
}
}
return Vendor(VendorId());
}

View File

@ -28,6 +28,7 @@
#include "typeutils.h"
#include <QString>
#include <QList>
class LIBNYMEA_EXPORT Vendor
{
@ -51,4 +52,13 @@ private:
QString m_displayName;
};
class LIBNYMEA_EXPORT Vendors: public QList<Vendor>
{
public:
Vendors();
Vendors(const QList<Vendor> &other);
Vendor findById(const VendorId &vendorId) const;
};
#endif // VENDOR_H

View File

@ -41,14 +41,13 @@
#include "devicepluginmock.h"
#include "httpdaemon.h"
#include "plugin/device.h"
#include "devicemanager.h"
#include "devices/device.h"
#include "plugininfo.h"
#include <QDebug>
#include <QColor>
#include <QStringList>
#include <QTimer>
DevicePluginMock::DevicePluginMock()
{
@ -59,28 +58,28 @@ DevicePluginMock::~DevicePluginMock()
{
}
DeviceManager::DeviceError DevicePluginMock::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
Device::DeviceError DevicePluginMock::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{
if (deviceClassId == mockDeviceClassId) {
qCDebug(dcMockDevice) << "starting mock discovery:" << params;
m_discoveredDeviceCount = params.paramValue(mockDiscoveryResultCountParamTypeId).toInt();
QTimer::singleShot(1000, this, SLOT(emitDevicesDiscovered()));
return DeviceManager::DeviceErrorAsync;
return Device::DeviceErrorAsync;
} else if (deviceClassId == mockPushButtonDeviceClassId) {
qCDebug(dcMockDevice) << "starting mock push button discovery:" << params;
m_discoveredDeviceCount = params.paramValue(mockPushButtonDiscoveryResultCountParamTypeId).toInt();
QTimer::singleShot(1000, this, SLOT(emitPushButtonDevicesDiscovered()));
return DeviceManager::DeviceErrorAsync;
return Device::DeviceErrorAsync;
} else if (deviceClassId == mockDisplayPinDeviceClassId) {
qCDebug(dcMockDevice) << "starting mock display pin discovery:" << params;
m_discoveredDeviceCount = params.paramValue(mockDisplayPinDiscoveryResultCountParamTypeId).toInt();
QTimer::singleShot(1000, this, SLOT(emitDisplayPinDevicesDiscovered()));
return DeviceManager::DeviceErrorAsync;
return Device::DeviceErrorAsync;
}
return DeviceManager::DeviceErrorDeviceClassNotFound;
return Device::DeviceErrorDeviceClassNotFound;
}
DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
Device::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
{
if (device->deviceClassId() == mockDeviceClassId || device->deviceClassId() == mockDeviceAutoDeviceClassId) {
bool async = false;
@ -95,7 +94,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
if (broken) {
qCWarning(dcMockDevice) << "This device is intentionally broken.";
return DeviceManager::DeviceSetupStatusFailure;
return Device::DeviceSetupStatusFailure;
}
HttpDaemon *daemon = new HttpDaemon(device, this);
@ -103,7 +102,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
if (!daemon->isListening()) {
qCWarning(dcMockDevice) << "HTTP port opening failed:" << device->paramValue(mockDeviceHttpportParamTypeId).toInt();
return DeviceManager::DeviceSetupStatusFailure;
return Device::DeviceSetupStatusFailure;
}
connect(daemon, &HttpDaemon::triggerEvent, this, &DevicePluginMock::triggerEvent);
@ -115,27 +114,27 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
if (async) {
m_asyncSetupDevices.append(device);
QTimer::singleShot(1000, this, SLOT(emitDeviceSetupFinished()));
return DeviceManager::DeviceSetupStatusAsync;
return Device::DeviceSetupStatusAsync;
}
return DeviceManager::DeviceSetupStatusSuccess;
return Device::DeviceSetupStatusSuccess;
} else if (device->deviceClassId() == mockPushButtonDeviceClassId) {
qCDebug(dcMockDevice) << "Setup PushButton mock device" << device->params();
return DeviceManager::DeviceSetupStatusSuccess;
return Device::DeviceSetupStatusSuccess;
} else if (device->deviceClassId() == mockDisplayPinDeviceClassId) {
qCDebug(dcMockDevice) << "Setup DisplayPin mock device" << device->params();
return DeviceManager::DeviceSetupStatusSuccess;
return Device::DeviceSetupStatusSuccess;
} else if (device->deviceClassId() == mockParentDeviceClassId) {
qCDebug(dcMockDevice) << "Setup Parent mock device" << device->params();
return DeviceManager::DeviceSetupStatusSuccess;
return Device::DeviceSetupStatusSuccess;
} else if (device->deviceClassId() == mockChildDeviceClassId) {
qCDebug(dcMockDevice) << "Setup Child mock device" << device->params();
return DeviceManager::DeviceSetupStatusSuccess;
return Device::DeviceSetupStatusSuccess;
} else if (device->deviceClassId() == mockInputTypeDeviceClassId) {
qCDebug(dcMockDevice) << "Setup InputType mock device" << device->params();
return DeviceManager::DeviceSetupStatusSuccess;
return Device::DeviceSetupStatusSuccess;
}
return DeviceManager::DeviceSetupStatusFailure;
return Device::DeviceSetupStatusFailure;
}
void DevicePluginMock::postSetupDevice(Device *device)
@ -179,7 +178,7 @@ void DevicePluginMock::startMonitoringAutoDevices()
emit autoDevicesAppeared(mockDeviceAutoDeviceClassId, deviceDescriptorList);
}
DeviceManager::DeviceSetupStatus DevicePluginMock::confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret)
Device::DeviceSetupStatus DevicePluginMock::confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret)
{
Q_UNUSED(params)
Q_UNUSED(secret)
@ -189,133 +188,133 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::confirmPairing(const PairingT
if (deviceClassId == mockPushButtonDeviceClassId) {
if (!m_pushbuttonPressed) {
qCDebug(dcMockDevice) << "PushButton not pressed yet!";
return DeviceManager::DeviceSetupStatusFailure;
return Device::DeviceSetupStatusFailure;
}
m_pairingId = pairingTransactionId;
QTimer::singleShot(1000, this, SLOT(onPushButtonPairingFinished()));
return DeviceManager::DeviceSetupStatusAsync;
return Device::DeviceSetupStatusAsync;
} else if (deviceClassId == mockDisplayPinDeviceClassId) {
if (secret != "243681") {
qCWarning(dcMockDevice) << "Invalid pin:" << secret;
return DeviceManager::DeviceSetupStatusFailure;
return Device::DeviceSetupStatusFailure;
}
m_pairingId = pairingTransactionId;
QTimer::singleShot(500, this, SLOT(onDisplayPinPairingFinished()));
return DeviceManager::DeviceSetupStatusAsync;
return Device::DeviceSetupStatusAsync;
}
qCWarning(dcMockDevice) << "Invalid deviceclassId -> no pairing possible with this device";
return DeviceManager::DeviceSetupStatusFailure;
return Device::DeviceSetupStatusFailure;
}
DeviceManager::DeviceError DevicePluginMock::displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor)
Device::DeviceError DevicePluginMock::displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor)
{
Q_UNUSED(pairingTransactionId)
Q_UNUSED(deviceDescriptor)
qCDebug(dcMockDevice) << QString(tr("Display pin!! The pin is 243681"));
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
}
DeviceManager::DeviceError DevicePluginMock::executeAction(Device *device, const Action &action)
Device::DeviceError DevicePluginMock::executeAction(Device *device, const Action &action)
{
if (!myDevices().contains(device))
return DeviceManager::DeviceErrorDeviceNotFound;
return Device::DeviceErrorDeviceNotFound;
if (device->deviceClassId() == mockDeviceClassId) {
if (action.actionTypeId() == mockMockAsyncActionTypeId || action.actionTypeId() == mockMockAsyncFailingActionTypeId) {
m_asyncActions.append(qMakePair<Action, Device*>(action, device));
QTimer::singleShot(1000, this, SLOT(emitActionExecuted()));
return DeviceManager::DeviceErrorAsync;
return Device::DeviceErrorAsync;
}
if (action.actionTypeId() == mockMockFailingActionTypeId)
return DeviceManager::DeviceErrorSetupFailed;
return Device::DeviceErrorSetupFailed;
if (action.actionTypeId() == mockPowerActionTypeId) {
qCDebug(dcMockDevice()) << "Setting power to" << action.param(mockPowerActionPowerParamTypeId).value().toBool();
device->setStateValue(mockPowerStateTypeId, action.param(mockPowerActionPowerParamTypeId).value().toBool());
}
m_daemons.value(device)->actionExecuted(action.actionTypeId());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (device->deviceClassId() == mockDeviceAutoDeviceClassId) {
if (action.actionTypeId() == mockDeviceAutoMockActionAsyncActionTypeId || action.actionTypeId() == mockDeviceAutoMockActionAsyncBrokenActionTypeId) {
m_asyncActions.append(qMakePair<Action, Device*>(action, device));
QTimer::singleShot(1000, this, SLOT(emitActionExecuted()));
return DeviceManager::DeviceErrorAsync;
return Device::DeviceErrorAsync;
}
if (action.actionTypeId() == mockDeviceAutoMockActionBrokenActionTypeId)
return DeviceManager::DeviceErrorSetupFailed;
return Device::DeviceErrorSetupFailed;
m_daemons.value(device)->actionExecuted(action.actionTypeId());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (device->deviceClassId() == mockPushButtonDeviceClassId) {
if (action.actionTypeId() == mockPushButtonColorActionTypeId) {
QString colorString = action.param(mockPushButtonColorActionColorParamTypeId).value().toString();
QColor color(colorString);
if (!color.isValid()) {
qCWarning(dcMockDevice) << "Invalid color parameter";
return DeviceManager::DeviceErrorInvalidParameter;
return Device::DeviceErrorInvalidParameter;
}
device->setStateValue(mockPushButtonColorStateTypeId, colorString);
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockPushButtonPercentageActionTypeId) {
device->setStateValue(mockPushButtonPercentageStateTypeId, action.param(mockPushButtonPercentageActionPercentageParamTypeId).value().toInt());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockPushButtonAllowedValuesActionTypeId) {
device->setStateValue(mockPushButtonAllowedValuesStateTypeId, action.param(mockPushButtonAllowedValuesActionAllowedValuesParamTypeId).value().toString());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockPushButtonDoubleActionTypeId) {
device->setStateValue(mockPushButtonDoubleStateTypeId, action.param(mockPushButtonDoubleActionDoubleParamTypeId).value().toDouble());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockPushButtonBoolActionTypeId) {
device->setStateValue(mockPushButtonBoolStateTypeId, action.param(mockPushButtonBoolActionBoolParamTypeId).value().toBool());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockPushButtonTimeoutActionTypeId) {
return DeviceManager::DeviceErrorAsync;
return Device::DeviceErrorAsync;
}
return DeviceManager::DeviceErrorActionTypeNotFound;
return Device::DeviceErrorActionTypeNotFound;
} else if (device->deviceClassId() == mockDisplayPinDeviceClassId) {
if (action.actionTypeId() == mockDisplayPinColorActionTypeId) {
QString colorString = action.param(mockDisplayPinColorActionColorParamTypeId).value().toString();
QColor color(colorString);
if (!color.isValid()) {
qCWarning(dcMockDevice) << "Invalid color parameter";
return DeviceManager::DeviceErrorInvalidParameter;
return Device::DeviceErrorInvalidParameter;
}
device->setStateValue(mockDisplayPinColorStateTypeId, colorString);
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockDisplayPinPercentageActionTypeId) {
device->setStateValue(mockDisplayPinPercentageStateTypeId, action.param(mockDisplayPinPercentageActionPercentageParamTypeId).value().toInt());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockDisplayPinAllowedValuesActionTypeId) {
device->setStateValue(mockDisplayPinAllowedValuesStateTypeId, action.param(mockDisplayPinAllowedValuesActionAllowedValuesParamTypeId).value().toString());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockDisplayPinDoubleActionTypeId) {
device->setStateValue(mockDisplayPinDoubleStateTypeId, action.param(mockDisplayPinDoubleActionDoubleParamTypeId).value().toDouble());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockDisplayPinBoolActionTypeId) {
device->setStateValue(mockDisplayPinBoolStateTypeId, action.param(mockDisplayPinBoolActionBoolParamTypeId).value().toBool());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == mockDisplayPinTimeoutActionTypeId) {
return DeviceManager::DeviceErrorAsync;
return Device::DeviceErrorAsync;
}
return DeviceManager::DeviceErrorActionTypeNotFound;
return Device::DeviceErrorActionTypeNotFound;
} else if (device->deviceClassId() == mockParentDeviceClassId) {
if (action.actionTypeId() == mockParentBoolValueActionTypeId) {
device->setStateValue(mockParentBoolValueStateTypeId, action.param(mockParentBoolValueActionBoolValueParamTypeId).value().toBool());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
}
return DeviceManager::DeviceErrorActionTypeNotFound;
return Device::DeviceErrorActionTypeNotFound;
} else if (device->deviceClassId() == mockChildDeviceClassId) {
if (action.actionTypeId() == mockChildBoolValueActionTypeId) {
device->setStateValue(mockChildBoolValueStateTypeId, action.param(mockChildBoolValueActionBoolValueParamTypeId).value().toBool());
return DeviceManager::DeviceErrorNoError;
return Device::DeviceErrorNoError;
}
return DeviceManager::DeviceErrorActionTypeNotFound;
return Device::DeviceErrorActionTypeNotFound;
} else if (device->deviceClassId() == mockInputTypeDeviceClassId) {
if (action.actionTypeId() == mockInputTypeWritableBoolActionTypeId) {
device->setStateValue(mockInputTypeWritableBoolStateTypeId, action.param(mockInputTypeWritableBoolActionWritableBoolParamTypeId).value().toULongLong());
@ -346,7 +345,7 @@ DeviceManager::DeviceError DevicePluginMock::executeAction(Device *device, const
}
}
return DeviceManager::DeviceErrorDeviceClassNotFound;
return Device::DeviceErrorDeviceClassNotFound;
}
void DevicePluginMock::setState(const StateTypeId &stateTypeId, const QVariant &value)
@ -506,9 +505,9 @@ void DevicePluginMock::emitDeviceSetupFinished()
qCDebug(dcMockDevice) << "Emitting setup finised";
Device *device = m_asyncSetupDevices.takeFirst();
if (device->paramValue(mockDeviceBrokenParamTypeId).toBool()) {
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
} else {
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
}
}
@ -517,22 +516,22 @@ void DevicePluginMock::emitActionExecuted()
QPair<Action, Device*> action = m_asyncActions.takeFirst();
if (action.first.actionTypeId() == mockMockAsyncActionTypeId) {
m_daemons.value(action.second)->actionExecuted(action.first.actionTypeId());
emit actionExecutionFinished(action.first.id(), DeviceManager::DeviceErrorNoError);
emit actionExecutionFinished(action.first.id(), Device::DeviceErrorNoError);
} else if (action.first.actionTypeId() == mockMockAsyncFailingActionTypeId) {
emit actionExecutionFinished(action.first.id(), DeviceManager::DeviceErrorSetupFailed);
emit actionExecutionFinished(action.first.id(), Device::DeviceErrorSetupFailed);
}
}
void DevicePluginMock::onPushButtonPairingFinished()
{
qCDebug(dcMockDevice) << "Pairing PushButton Device finished";
emit pairingFinished(m_pairingId, DeviceManager::DeviceSetupStatusSuccess);
emit pairingFinished(m_pairingId, Device::DeviceSetupStatusSuccess);
}
void DevicePluginMock::onDisplayPinPairingFinished()
{
qCDebug(dcMockDevice) << "Pairing DisplayPin Device finished";
emit pairingFinished(m_pairingId, DeviceManager::DeviceSetupStatusSuccess);
emit pairingFinished(m_pairingId, Device::DeviceSetupStatusSuccess);
}
void DevicePluginMock::onChildDeviceDiscovered(const DeviceId &parentId)

View File

@ -24,7 +24,7 @@
#ifndef DEVICEPLUGINMOCK_H
#define DEVICEPLUGINMOCK_H
#include "plugin/deviceplugin.h"
#include "devices/deviceplugin.h"
#include <QProcess>
@ -41,19 +41,19 @@ public:
explicit DevicePluginMock();
~DevicePluginMock();
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
Device::DeviceSetupStatus setupDevice(Device *device) override;
void postSetupDevice(Device *device) override;
void deviceRemoved(Device *device) override;
void startMonitoringAutoDevices() override;
DeviceManager::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret) override;
DeviceManager::DeviceError displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor) override;
Device::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret) override;
Device::DeviceError displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor) override;
public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
Device::DeviceError executeAction(Device *device, const Action &action) override;
private slots:
void setState(const StateTypeId &stateTypeId, const QVariant &value);

View File

@ -23,8 +23,8 @@
#include "httpdaemon.h"
#include "plugin/device.h"
#include "plugin/deviceplugin.h"
#include "devices/device.h"
#include "devices/deviceplugin.h"
#include "types/deviceclass.h"
#include "types/statetype.h"
#include "extern-plugininfo.h"

View File

@ -14,7 +14,7 @@ JSONFILE=$$PWD/$$TARGET/deviceplugin"$$TARGET".json
plugininfo.input = JSONFILE
plugininfo.output = plugininfo.h
plugininfo.CONFIG = no_link target_predeps
plugininfo.commands = $$top_srcdir/libnymea/plugin/nymea-generateplugininfo \
plugininfo.commands = $$top_srcdir/libnymea/devices/nymea-generateplugininfo \
--filetype i \
--jsonfile $$PWD/$$TARGET/deviceplugin"$$TARGET".json \
--output plugininfo.h \
@ -22,7 +22,7 @@ plugininfo.commands = $$top_srcdir/libnymea/plugin/nymea-generateplugininfo \
extern-plugininfo.input = JSONFILE
extern-plugininfo.output = extern-plugininfo.h
extern-plugininfo.CONFIG = no_link target_predeps
extern-plugininfo.commands = $$top_srcdir/libnymea/plugin/nymea-generateplugininfo \
extern-plugininfo.commands = $$top_srcdir/libnymea/devices/nymea-generateplugininfo \
--filetype e \
--jsonfile $$PWD/$$TARGET/deviceplugin"$$TARGET".json \
--output extern-plugininfo.h \

View File

@ -105,6 +105,7 @@ int main(int argc, char *argv[])
"Platform",
"PlatformUpdate",
"PlatformZeroConf",
"Device",
"DeviceManager",
"RuleEngine",
"RuleEngineDebug",
@ -141,7 +142,7 @@ int main(int argc, char *argv[])
};
QStringList loggingFiltersPlugins;
foreach (const QJsonObject &pluginMetadata, DeviceManager::pluginsMetadata()) {
foreach (const QJsonObject &pluginMetadata, DeviceManagerImplementation::pluginsMetadata()) {
QString pluginName = pluginMetadata.value("name").toString();
loggingFiltersPlugins << pluginName.left(1).toUpper() + pluginName.mid(1);
}

View File

@ -41,7 +41,7 @@ void TestActions::executeAction_data()
QTest::addColumn<DeviceId>("deviceId");
QTest::addColumn<ActionTypeId>("actionTypeId");
QTest::addColumn<QVariantList>("actionParams");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QVariantList params;
QVariantMap param1;
@ -53,13 +53,13 @@ void TestActions::executeAction_data()
param2.insert("value", true);
params.append(param2);
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::DeviceErrorSetupFailed;
QTest::newRow("async broken action") << m_mockDeviceId << mockActionIdAsyncFailing << QVariantList() << DeviceManager::DeviceErrorSetupFailed;
QTest::newRow("valid action") << m_mockDeviceId << mockActionIdWithParams << params << Device::DeviceErrorNoError;
QTest::newRow("invalid deviceId") << DeviceId::createDeviceId() << mockActionIdWithParams << params << Device::DeviceErrorDeviceNotFound;
QTest::newRow("invalid actionTypeId") << m_mockDeviceId << ActionTypeId::createActionTypeId() << params << Device::DeviceErrorActionTypeNotFound;
QTest::newRow("missing params") << m_mockDeviceId << mockActionIdWithParams << QVariantList() << Device::DeviceErrorMissingParameter;
QTest::newRow("async action") << m_mockDeviceId << mockActionIdAsync << QVariantList() << Device::DeviceErrorNoError;
QTest::newRow("broken action") << m_mockDeviceId << mockActionIdFailing << QVariantList() << Device::DeviceErrorSetupFailed;
QTest::newRow("async broken action") << m_mockDeviceId << mockActionIdAsyncFailing << QVariantList() << Device::DeviceErrorSetupFailed;
}
void TestActions::executeAction()
@ -67,7 +67,7 @@ void TestActions::executeAction()
QFETCH(DeviceId, deviceId);
QFETCH(ActionTypeId, actionTypeId);
QFETCH(QVariantList, actionParams);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QVariantMap params;
params.insert("actionTypeId", actionTypeId);
@ -88,7 +88,7 @@ void TestActions::executeAction()
reply->deleteLater();
QByteArray data = reply->readAll();
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
QVERIFY2(actionTypeId == ActionTypeId(data), QString("ActionTypeId mismatch. Got %1, Expected: %2")
.arg(ActionTypeId(data).toString()).arg(actionTypeId.toString()).toLatin1().data());
} else {
@ -117,16 +117,16 @@ void TestActions::executeAction()
void TestActions::getActionType_data()
{
QTest::addColumn<ActionTypeId>("actionTypeId");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::newRow("valid actiontypeid") << mockActionIdWithParams << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid actiontypeid") << ActionTypeId::createActionTypeId() << DeviceManager::DeviceErrorActionTypeNotFound;
QTest::newRow("valid actiontypeid") << mockActionIdWithParams << Device::DeviceErrorNoError;
QTest::newRow("invalid actiontypeid") << ActionTypeId::createActionTypeId() << Device::DeviceErrorActionTypeNotFound;
}
void TestActions::getActionType()
{
QFETCH(ActionTypeId, actionTypeId);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QVariantMap params;
params.insert("actionTypeId", actionTypeId.toString());
@ -134,7 +134,7 @@ void TestActions::getActionType()
verifyDeviceError(response, error);
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
QVERIFY2(ActionTypeId(response.toMap().value("params").toMap().value("actionType").toMap().value("id").toString()) == actionTypeId, "Didn't get a reply for the same actionTypeId as requested.");
}
}

View File

@ -120,16 +120,16 @@ void TestDevices::getPlugins()
void TestDevices::getPluginConfig_data()
{
QTest::addColumn<PluginId>("pluginId");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::newRow("valid plugin") << mockPluginId << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid plugin") << PluginId::createPluginId() << DeviceManager::DeviceErrorPluginNotFound;
QTest::newRow("valid plugin") << mockPluginId << Device::DeviceErrorNoError;
QTest::newRow("invalid plugin") << PluginId::createPluginId() << Device::DeviceErrorPluginNotFound;
}
void TestDevices::getPluginConfig()
{
QFETCH(PluginId, pluginId);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QVariantMap params;
params.insert("pluginId", pluginId);
@ -141,20 +141,20 @@ void TestDevices::setPluginConfig_data()
{
QTest::addColumn<PluginId>("pluginId");
QTest::addColumn<QVariant>("value");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
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;
QTest::newRow("valid") << mockPluginId << QVariant(13) << Device::DeviceErrorNoError;
QTest::newRow("invalid plugin") << PluginId::createPluginId() << QVariant(13) << Device::DeviceErrorPluginNotFound;
QTest::newRow("too big") << mockPluginId << QVariant(130) << Device::DeviceErrorInvalidParameter;
QTest::newRow("too small") << mockPluginId << QVariant(-13) << Device::DeviceErrorInvalidParameter;
QTest::newRow("wrong type") << mockPluginId << QVariant("wrontType") << Device::DeviceErrorInvalidParameter;
}
void TestDevices::setPluginConfig()
{
QFETCH(PluginId, pluginId);
QFETCH(QVariant, value);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QVariantMap params;
params.insert("pluginId", pluginId);
@ -168,7 +168,7 @@ void TestDevices::setPluginConfig()
QVariant response = injectAndWait("Devices.SetPluginConfiguration", params);
verifyDeviceError(response, error);
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
params.clear();
params.insert("pluginId", pluginId);
response = injectAndWait("Devices.GetPluginConfiguration", params);
@ -252,7 +252,7 @@ void TestDevices::addConfiguredDevice_data()
{
QTest::addColumn<DeviceClassId>("deviceClassId");
QTest::addColumn<QVariantList>("deviceParams");
QTest::addColumn<DeviceManager::DeviceError>("deviceError");
QTest::addColumn<Device::DeviceError>("deviceError");
QVariantMap httpportParam;
httpportParam.insert("paramTypeId", httpportParamTypeId.toString());
@ -267,27 +267,27 @@ void TestDevices::addConfiguredDevice_data()
QVariantList deviceParams;
deviceParams.clear(); deviceParams << httpportParam;
QTest::newRow("User, JustAdd") << mockDeviceClassId << deviceParams << DeviceManager::DeviceErrorNoError;
QTest::newRow("User, JustAdd") << mockDeviceClassId << deviceParams << Device::DeviceErrorNoError;
deviceParams.clear(); deviceParams << httpportParam << asyncParam;
QTest::newRow("User, JustAdd, Async") << mockDeviceClassId << deviceParams << DeviceManager::DeviceErrorNoError;
QTest::newRow("Invalid DeviceClassId") << DeviceClassId::createDeviceClassId() << deviceParams << DeviceManager::DeviceErrorDeviceClassNotFound;
QTest::newRow("User, JustAdd, Async") << mockDeviceClassId << deviceParams << Device::DeviceErrorNoError;
QTest::newRow("Invalid DeviceClassId") << DeviceClassId::createDeviceClassId() << deviceParams << Device::DeviceErrorDeviceClassNotFound;
deviceParams.clear(); deviceParams << httpportParam << brokenParam;
QTest::newRow("Setup failure") << mockDeviceClassId << deviceParams << DeviceManager::DeviceErrorSetupFailed;
QTest::newRow("Setup failure") << mockDeviceClassId << deviceParams << Device::DeviceErrorSetupFailed;
deviceParams.clear(); deviceParams << httpportParam << asyncParam << brokenParam;
QTest::newRow("Setup failure, Async") << mockDeviceClassId << deviceParams << DeviceManager::DeviceErrorSetupFailed;
QTest::newRow("Setup failure, Async") << mockDeviceClassId << deviceParams << Device::DeviceErrorSetupFailed;
QVariantList invalidDeviceParams;
QTest::newRow("User, JustAdd, missing params") << mockDeviceClassId << invalidDeviceParams << DeviceManager::DeviceErrorMissingParameter;
QTest::newRow("User, JustAdd, missing params") << mockDeviceClassId << invalidDeviceParams << Device::DeviceErrorMissingParameter;
QVariantMap fakeparam;
fakeparam.insert("paramTypeId", ParamTypeId::createParamTypeId());
invalidDeviceParams.append(fakeparam);
QTest::newRow("User, JustAdd, invalid param") << mockDeviceClassId << invalidDeviceParams << DeviceManager::DeviceErrorInvalidParameter;
QTest::newRow("User, JustAdd, invalid param") << mockDeviceClassId << invalidDeviceParams << Device::DeviceErrorInvalidParameter;
fakeparam.insert("value", "buhuu");
invalidDeviceParams.clear();
invalidDeviceParams.append(fakeparam);
QTest::newRow("User, JustAdd, wrong param") << mockDeviceClassId << invalidDeviceParams << DeviceManager::DeviceErrorInvalidParameter;
QTest::newRow("User, JustAdd, wrong param") << mockDeviceClassId << invalidDeviceParams << Device::DeviceErrorInvalidParameter;
}
@ -295,7 +295,7 @@ void TestDevices::addConfiguredDevice()
{
QFETCH(DeviceClassId, deviceClassId);
QFETCH(QVariantList, deviceParams);
QFETCH(DeviceManager::DeviceError, deviceError);
QFETCH(Device::DeviceError, deviceError);
QVariantMap params;
params.insert("deviceClassId", deviceClassId);
@ -306,7 +306,7 @@ void TestDevices::addConfiguredDevice()
verifyDeviceError(response, deviceError);
if (deviceError == DeviceManager::DeviceErrorNoError) {
if (deviceError == Device::DeviceErrorNoError) {
QUuid deviceId(response.toMap().value("params").toMap().value("deviceId").toString());
params.clear();
params.insert("deviceId", deviceId.toString());
@ -375,7 +375,7 @@ void TestDevices::discoverDevices_data()
{
QTest::addColumn<DeviceClassId>("deviceClassId");
QTest::addColumn<int>("resultCount");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::addColumn<QVariantList>("discoveryParams");
QVariantList discoveryParams;
@ -384,16 +384,16 @@ void TestDevices::discoverDevices_data()
resultCountParam.insert("value", 1);
discoveryParams.append(resultCountParam);
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();
QTest::newRow("valid deviceClassId") << mockDeviceClassId << 2 << Device::DeviceErrorNoError << QVariantList();
QTest::newRow("valid deviceClassId with params") << mockDeviceClassId << 1 << Device::DeviceErrorNoError << discoveryParams;
QTest::newRow("invalid deviceClassId") << DeviceClassId::createDeviceClassId() << 0 << Device::DeviceErrorDeviceClassNotFound << QVariantList();
}
void TestDevices::discoverDevices()
{
QFETCH(DeviceClassId, deviceClassId);
QFETCH(int, resultCount);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QFETCH(QVariantList, discoveryParams);
QVariantMap params;
@ -402,12 +402,12 @@ void TestDevices::discoverDevices()
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
verifyDeviceError(response, error);
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
QCOMPARE(response.toMap().value("params").toMap().value("deviceDescriptors").toList().count(), resultCount);
}
// If we found something, lets try to add it
if (DeviceManager::DeviceErrorNoError) {
if (Device::DeviceErrorNoError) {
DeviceDescriptorId descriptorId = DeviceDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString());
params.clear();
@ -429,17 +429,17 @@ void TestDevices::discoverDevices()
void TestDevices::addPushButtonDevices_data()
{
QTest::addColumn<DeviceClassId>("deviceClassId");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::addColumn<bool>("waitForButtonPressed");
QTest::newRow("Valid: Add PushButton device") << mockPushButtonDeviceClassId << DeviceManager::DeviceErrorNoError << true;
QTest::newRow("Invalid: Add PushButton device (press to early)") << mockPushButtonDeviceClassId << DeviceManager::DeviceErrorSetupFailed << false;
QTest::newRow("Valid: Add PushButton device") << mockPushButtonDeviceClassId << Device::DeviceErrorNoError << true;
QTest::newRow("Invalid: Add PushButton device (press to early)") << mockPushButtonDeviceClassId << Device::DeviceErrorSetupFailed << false;
}
void TestDevices::addPushButtonDevices()
{
QFETCH(DeviceClassId, deviceClassId);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QFETCH(bool, waitForButtonPressed);
// Discover device
@ -454,7 +454,7 @@ void TestDevices::addPushButtonDevices()
params.insert("discoveryParams", discoveryParams);
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
verifyDeviceError(response, DeviceManager::DeviceErrorNoError);
verifyDeviceError(response, Device::DeviceErrorNoError);
QCOMPARE(response.toMap().value("params").toMap().value("deviceDescriptors").toList().count(), 1);
@ -483,7 +483,7 @@ void TestDevices::addPushButtonDevices()
verifyDeviceError(response, error);
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
DeviceId deviceId(response.toMap().value("params").toMap().value("deviceId").toString());
params.clear();
params.insert("deviceId", deviceId.toString());
@ -495,17 +495,17 @@ void TestDevices::addPushButtonDevices()
void TestDevices::addDisplayPinDevices_data()
{
QTest::addColumn<DeviceClassId>("deviceClassId");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::addColumn<QString>("secret");
QTest::newRow("Valid: Add DisplayPin device") << mockDisplayPinDeviceClassId << DeviceManager::DeviceErrorNoError << "243681";
QTest::newRow("Invalid: Add DisplayPin device (wrong pin)") << mockDisplayPinDeviceClassId << DeviceManager::DeviceErrorSetupFailed << "243682";
QTest::newRow("Valid: Add DisplayPin device") << mockDisplayPinDeviceClassId << Device::DeviceErrorNoError << "243681";
QTest::newRow("Invalid: Add DisplayPin device (wrong pin)") << mockDisplayPinDeviceClassId << Device::DeviceErrorSetupFailed << "243682";
}
void TestDevices::addDisplayPinDevices()
{
QFETCH(DeviceClassId, deviceClassId);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QFETCH(QString, secret);
// Discover device
@ -520,7 +520,7 @@ void TestDevices::addDisplayPinDevices()
params.insert("discoveryParams", discoveryParams);
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
verifyDeviceError(response, DeviceManager::DeviceErrorNoError);
verifyDeviceError(response, Device::DeviceErrorNoError);
QCOMPARE(response.toMap().value("params").toMap().value("deviceDescriptors").toList().count(), 1);
// Pair device
@ -545,7 +545,7 @@ void TestDevices::addDisplayPinDevices()
verifyDeviceError(response, error);
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
DeviceId deviceId(response.toMap().value("params").toMap().value("deviceId").toString());
params.clear();
params.insert("deviceId", deviceId.toString());
@ -591,7 +591,7 @@ void TestDevices::parentChildDevices()
params.clear();
params.insert("deviceId", childDeviceId.toString());
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceIsChild);
verifyDeviceError(response, Device::DeviceErrorDeviceIsChild);
// check if the child device is still there
response = injectAndWait("Devices.GetConfiguredDevices");
@ -716,24 +716,24 @@ void TestDevices::getStateTypes()
void TestDevices::getStateType_data()
{
QTest::addColumn<StateTypeId>("stateTypeId");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::newRow("valid int state") << mockIntStateId << DeviceManager::DeviceErrorNoError;
QTest::newRow("valid bool state") << mockBoolStateId << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid stateTypeId") << StateTypeId::createStateTypeId() << DeviceManager::DeviceErrorStateTypeNotFound;
QTest::newRow("valid int state") << mockIntStateId << Device::DeviceErrorNoError;
QTest::newRow("valid bool state") << mockBoolStateId << Device::DeviceErrorNoError;
QTest::newRow("invalid stateTypeId") << StateTypeId::createStateTypeId() << Device::DeviceErrorStateTypeNotFound;
}
void TestDevices::getStateType()
{
QFETCH(StateTypeId, stateTypeId);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QVariantMap params;
params.insert("stateTypeId", stateTypeId);
QVariant response = injectAndWait("States.GetStateType", params);
verifyDeviceError(response, error);
if (error != DeviceManager::DeviceErrorNoError)
if (error != Device::DeviceErrorNoError)
return;
QVariantMap stateType = response.toMap().value("params").toMap().value("stateType").toMap();
@ -748,18 +748,18 @@ void TestDevices::getStateValue_data()
{
QTest::addColumn<DeviceId>("deviceId");
QTest::addColumn<StateTypeId>("stateTypeId");
QTest::addColumn<DeviceManager::DeviceError>("statusCode");
QTest::addColumn<Device::DeviceError>("statusCode");
QTest::newRow("valid deviceId") << m_mockDeviceId << mockIntStateId << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid deviceId") << DeviceId("094f8024-5caa-48c1-ab6a-de486a92088f") << mockIntStateId << DeviceManager::DeviceErrorDeviceNotFound;
QTest::newRow("invalid statetypeId") << m_mockDeviceId << StateTypeId("120514f1-343e-4621-9bff-dac616169df9") << DeviceManager::DeviceErrorStateTypeNotFound;
QTest::newRow("valid deviceId") << m_mockDeviceId << mockIntStateId << Device::DeviceErrorNoError;
QTest::newRow("invalid deviceId") << DeviceId("094f8024-5caa-48c1-ab6a-de486a92088f") << mockIntStateId << Device::DeviceErrorDeviceNotFound;
QTest::newRow("invalid statetypeId") << m_mockDeviceId << StateTypeId("120514f1-343e-4621-9bff-dac616169df9") << Device::DeviceErrorStateTypeNotFound;
}
void TestDevices::getStateValue()
{
QFETCH(DeviceId, deviceId);
QFETCH(StateTypeId, stateTypeId);
QFETCH(DeviceManager::DeviceError, statusCode);
QFETCH(Device::DeviceError, statusCode);
QVariantMap params;
params.insert("deviceId", deviceId);
@ -767,7 +767,7 @@ void TestDevices::getStateValue()
QVariant response = injectAndWait("Devices.GetStateValue", params);
QCOMPARE(response.toMap().value("params").toMap().value("deviceError").toString(), JsonTypes::deviceErrorToString(statusCode));
if (statusCode == DeviceManager::DeviceErrorNoError) {
if (statusCode == Device::DeviceErrorNoError) {
QVariant value = response.toMap().value("params").toMap().value("value");
QCOMPARE(value.toInt(), 10); // Mock device has value 10 by default...
}
@ -776,23 +776,23 @@ void TestDevices::getStateValue()
void TestDevices::getStateValues_data()
{
QTest::addColumn<DeviceId>("deviceId");
QTest::addColumn<DeviceManager::DeviceError>("statusCode");
QTest::addColumn<Device::DeviceError>("statusCode");
QTest::newRow("valid deviceId") << m_mockDeviceId << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid deviceId") << DeviceId("094f8024-5caa-48c1-ab6a-de486a92088f") << DeviceManager::DeviceErrorDeviceNotFound;
QTest::newRow("valid deviceId") << m_mockDeviceId << Device::DeviceErrorNoError;
QTest::newRow("invalid deviceId") << DeviceId("094f8024-5caa-48c1-ab6a-de486a92088f") << Device::DeviceErrorDeviceNotFound;
}
void TestDevices::getStateValues()
{
QFETCH(DeviceId, deviceId);
QFETCH(DeviceManager::DeviceError, statusCode);
QFETCH(Device::DeviceError, statusCode);
QVariantMap params;
params.insert("deviceId", deviceId);
QVariant response = injectAndWait("Devices.GetStateValues", params);
QCOMPARE(response.toMap().value("params").toMap().value("deviceError").toString(), JsonTypes::deviceErrorToString(statusCode));
if (statusCode == DeviceManager::DeviceErrorNoError) {
if (statusCode == Device::DeviceErrorNoError) {
QVariantList values = response.toMap().value("params").toMap().value("values").toList();
QCOMPARE(values.count(), 6); // Mock device has 6 states...
}
@ -980,19 +980,19 @@ void TestDevices::reconfigureDevices_data()
QTest::addColumn<bool>("broken");
QTest::addColumn<QVariantList>("newDeviceParams");
QTest::addColumn<DeviceManager::DeviceError>("deviceError");
QTest::addColumn<Device::DeviceError>("deviceError");
QTest::newRow("valid - change async param") << false << asyncChangeDeviceParams << DeviceManager::DeviceErrorParameterNotWritable;
QTest::newRow("valid - change httpport param") << false << httpportChangeDeviceParams << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid - change httpport and async param") << false << asyncAndPortChangeDeviceParams << DeviceManager::DeviceErrorParameterNotWritable;
QTest::newRow("invalid - change all params (except broken)") << false << changeAllWritableDeviceParams << DeviceManager::DeviceErrorParameterNotWritable;
QTest::newRow("valid - change async param") << false << asyncChangeDeviceParams << Device::DeviceErrorParameterNotWritable;
QTest::newRow("valid - change httpport param") << false << httpportChangeDeviceParams << Device::DeviceErrorNoError;
QTest::newRow("invalid - change httpport and async param") << false << asyncAndPortChangeDeviceParams << Device::DeviceErrorParameterNotWritable;
QTest::newRow("invalid - change all params (except broken)") << false << changeAllWritableDeviceParams << Device::DeviceErrorParameterNotWritable;
}
void TestDevices::reconfigureDevices()
{
QFETCH(bool, broken);
QFETCH(QVariantList, newDeviceParams);
QFETCH(DeviceManager::DeviceError, deviceError);
QFETCH(Device::DeviceError, deviceError);
// add device
QVariantMap params;
@ -1029,7 +1029,7 @@ void TestDevices::reconfigureDevices()
verifyDeviceError(response, deviceError);
// if the edit should have been successful
if (deviceError == DeviceManager::DeviceErrorNoError) {
if (deviceError == Device::DeviceErrorNoError) {
response = injectAndWait("Devices.GetConfiguredDevices", QVariantMap());
bool found = false;
@ -1118,7 +1118,7 @@ void TestDevices::reconfigureByDiscovery_data()
{
QTest::addColumn<DeviceClassId>("deviceClassId");
QTest::addColumn<int>("resultCount");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::addColumn<QVariantList>("discoveryParams");
QVariantList discoveryParams;
@ -1127,14 +1127,14 @@ void TestDevices::reconfigureByDiscovery_data()
resultCountParam.insert("value", 2);
discoveryParams.append(resultCountParam);
QTest::newRow("discover 2 devices with params") << mockDeviceClassId << 2 << DeviceManager::DeviceErrorNoError << discoveryParams;
QTest::newRow("discover 2 devices with params") << mockDeviceClassId << 2 << Device::DeviceErrorNoError << discoveryParams;
}
void TestDevices::reconfigureByDiscovery()
{
QFETCH(DeviceClassId, deviceClassId);
QFETCH(int, resultCount);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QFETCH(QVariantList, discoveryParams);
QVariantMap params;
@ -1143,7 +1143,7 @@ void TestDevices::reconfigureByDiscovery()
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
verifyDeviceError(response);
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
QCOMPARE(response.toMap().value("params").toMap().value("deviceDescriptors").toList().count(), resultCount);
}
@ -1182,7 +1182,7 @@ void TestDevices::reconfigureByDiscovery()
response = injectAndWait("Devices.GetDiscoveredDevices", params);
verifyDeviceError(response, error);
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
QCOMPARE(response.toMap().value("params").toMap().value("deviceDescriptors").toList().count(), resultCount);
}
@ -1320,7 +1320,7 @@ void TestDevices::reconfigureByDiscoveryAndPair()
deviceDescriptors = response.toMap().value("params").toMap().value("deviceDescriptors").toList();
qCDebug(dcTests()) << "Discovery result:" << qUtf8Printable(QJsonDocument::fromVariant(deviceDescriptors).toJson(QJsonDocument::Indented));
verifyDeviceError(response, DeviceManager::DeviceErrorNoError);
verifyDeviceError(response, Device::DeviceErrorNoError);
QCOMPARE(deviceDescriptors.count(), 1);
descriptor = deviceDescriptors.first();
@ -1390,21 +1390,21 @@ void TestDevices::reconfigureAutodevice()
void TestDevices::removeDevice_data()
{
QTest::addColumn<DeviceId>("deviceId");
QTest::addColumn<DeviceManager::DeviceError>("deviceError");
QTest::addColumn<Device::DeviceError>("deviceError");
QTest::newRow("Existing Device") << m_mockDeviceId << DeviceManager::DeviceErrorNoError;
QTest::newRow("Not existing Device") << DeviceId::createDeviceId() << DeviceManager::DeviceErrorDeviceNotFound;
// QTest::newRow("Auto device") << m_mockDeviceAutoId << DeviceManager::DeviceErrorCreationMethodNotSupported;
QTest::newRow("Existing Device") << m_mockDeviceId << Device::DeviceErrorNoError;
QTest::newRow("Not existing Device") << DeviceId::createDeviceId() << Device::DeviceErrorDeviceNotFound;
// QTest::newRow("Auto device") << m_mockDeviceAutoId << Device::DeviceErrorCreationMethodNotSupported;
}
void TestDevices::removeDevice()
{
QFETCH(DeviceId, deviceId);
QFETCH(DeviceManager::DeviceError, deviceError);
QFETCH(Device::DeviceError, deviceError);
NymeaSettings settings(NymeaSettings::SettingsRoleDevices);
settings.beginGroup("DeviceConfig");
if (deviceError == DeviceManager::DeviceErrorNoError) {
if (deviceError == Device::DeviceErrorNoError) {
settings.beginGroup(m_mockDeviceId.toString());
// Make sure we have some config values for this device
QVERIFY(settings.allKeys().count() > 0);
@ -1417,7 +1417,7 @@ void TestDevices::removeDevice()
verifyDeviceError(response, deviceError);
if (DeviceManager::DeviceErrorNoError) {
if (Device::DeviceErrorNoError) {
// Make sure the device is gone from settings too
QCOMPARE(settings.allKeys().count(), 0);
}

View File

@ -113,16 +113,16 @@ void TestEvents::params()
void TestEvents::getEventType_data()
{
QTest::addColumn<EventTypeId>("eventTypeId");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::newRow("valid eventypeid") << mockEvent1Id << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid eventypeid") << EventTypeId::createEventTypeId() << DeviceManager::DeviceErrorEventTypeNotFound;
QTest::newRow("valid eventypeid") << mockEvent1Id << Device::DeviceErrorNoError;
QTest::newRow("invalid eventypeid") << EventTypeId::createEventTypeId() << Device::DeviceErrorEventTypeNotFound;
}
void TestEvents::getEventType()
{
QFETCH(EventTypeId, eventTypeId);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QVariantMap params;
params.insert("eventTypeId", eventTypeId.toString());
@ -130,7 +130,7 @@ void TestEvents::getEventType()
verifyDeviceError(response, error);
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
QVERIFY2(EventTypeId(response.toMap().value("params").toMap().value("eventType").toMap().value("id").toString()) == eventTypeId, "Didn't get a reply for the same actionTypeId as requested.");
}
}

View File

@ -348,7 +348,7 @@ void TestLogging::actionLog()
params.insert("actionTypeId", mockActionIdFailing);
params.insert("deviceId", m_mockDeviceId);
response = injectAndWait("Actions.ExecuteAction", params);
verifyDeviceError(response, DeviceManager::DeviceErrorSetupFailed);
verifyDeviceError(response, Device::DeviceErrorSetupFailed);
clientSpy.wait(200);
@ -367,7 +367,7 @@ void TestLogging::actionLog()
QCOMPARE(logEntry.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger));
QCOMPARE(logEntry.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceActions));
QCOMPARE(logEntry.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelAlert));
QCOMPARE(logEntry.value("errorCode").toString(), JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorSetupFailed));
QCOMPARE(logEntry.value("errorCode").toString(), JsonTypes::deviceErrorToString(Device::DeviceErrorSetupFailed));
break;
}
}
@ -474,7 +474,7 @@ void TestLogging::testDoubleValues()
params.insert("discoveryParams", discoveryParams);
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
verifyDeviceError(response, DeviceManager::DeviceErrorNoError);
verifyDeviceError(response, Device::DeviceErrorNoError);
// Pair device
DeviceDescriptorId descriptorId = DeviceDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString());

View File

@ -105,7 +105,7 @@ void TestRestDeviceClasses::getSupportedDevices()
url.setQuery(query);
response = getAndWait(QNetworkRequest(url), 400);
QCOMPARE(JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorVendorNotFound), response.toMap().value("error").toString());
QCOMPARE(JsonTypes::deviceErrorToString(Device::DeviceErrorVendorNotFound), response.toMap().value("error").toString());
}
void TestRestDeviceClasses::invalidMethod()
@ -136,17 +136,17 @@ void TestRestDeviceClasses::getActionTypes_data()
QTest::addColumn<QString>("deviceClassId");
QTest::addColumn<QString>("actionTypeId");
QTest::addColumn<int>("expectedStatusCode");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::newRow("all ActionTypes") << mockDeviceClassId.toString() << QString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("ActionType async") << mockDeviceClassId.toString() << mockActionIdAsync.toString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("ActionType no params") << mockDeviceClassId.toString() << mockActionIdNoParams.toString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("ActionType failing") << mockDeviceClassId.toString() << mockActionIdFailing.toString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("ActionType with params") << mockDeviceClassId.toString() << mockActionIdWithParams.toString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId().toString() << mockActionIdNoParams.toString() << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
QTest::newRow("invalid ActionTypeId") << mockDeviceClassId.toString() << ActionTypeId::createActionTypeId().toString() << 404 << DeviceManager::DeviceErrorActionTypeNotFound;
QTest::newRow("invalid ActionTypeId format") << mockDeviceClassId.toString() << "uuid" << 400 << DeviceManager::DeviceErrorActionTypeNotFound;
QTest::newRow("invalid DeviceClassId format") << "uuid" << "uuid" << 400 << DeviceManager::DeviceErrorDeviceClassNotFound;
QTest::newRow("all ActionTypes") << mockDeviceClassId.toString() << QString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("ActionType async") << mockDeviceClassId.toString() << mockActionIdAsync.toString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("ActionType no params") << mockDeviceClassId.toString() << mockActionIdNoParams.toString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("ActionType failing") << mockDeviceClassId.toString() << mockActionIdFailing.toString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("ActionType with params") << mockDeviceClassId.toString() << mockActionIdWithParams.toString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId().toString() << mockActionIdNoParams.toString() << 404 << Device::DeviceErrorDeviceClassNotFound;
QTest::newRow("invalid ActionTypeId") << mockDeviceClassId.toString() << ActionTypeId::createActionTypeId().toString() << 404 << Device::DeviceErrorActionTypeNotFound;
QTest::newRow("invalid ActionTypeId format") << mockDeviceClassId.toString() << "uuid" << 400 << Device::DeviceErrorActionTypeNotFound;
QTest::newRow("invalid DeviceClassId format") << "uuid" << "uuid" << 400 << Device::DeviceErrorDeviceClassNotFound;
}
@ -155,7 +155,7 @@ void TestRestDeviceClasses::getActionTypes()
QFETCH(QString, deviceClassId);
QFETCH(QString, actionTypeId);
QFETCH(int, expectedStatusCode);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QNetworkRequest request;
if (!actionTypeId.isEmpty()) {
@ -177,15 +177,15 @@ void TestRestDeviceClasses::getStateTypes_data()
QTest::addColumn<QString>("deviceClassId");
QTest::addColumn<QString>("stateTypeId");
QTest::addColumn<int>("expectedStatusCode");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::newRow("all ActionTypes") << mockDeviceClassId.toString() << QString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("StateType bool") << mockDeviceClassId.toString() << mockBoolStateId.toString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("StateType int") << mockDeviceClassId.toString() << mockIntStateId.toString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId().toString() << mockBoolStateId.toString() << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
QTest::newRow("invalid StateTypeId") << mockDeviceClassId.toString() << StateTypeId::createStateTypeId().toString() << 404 << DeviceManager::DeviceErrorStateTypeNotFound;
QTest::newRow("invalid StateTypeId format") << mockDeviceClassId.toString() << "uuid" << 400 << DeviceManager::DeviceErrorStateTypeNotFound;
QTest::newRow("invalid DeviceClassId format") << "uuid" << "uuid" << 400 << DeviceManager::DeviceErrorDeviceClassNotFound;
QTest::newRow("all ActionTypes") << mockDeviceClassId.toString() << QString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("StateType bool") << mockDeviceClassId.toString() << mockBoolStateId.toString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("StateType int") << mockDeviceClassId.toString() << mockIntStateId.toString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId().toString() << mockBoolStateId.toString() << 404 << Device::DeviceErrorDeviceClassNotFound;
QTest::newRow("invalid StateTypeId") << mockDeviceClassId.toString() << StateTypeId::createStateTypeId().toString() << 404 << Device::DeviceErrorStateTypeNotFound;
QTest::newRow("invalid StateTypeId format") << mockDeviceClassId.toString() << "uuid" << 400 << Device::DeviceErrorStateTypeNotFound;
QTest::newRow("invalid DeviceClassId format") << "uuid" << "uuid" << 400 << Device::DeviceErrorDeviceClassNotFound;
}
void TestRestDeviceClasses::getStateTypes()
@ -193,7 +193,7 @@ void TestRestDeviceClasses::getStateTypes()
QFETCH(QString, deviceClassId);
QFETCH(QString, stateTypeId);
QFETCH(int, expectedStatusCode);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QNetworkRequest request;
if (!stateTypeId.isEmpty()) {
@ -215,15 +215,15 @@ void TestRestDeviceClasses::getEventTypes_data()
QTest::addColumn<QString>("deviceClassId");
QTest::addColumn<QString>("eventTypeId");
QTest::addColumn<int>("expectedStatusCode");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::newRow("all ActionTypes") << mockDeviceClassId.toString() << QString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("EventType 1") << mockDeviceClassId.toString() << mockEvent1Id.toString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("EventType 2") << mockDeviceClassId.toString() << mockEvent2Id.toString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId().toString() << mockEvent2Id.toString() << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
QTest::newRow("invalid EventTypeId") << mockDeviceClassId.toString() << EventTypeId::createEventTypeId().toString() << 404 << DeviceManager::DeviceErrorEventTypeNotFound;
QTest::newRow("invalid EventTypeId format") << mockDeviceClassId.toString() << "uuid" << 400 << DeviceManager::DeviceErrorEventTypeNotFound;
QTest::newRow("invalid DeviceClassId format") << "uuid" << "uuid" << 400 << DeviceManager::DeviceErrorDeviceClassNotFound;
QTest::newRow("all ActionTypes") << mockDeviceClassId.toString() << QString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("EventType 1") << mockDeviceClassId.toString() << mockEvent1Id.toString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("EventType 2") << mockDeviceClassId.toString() << mockEvent2Id.toString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("invalid DeviceClassId") << DeviceClassId::createDeviceClassId().toString() << mockEvent2Id.toString() << 404 << Device::DeviceErrorDeviceClassNotFound;
QTest::newRow("invalid EventTypeId") << mockDeviceClassId.toString() << EventTypeId::createEventTypeId().toString() << 404 << Device::DeviceErrorEventTypeNotFound;
QTest::newRow("invalid EventTypeId format") << mockDeviceClassId.toString() << "uuid" << 400 << Device::DeviceErrorEventTypeNotFound;
QTest::newRow("invalid DeviceClassId format") << "uuid" << "uuid" << 400 << Device::DeviceErrorDeviceClassNotFound;
}
void TestRestDeviceClasses::getEventTypes()
@ -231,7 +231,7 @@ void TestRestDeviceClasses::getEventTypes()
QFETCH(QString, deviceClassId);
QFETCH(QString, eventTypeId);
QFETCH(int, expectedStatusCode);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QNetworkRequest request;
if (!eventTypeId.isNull()) {
@ -254,7 +254,7 @@ void TestRestDeviceClasses::discoverDevices_data()
QTest::addColumn<int>("resultCount");
QTest::addColumn<QVariantList>("discoveryParams");
QTest::addColumn<int>("expectedStatusCode");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QVariantMap resultCountParam;
resultCountParam.insert("paramTypeId", resultCountParamTypeId);
@ -270,10 +270,10 @@ void TestRestDeviceClasses::discoverDevices_data()
QVariantList invalidDiscoveryParams;
invalidDiscoveryParams.append(invalidResultCountParam);
QTest::newRow("valid deviceClassId without params") << mockDeviceClassId << 2 << QVariantList() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("valid deviceClassId with params") << mockDeviceClassId << 1 << discoveryParams << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid deviceClassId") << DeviceClassId::createDeviceClassId() << 0 << QVariantList() << 404 << DeviceManager::DeviceErrorDeviceClassNotFound;
QTest::newRow("valid deviceClassId with invalid params") << mockDeviceClassId << 10 << invalidDiscoveryParams << 500 << DeviceManager::DeviceErrorInvalidParameter;
QTest::newRow("valid deviceClassId without params") << mockDeviceClassId << 2 << QVariantList() << 200 << Device::DeviceErrorNoError;
QTest::newRow("valid deviceClassId with params") << mockDeviceClassId << 1 << discoveryParams << 200 << Device::DeviceErrorNoError;
QTest::newRow("invalid deviceClassId") << DeviceClassId::createDeviceClassId() << 0 << QVariantList() << 404 << Device::DeviceErrorDeviceClassNotFound;
QTest::newRow("valid deviceClassId with invalid params") << mockDeviceClassId << 10 << invalidDiscoveryParams << 500 << Device::DeviceErrorInvalidParameter;
}
void TestRestDeviceClasses::discoverDevices()
@ -282,7 +282,7 @@ void TestRestDeviceClasses::discoverDevices()
QFETCH(int, resultCount);
QFETCH(QVariantList, discoveryParams);
QFETCH(int, expectedStatusCode);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QVariantMap params;
params.insert("deviceClassId", deviceClassId);

View File

@ -371,7 +371,7 @@ void TestRestDevices::parentChildDevices()
QNetworkRequest deleteRequest(QUrl(QString("https://localhost:3333/api/v1/devices/%1").arg(childDeviceId.toString())));
response = deleteAndWait(deleteRequest, 400);
//QVERIFY2(!response.isNull(), "Could not delete device");
QCOMPARE(JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorDeviceIsChild), response.toMap().value("error").toString());
QCOMPARE(JsonTypes::deviceErrorToString(Device::DeviceErrorDeviceIsChild), response.toMap().value("error").toString());
// check if the child device is still there
response = getAndWait(QNetworkRequest(QUrl("https://localhost:3333/api/v1/devices")));
@ -415,7 +415,7 @@ void TestRestDevices::executeAction_data()
QTest::addColumn<ActionTypeId>("actionTypeId");
QTest::addColumn<QVariantList>("actionParams");
QTest::addColumn<int>("expectedStatusCode");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QVariantList params;
QVariantMap param1;
@ -427,13 +427,13 @@ void TestRestDevices::executeAction_data()
param2.insert("value", true);
params.append(param2);
QTest::newRow("valid action") << m_mockDeviceId << mockActionIdWithParams << params << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid deviceId") << DeviceId::createDeviceId() << mockActionIdWithParams << params << 404 << DeviceManager::DeviceErrorDeviceNotFound;
QTest::newRow("invalid actionTypeId") << m_mockDeviceId << ActionTypeId::createActionTypeId() << params << 404 << DeviceManager::DeviceErrorActionTypeNotFound;
QTest::newRow("missing params") << m_mockDeviceId << mockActionIdWithParams << QVariantList() << 500 << DeviceManager::DeviceErrorMissingParameter;
QTest::newRow("async action") << m_mockDeviceId << mockActionIdAsync << QVariantList() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("broken action") << m_mockDeviceId << mockActionIdFailing << QVariantList() << 500 << DeviceManager::DeviceErrorSetupFailed;
QTest::newRow("async broken action") << m_mockDeviceId << mockActionIdAsyncFailing << QVariantList() << 500 << DeviceManager::DeviceErrorSetupFailed;
QTest::newRow("valid action") << m_mockDeviceId << mockActionIdWithParams << params << 200 << Device::DeviceErrorNoError;
QTest::newRow("invalid deviceId") << DeviceId::createDeviceId() << mockActionIdWithParams << params << 404 << Device::DeviceErrorDeviceNotFound;
QTest::newRow("invalid actionTypeId") << m_mockDeviceId << ActionTypeId::createActionTypeId() << params << 404 << Device::DeviceErrorActionTypeNotFound;
QTest::newRow("missing params") << m_mockDeviceId << mockActionIdWithParams << QVariantList() << 500 << Device::DeviceErrorMissingParameter;
QTest::newRow("async action") << m_mockDeviceId << mockActionIdAsync << QVariantList() << 200 << Device::DeviceErrorNoError;
QTest::newRow("broken action") << m_mockDeviceId << mockActionIdFailing << QVariantList() << 500 << Device::DeviceErrorSetupFailed;
QTest::newRow("async broken action") << m_mockDeviceId << mockActionIdAsyncFailing << QVariantList() << 500 << Device::DeviceErrorSetupFailed;
}
void TestRestDevices::executeAction()
@ -442,7 +442,7 @@ void TestRestDevices::executeAction()
QFETCH(ActionTypeId, actionTypeId);
QFETCH(QVariantList, actionParams);
QFETCH(int, expectedStatusCode);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
// execute action
QVariantMap params;
@ -465,7 +465,7 @@ void TestRestDevices::executeAction()
reply->deleteLater();
QByteArray data = reply->readAll();
if (error == DeviceManager::DeviceErrorNoError) {
if (error == Device::DeviceErrorNoError) {
QVERIFY2(actionTypeId == ActionTypeId(data), QString("ActionTypeId mismatch. Got %1, Expected: %2")
.arg(ActionTypeId(data).toString()).arg(actionTypeId.toString()).toLatin1().data());
} else {
@ -499,14 +499,14 @@ void TestRestDevices::getStateValue_data()
QTest::addColumn<QString>("deviceId");
QTest::addColumn<QString>("stateTypeId");
QTest::addColumn<int>("expectedStatusCode");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::newRow("existing state") << device->id().toString() << mockIntStateId.toString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("all states") << device->id().toString() << QString() << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("invalid device") << DeviceId::createDeviceId().toString() << mockIntStateId.toString() << 404 << DeviceManager::DeviceErrorDeviceNotFound;
QTest::newRow("invalid device id format") << "uuid" << StateTypeId::createStateTypeId().toString() << 400 << DeviceManager::DeviceErrorDeviceNotFound;
QTest::newRow("invalid statetype") << device->id().toString() << StateTypeId::createStateTypeId().toString() << 404 << DeviceManager::DeviceErrorStateTypeNotFound;
QTest::newRow("invalid statetype format") << device->id().toString() << "uuid" << 400 << DeviceManager::DeviceErrorStateTypeNotFound;
QTest::newRow("existing state") << device->id().toString() << mockIntStateId.toString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("all states") << device->id().toString() << QString() << 200 << Device::DeviceErrorNoError;
QTest::newRow("invalid device") << DeviceId::createDeviceId().toString() << mockIntStateId.toString() << 404 << Device::DeviceErrorDeviceNotFound;
QTest::newRow("invalid device id format") << "uuid" << StateTypeId::createStateTypeId().toString() << 400 << Device::DeviceErrorDeviceNotFound;
QTest::newRow("invalid statetype") << device->id().toString() << StateTypeId::createStateTypeId().toString() << 404 << Device::DeviceErrorStateTypeNotFound;
QTest::newRow("invalid statetype format") << device->id().toString() << "uuid" << 400 << Device::DeviceErrorStateTypeNotFound;
}
void TestRestDevices::getStateValue()
@ -514,7 +514,7 @@ void TestRestDevices::getStateValue()
QFETCH(QString, deviceId);
QFETCH(QString, stateTypeId);
QFETCH(int, expectedStatusCode);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QNetworkRequest request;
request.setHeader(QNetworkRequest::ContentTypeHeader, "text/json");
@ -572,7 +572,7 @@ void TestRestDevices::editDevices()
deviceRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
response = postAndWait(deviceRequest, params);
QVERIFY2(response.toMap().value("error").toString() == JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorNoError), "Could not edit device name");
QVERIFY2(response.toMap().value("error").toString() == JsonTypes::deviceErrorToString(Device::DeviceErrorNoError), "Could not edit device name");
// check device name
response = getAndWait(deviceRequest);
@ -580,7 +580,7 @@ void TestRestDevices::editDevices()
// Remove the device
response = deleteAndWait(deviceRequest);
QVERIFY2(response.toMap().value("error").toString() == JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorNoError), "Could not remove device");
QVERIFY2(response.toMap().value("error").toString() == JsonTypes::deviceErrorToString(Device::DeviceErrorNoError), "Could not remove device");
}
void TestRestDevices::reconfigureDevices_data()
@ -614,12 +614,12 @@ void TestRestDevices::reconfigureDevices_data()
QTest::addColumn<bool>("broken");
QTest::addColumn<QVariantList>("newDeviceParams");
QTest::addColumn<int>("expectedStatusCode");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
QTest::newRow("invalid - change async param") << false << asyncChangeDeviceParams << 500 << DeviceManager::DeviceErrorParameterNotWritable;
QTest::newRow("valid - change httpport param") << false << httpportChangeDeviceParams << 200 << DeviceManager::DeviceErrorNoError;
QTest::newRow("valid - change httpport and async param") << false << asyncAndPortChangeDeviceParams << 500 << DeviceManager::DeviceErrorParameterNotWritable;
QTest::newRow("invalid - change all params (except broken)") << false << changeAllWritableDeviceParams << 500 << DeviceManager::DeviceErrorParameterNotWritable;
QTest::newRow("invalid - change async param") << false << asyncChangeDeviceParams << 500 << Device::DeviceErrorParameterNotWritable;
QTest::newRow("valid - change httpport param") << false << httpportChangeDeviceParams << 200 << Device::DeviceErrorNoError;
QTest::newRow("valid - change httpport and async param") << false << asyncAndPortChangeDeviceParams << 500 << Device::DeviceErrorParameterNotWritable;
QTest::newRow("invalid - change all params (except broken)") << false << changeAllWritableDeviceParams << 500 << Device::DeviceErrorParameterNotWritable;
}
void TestRestDevices::reconfigureDevices()
@ -627,7 +627,7 @@ void TestRestDevices::reconfigureDevices()
QFETCH(bool, broken);
QFETCH(QVariantList, newDeviceParams);
QFETCH(int, expectedStatusCode);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
// add device
QVariantMap params;

View File

@ -272,7 +272,7 @@ void TestRestLogging::actionLog()
params.insert("actionTypeId", mockActionIdFailing);
params.insert("deviceId", m_mockDeviceId);
response = injectAndWait("Actions.ExecuteAction", params);
verifyDeviceError(response, DeviceManager::DeviceErrorSetupFailed);
verifyDeviceError(response, Device::DeviceErrorSetupFailed);
clientSpy.wait(200);
notification = checkNotification(clientSpy, "Logging.LogEntryAdded");
@ -286,7 +286,7 @@ void TestRestLogging::actionLog()
QCOMPARE(logEntry.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger));
QCOMPARE(logEntry.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceActions));
QCOMPARE(logEntry.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelAlert));
QCOMPARE(logEntry.value("errorCode").toString(), JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorSetupFailed));
QCOMPARE(logEntry.value("errorCode").toString(), JsonTypes::deviceErrorToString(Device::DeviceErrorSetupFailed));
// get this logentry with filter
params.clear();

View File

@ -146,7 +146,7 @@ void TestRestPlugins::invalidPlugin()
QNetworkRequest request(QUrl("https://localhost:3333/api/v1/vendors/" + path));
QVariant response = getAndWait(request, expectedStatusCode);
QCOMPARE(JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorVendorNotFound), response.toMap().value("error").toString());
QCOMPARE(JsonTypes::deviceErrorToString(Device::DeviceErrorVendorNotFound), response.toMap().value("error").toString());
}
void TestRestPlugins::getPluginConfiguration()

View File

@ -139,7 +139,7 @@ void TestRestVendors::invalidVendor()
QNetworkRequest request(QUrl("https://localhost:3333/api/v1/vendors/" + path));
QVariant response = getAndWait(request, expectedStatusCode);
QCOMPARE(JsonTypes::deviceErrorToString(DeviceManager::DeviceErrorVendorNotFound), response.toMap().value("error").toString());
QCOMPARE(JsonTypes::deviceErrorToString(Device::DeviceErrorVendorNotFound), response.toMap().value("error").toString());
}
#include "testrestvendors.moc"

View File

@ -154,7 +154,7 @@ DeviceId TestRules::addDisplayPinDevice()
params.insert("discoveryParams", discoveryParams);
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
verifyDeviceError(response, DeviceManager::DeviceErrorNoError);
verifyDeviceError(response, Device::DeviceErrorNoError);
// Pair device
DeviceDescriptorId descriptorId = DeviceDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString());
@ -2362,13 +2362,13 @@ void TestRules::removePolicyUpdate()
params.clear(); response.clear();
params.insert("deviceId", childDeviceId);
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceIsChild);
verifyDeviceError(response, Device::DeviceErrorDeviceIsChild);
// Try to remove child device
params.clear(); response.clear();
params.insert("deviceId", parentDeviceId);
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceInRule);
verifyDeviceError(response, Device::DeviceErrorDeviceInRule);
// Remove policy
params.clear(); response.clear();
@ -2445,13 +2445,13 @@ void TestRules::removePolicyCascade()
params.clear(); response.clear();
params.insert("deviceId", childDeviceId);
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceIsChild);
verifyDeviceError(response, Device::DeviceErrorDeviceIsChild);
// Try to remove child device
params.clear(); response.clear();
params.insert("deviceId", parentDeviceId);
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceInRule);
verifyDeviceError(response, Device::DeviceErrorDeviceInRule);
// Remove policy
params.clear(); response.clear();
@ -2530,14 +2530,14 @@ void TestRules::removePolicyUpdateRendersUselessRule()
params.clear(); response.clear();
params.insert("deviceId", childDeviceId);
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceIsChild);
verifyDeviceError(response, Device::DeviceErrorDeviceIsChild);
// Try to remove child device
qCDebug(dcTests()) << "Removing device (expeciting failure - device in use)";
params.clear(); response.clear();
params.insert("deviceId", parentDeviceId);
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
verifyDeviceError(response, DeviceManager::DeviceErrorDeviceInRule);
verifyDeviceError(response, Device::DeviceErrorDeviceInRule);
// Remove policy
qCDebug(dcTests()) << "Removing device with update policy";

View File

@ -54,18 +54,18 @@ void TestStates::getStateValue_data()
QTest::addColumn<DeviceId>("deviceId");
QTest::addColumn<StateTypeId>("stateTypeId");
QTest::addColumn<DeviceManager::DeviceError>("error");
QTest::addColumn<Device::DeviceError>("error");
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::DeviceErrorStateTypeNotFound;
QTest::newRow("existing state") << device->id() << mockIntStateId << Device::DeviceErrorNoError;
QTest::newRow("invalid device") << DeviceId::createDeviceId() << mockIntStateId << Device::DeviceErrorDeviceNotFound;
QTest::newRow("invalid statetype") << device->id() << StateTypeId::createStateTypeId() << Device::DeviceErrorStateTypeNotFound;
}
void TestStates::getStateValue()
{
QFETCH(DeviceId, deviceId);
QFETCH(StateTypeId, stateTypeId);
QFETCH(DeviceManager::DeviceError, error);
QFETCH(Device::DeviceError, error);
QVariantMap params;
params.insert("deviceId", deviceId.toString());

View File

@ -23,7 +23,7 @@
#include "logging/logengine.h"
#include "logging/logvaluetool.h"
#include "usermanager.h"
#include "usermanager/usermanager.h"
using namespace nymeaserver;

View File

@ -139,7 +139,7 @@ protected:
verifyError(response, "ruleError", JsonTypes::ruleErrorToString(error));
}
inline void verifyDeviceError(const QVariant &response, DeviceManager::DeviceError error = DeviceManager::DeviceErrorNoError) {
inline void verifyDeviceError(const QVariant &response, Device::DeviceError error = Device::DeviceErrorNoError) {
verifyError(response, "deviceError", JsonTypes::deviceErrorToString(error));
}