fix plugin configuration and move to plugin json file
close #264 close #268
This commit is contained in:
parent
ffaa50c6c4
commit
9b9a5d6b23
1
guh.pri
1
guh.pri
@ -10,7 +10,6 @@ DEFINES += GUH_VERSION_STRING=\\\"$${GUH_VERSION_STRING}\\\" \
|
|||||||
REST_API_VERSION=\\\"$${REST_API_VERSION}\\\"
|
REST_API_VERSION=\\\"$${REST_API_VERSION}\\\"
|
||||||
|
|
||||||
QT+= network
|
QT+= network
|
||||||
CONFIG += c++11
|
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += -Werror -std=c++11
|
QMAKE_CXXFLAGS += -Werror -std=c++11
|
||||||
QMAKE_LFLAGS += -std=c++11
|
QMAKE_LFLAGS += -std=c++11
|
||||||
|
|||||||
@ -295,21 +295,18 @@ DevicePlugin *DeviceManager::plugin(const PluginId &id) const
|
|||||||
DeviceManager::DeviceError DeviceManager::setPluginConfig(const PluginId &pluginId, const ParamList &pluginConfig)
|
DeviceManager::DeviceError DeviceManager::setPluginConfig(const PluginId &pluginId, const ParamList &pluginConfig)
|
||||||
{
|
{
|
||||||
DevicePlugin *plugin = m_devicePlugins.value(pluginId);
|
DevicePlugin *plugin = m_devicePlugins.value(pluginId);
|
||||||
if (!plugin) {
|
if (!plugin)
|
||||||
return DeviceErrorPluginNotFound;
|
return DeviceErrorPluginNotFound;
|
||||||
}
|
|
||||||
|
|
||||||
ParamList params = pluginConfig;
|
ParamList params = pluginConfig;
|
||||||
|
|
||||||
DeviceError verify = verifyParams(plugin->configurationDescription(), params);
|
DeviceError verify = verifyParams(plugin->configurationDescription(), params);
|
||||||
if (verify != DeviceErrorNoError) {
|
if (verify != DeviceErrorNoError)
|
||||||
return verify;
|
return verify;
|
||||||
}
|
|
||||||
|
|
||||||
DeviceError result = plugin->setConfiguration(pluginConfig);
|
DeviceError result = plugin->setConfiguration(pluginConfig);
|
||||||
if (result != DeviceErrorNoError) {
|
if (result != DeviceErrorNoError)
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
GuhSettings settings(GuhSettings::SettingsRolePlugins);
|
GuhSettings settings(GuhSettings::SettingsRolePlugins);
|
||||||
settings.beginGroup("PluginConfig");
|
settings.beginGroup("PluginConfig");
|
||||||
@ -836,10 +833,12 @@ DeviceManager::DeviceError DeviceManager::verifyParam(const ParamType ¶mType
|
|||||||
qCWarning(dcDeviceManager) << "Value out of range for param" << param.name() << " Got:" << param.value() << " Max:" << paramType.maxValue();
|
qCWarning(dcDeviceManager) << "Value out of range for param" << param.name() << " Got:" << param.value() << " Max:" << paramType.maxValue();
|
||||||
return DeviceErrorInvalidParameter;
|
return DeviceErrorInvalidParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paramType.minValue().isValid() && param.value() < paramType.minValue()) {
|
if (paramType.minValue().isValid() && param.value() < paramType.minValue()) {
|
||||||
qCWarning(dcDeviceManager) << "Value out of range for param" << param.name() << " Got:" << param.value() << " Min:" << paramType.minValue();
|
qCWarning(dcDeviceManager) << "Value out of range for param" << param.name() << " Got:" << param.value() << " Min:" << paramType.minValue();
|
||||||
return DeviceErrorInvalidParameter;
|
return DeviceErrorInvalidParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!paramType.allowedValues().isEmpty() && !paramType.allowedValues().contains(param.value())) {
|
if (!paramType.allowedValues().isEmpty() && !paramType.allowedValues().contains(param.value())) {
|
||||||
QStringList allowedValues;
|
QStringList allowedValues;
|
||||||
foreach (const QVariant &value, paramType.allowedValues()) {
|
foreach (const QVariant &value, paramType.allowedValues()) {
|
||||||
@ -851,6 +850,7 @@ DeviceManager::DeviceError DeviceManager::verifyParam(const ParamType ¶mType
|
|||||||
}
|
}
|
||||||
return DeviceErrorNoError;
|
return DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
qCWarning(dcDeviceManager) << "Parameter name" << param.name() << "does not match with ParamType name" << paramType.name();
|
qCWarning(dcDeviceManager) << "Parameter name" << param.name() << "does not match with ParamType name" << paramType.name();
|
||||||
return DeviceErrorInvalidParameter;
|
return DeviceErrorInvalidParameter;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -137,6 +137,7 @@
|
|||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
|
|
||||||
#include "devicemanager.h"
|
#include "devicemanager.h"
|
||||||
|
#include "guhsettings.h"
|
||||||
#include "hardware/radio433/radio433.h"
|
#include "hardware/radio433/radio433.h"
|
||||||
#include "network/upnpdiscovery/upnpdiscovery.h"
|
#include "network/upnpdiscovery/upnpdiscovery.h"
|
||||||
|
|
||||||
@ -412,7 +413,7 @@ DeviceManager::DeviceError DevicePlugin::executeAction(Device *device, const Act
|
|||||||
/*! Returns the configuration description of this DevicePlugin as a list of \l{ParamType}{ParamTypes}. */
|
/*! Returns the configuration description of this DevicePlugin as a list of \l{ParamType}{ParamTypes}. */
|
||||||
QList<ParamType> DevicePlugin::configurationDescription() const
|
QList<ParamType> DevicePlugin::configurationDescription() const
|
||||||
{
|
{
|
||||||
return QList<ParamType>();
|
return m_configurationDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! This will be called when the DeviceManager initializes the plugin and set up the things behind the scenes.
|
/*! This will be called when the DeviceManager initializes the plugin and set up the things behind the scenes.
|
||||||
@ -420,6 +421,11 @@ QList<ParamType> DevicePlugin::configurationDescription() const
|
|||||||
void DevicePlugin::initPlugin(const QJsonObject &metaData, DeviceManager *deviceManager)
|
void DevicePlugin::initPlugin(const QJsonObject &metaData, DeviceManager *deviceManager)
|
||||||
{
|
{
|
||||||
m_metaData = metaData;
|
m_metaData = metaData;
|
||||||
|
|
||||||
|
// parse plugin configuration params
|
||||||
|
if (m_metaData.contains("paramTypes"))
|
||||||
|
m_configurationDescription = parseParamTypes(m_metaData.value("paramTypes").toArray());
|
||||||
|
|
||||||
m_deviceManager = deviceManager;
|
m_deviceManager = deviceManager;
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
@ -495,7 +501,7 @@ QVariant DevicePlugin::configValue(const QString ¶mName) const
|
|||||||
DeviceManager::DeviceError DevicePlugin::setConfiguration(const ParamList &configuration)
|
DeviceManager::DeviceError DevicePlugin::setConfiguration(const ParamList &configuration)
|
||||||
{
|
{
|
||||||
foreach (const Param ¶m, configuration) {
|
foreach (const Param ¶m, configuration) {
|
||||||
qCDebug(dcDeviceManager) << "* setting config" << param;
|
qCDebug(dcDeviceManager) << "* set plugin configuration" << param;
|
||||||
DeviceManager::DeviceError result = setConfigValue(param.name(), param.value());
|
DeviceManager::DeviceError result = setConfigValue(param.name(), param.value());
|
||||||
if (result != DeviceManager::DeviceErrorNoError) {
|
if (result != DeviceManager::DeviceErrorNoError) {
|
||||||
return result;
|
return result;
|
||||||
@ -504,46 +510,33 @@ DeviceManager::DeviceError DevicePlugin::setConfiguration(const ParamList &confi
|
|||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Will be called by the DeviceManager to set a plugin's \l{Param} with the given \a paramName and \a value. */
|
/*! Can be called in the DevicePlugin to set a plugin's \l{Param} with the given \a paramName and \a value. */
|
||||||
DeviceManager::DeviceError DevicePlugin::setConfigValue(const QString ¶mName, const QVariant &value)
|
DeviceManager::DeviceError DevicePlugin::setConfigValue(const QString ¶mName, const QVariant &value)
|
||||||
{
|
{
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
foreach (const ParamType ¶mType, configurationDescription()) {
|
foreach (const ParamType ¶mType, configurationDescription()) {
|
||||||
if (paramType.name() == paramName) {
|
if (paramType.name() == paramName) {
|
||||||
if (!value.canConvert(paramType.type())) {
|
|
||||||
qCWarning(dcDeviceManager) << QString("Wrong parameter type for param %1. Got %2. Expected %3.")
|
|
||||||
.arg(paramName).arg(value.toString()).arg(QVariant::typeToName(paramType.type()));
|
|
||||||
return DeviceManager::DeviceErrorInvalidParameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (paramType.maxValue().isValid() && value > paramType.maxValue()) {
|
|
||||||
qCWarning(dcDeviceManager) << QString("Value out of range for param %1. Got %2. Max: %3.")
|
|
||||||
.arg(paramName).arg(value.toString()).arg(paramType.maxValue().toString());
|
|
||||||
return DeviceManager::DeviceErrorInvalidParameter;
|
|
||||||
}
|
|
||||||
if (paramType.minValue().isValid() && value < paramType.minValue()) {
|
|
||||||
qCWarning(dcDeviceManager) << QString("Value out of range for param %1. Got: %2. Min: %3.")
|
|
||||||
.arg(paramName).arg(value.toString()).arg(paramType.minValue().toString());
|
|
||||||
return DeviceManager::DeviceErrorInvalidParameter;
|
|
||||||
}
|
|
||||||
found = true;
|
found = true;
|
||||||
|
DeviceManager::DeviceError result = deviceManager()->verifyParam(paramType, Param(paramName, value));
|
||||||
|
if (result != DeviceManager::DeviceErrorNoError)
|
||||||
|
return result;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
qCWarning(dcDeviceManager) << QString("Invalid parameter %1.").arg(paramName);
|
qCWarning(dcDeviceManager) << QString("Could not find plugin parameter with the name %1.").arg(paramName);
|
||||||
return DeviceManager::DeviceErrorInvalidParameter;
|
return DeviceManager::DeviceErrorInvalidParameter;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < m_config.count(); i++) {
|
|
||||||
if (m_config.at(i).name() == paramName) {
|
if (m_config.hasParam(paramName)) {
|
||||||
m_config[i].setValue(value);
|
m_config.setParamValue(paramName, value);
|
||||||
emit configValueChanged(paramName, value);
|
} else {
|
||||||
return DeviceManager::DeviceErrorNoError;
|
Param newParam(paramName, value);
|
||||||
}
|
m_config.append(newParam);
|
||||||
}
|
}
|
||||||
// Still here? need to create the param
|
|
||||||
Param newParam(paramName, value);
|
|
||||||
m_config.append(newParam);
|
|
||||||
emit configValueChanged(paramName, value);
|
emit configValueChanged(paramName, value);
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,7 +84,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
virtual QList<ParamType> configurationDescription() const;
|
QList<ParamType> configurationDescription() const;
|
||||||
DeviceManager::DeviceError setConfiguration(const ParamList &configuration);
|
DeviceManager::DeviceError setConfiguration(const ParamList &configuration);
|
||||||
ParamList configuration() const;
|
ParamList configuration() const;
|
||||||
QVariant configValue(const QString ¶mName) const;
|
QVariant configValue(const QString ¶mName) const;
|
||||||
@ -131,6 +131,7 @@ private:
|
|||||||
|
|
||||||
DeviceManager *m_deviceManager;
|
DeviceManager *m_deviceManager;
|
||||||
|
|
||||||
|
QList<ParamType> m_configurationDescription;
|
||||||
ParamList m_config;
|
ParamList m_config;
|
||||||
|
|
||||||
QJsonObject m_metaData;
|
QJsonObject m_metaData;
|
||||||
|
|||||||
@ -118,7 +118,7 @@ DevicePluginDateTime::DevicePluginDateTime() :
|
|||||||
m_timer = new QTimer(this);
|
m_timer = new QTimer(this);
|
||||||
m_timer->setInterval(1000);
|
m_timer->setInterval(1000);
|
||||||
|
|
||||||
m_timeZone = QTimeZone(configValue("timezone").toByteArray());
|
m_timeZone = QTimeZone(QTimeZone::systemTimeZoneId());
|
||||||
m_currentDateTime = QDateTime(QDate::currentDate(), QTime::currentTime(), m_timeZone);
|
m_currentDateTime = QDateTime(QDate::currentDate(), QTime::currentTime(), m_timeZone);
|
||||||
|
|
||||||
connect(m_timer, &QTimer::timeout, this, &DevicePluginDateTime::onSecondChanged);
|
connect(m_timer, &QTimer::timeout, this, &DevicePluginDateTime::onSecondChanged);
|
||||||
@ -130,20 +130,20 @@ DeviceManager::HardwareResources DevicePluginDateTime::requiredHardware() const
|
|||||||
return DeviceManager::HardwareResourceNetworkManager;
|
return DeviceManager::HardwareResourceNetworkManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ParamType> DevicePluginDateTime::configurationDescription() const
|
//QList<ParamType> DevicePluginDateTime::configurationDescription() const
|
||||||
{
|
//{
|
||||||
QList<ParamType> params;
|
// QList<ParamType> params;
|
||||||
ParamType timezoneParamType("timezone", QVariant::String, "Europe/Vienna");
|
// ParamType timezoneParamType("timezone", QVariant::String, "Europe/Vienna");
|
||||||
|
|
||||||
QList<QVariant> allowedValues;
|
// QList<QVariant> allowedValues;
|
||||||
foreach (QByteArray timeZone, QTimeZone::availableTimeZoneIds()) {
|
// foreach (QByteArray timeZone, QTimeZone::availableTimeZoneIds()) {
|
||||||
allowedValues.append(timeZone);
|
// allowedValues.append(timeZone);
|
||||||
}
|
// }
|
||||||
timezoneParamType.setAllowedValues(allowedValues);
|
// timezoneParamType.setAllowedValues(allowedValues);
|
||||||
|
|
||||||
params.append(timezoneParamType);
|
// params.append(timezoneParamType);
|
||||||
return params;
|
// return params;
|
||||||
}
|
//}
|
||||||
|
|
||||||
DeviceManager::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -41,7 +41,6 @@ public:
|
|||||||
explicit DevicePluginDateTime();
|
explicit DevicePluginDateTime();
|
||||||
|
|
||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
QList<ParamType> configurationDescription() const override;
|
|
||||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||||
void postSetupDevice(Device *device) override;
|
void postSetupDevice(Device *device) override;
|
||||||
void deviceRemoved(Device *device) override;
|
void deviceRemoved(Device *device) override;
|
||||||
|
|||||||
@ -87,12 +87,6 @@ DeviceManager::HardwareResources DevicePluginEQ3::requiredHardware() const
|
|||||||
return DeviceManager::HardwareResourceTimer;
|
return DeviceManager::HardwareResourceTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ParamType> DevicePluginEQ3::configurationDescription() const
|
|
||||||
{
|
|
||||||
QList<ParamType> params;
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginEQ3::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
DeviceManager::DeviceError DevicePluginEQ3::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||||
{
|
{
|
||||||
Q_UNUSED(params)
|
Q_UNUSED(params)
|
||||||
|
|||||||
@ -39,8 +39,6 @@ public:
|
|||||||
explicit DevicePluginEQ3();
|
explicit DevicePluginEQ3();
|
||||||
|
|
||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
|
|
||||||
QList<ParamType> configurationDescription() const override;
|
|
||||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||||
|
|
||||||
void startMonitoringAutoDevices() override;
|
void startMonitoringAutoDevices() override;
|
||||||
|
|||||||
@ -189,19 +189,6 @@ DeviceManager::DeviceError DevicePluginMock::displayPin(const PairingTransaction
|
|||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ParamType> DevicePluginMock::configurationDescription() const
|
|
||||||
{
|
|
||||||
QList<ParamType> params;
|
|
||||||
ParamType mockParam1("configParamInt", QVariant::Int, 42);
|
|
||||||
mockParam1.setLimits(1, 50);
|
|
||||||
params.append(mockParam1);
|
|
||||||
|
|
||||||
ParamType mockParam2("configParamBool", QVariant::Bool, true);
|
|
||||||
params.append(mockParam2);
|
|
||||||
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginMock::executeAction(Device *device, const Action &action)
|
DeviceManager::DeviceError DevicePluginMock::executeAction(Device *device, const Action &action)
|
||||||
{
|
{
|
||||||
if (device->deviceClassId() == mockDeviceClassId || device->deviceClassId() == mockDeviceAutoDeviceClassId) {
|
if (device->deviceClassId() == mockDeviceClassId || device->deviceClassId() == mockDeviceAutoDeviceClassId) {
|
||||||
|
|||||||
@ -51,8 +51,6 @@ public:
|
|||||||
DeviceManager::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList ¶ms, const QString &secret) override;
|
DeviceManager::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList ¶ms, const QString &secret) override;
|
||||||
DeviceManager::DeviceError displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor) override;
|
DeviceManager::DeviceError displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor) override;
|
||||||
|
|
||||||
QList<ParamType> configurationDescription() const override;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,20 @@
|
|||||||
"name": "Mock Devices",
|
"name": "Mock Devices",
|
||||||
"idName": "MockDevice",
|
"idName": "MockDevice",
|
||||||
"id": "727a4a9a-c187-446f-aadf-f1b2220607d1",
|
"id": "727a4a9a-c187-446f-aadf-f1b2220607d1",
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"name": "configParamInt",
|
||||||
|
"type": "int",
|
||||||
|
"defaultValue": 42,
|
||||||
|
"minValue": 1,
|
||||||
|
"maxValue": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "configParamBool",
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": true
|
||||||
|
}
|
||||||
|
],
|
||||||
"vendors": [
|
"vendors": [
|
||||||
{
|
{
|
||||||
"name": "guh",
|
"name": "guh",
|
||||||
|
|||||||
Reference in New Issue
Block a user