update how id names are generated
include the deviceClass/plugin name in all defines to avoid collisions between deviceClasses within the same file. So far this hasn't really been an issue because using idName we could set random ids. Now interfaces dictate the names, so having multiple deviceClasses in one file and both implementing the same interface would clash. This also should improve readability in the plugins code as we won't have ids like: "bridgeConnected" and "connected" available which easily causes the developer to accidentally use "connected" where instead "bridgeConnected" should be used (I actually found some bugs like this while updating plugins for this). The new style would force those states to be named like e.g. "bridgeConnected" and "lightConnected" which are not as easy to mix up.
This commit is contained in:
parent
948ffb968c
commit
562e7aa89d
@ -77,7 +77,7 @@ def extractPlugin(pluginMap):
|
|||||||
def extractParamTypes(paramTypes, contextName):
|
def extractParamTypes(paramTypes, contextName):
|
||||||
for paramType in paramTypes:
|
for paramType in paramTypes:
|
||||||
try:
|
try:
|
||||||
variableName = '%sParamTypeId' % (paramType['name'])
|
variableName = '%sParamTypeId' % (contextName + paramType['name'][0].capitalize() + paramType['name'][1:])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
printInfo('Define ParamTypeId %s = %s' % (variableName, paramType['id']))
|
printInfo('Define ParamTypeId %s = %s' % (variableName, paramType['id']))
|
||||||
@ -155,7 +155,7 @@ def extractStateTypes(stateTypes, deviceClassName):
|
|||||||
for stateType in stateTypes:
|
for stateType in stateTypes:
|
||||||
try:
|
try:
|
||||||
# Define StateType
|
# Define StateType
|
||||||
variableName = '%sStateTypeId' % (stateType['name'])
|
variableName = '%s%sStateTypeId' % (deviceClassName, stateType['name'][0].capitalize() + stateType['name'][1:])
|
||||||
#addTranslationString(stateType['name'], 'The name of the stateType (%s) of DeviceClass %s' % (stateType['id'], deviceClassName))
|
#addTranslationString(stateType['name'], 'The name of the stateType (%s) of DeviceClass %s' % (stateType['id'], deviceClassName))
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
@ -167,7 +167,7 @@ def extractStateTypes(stateTypes, deviceClassName):
|
|||||||
printWarning('Duplicated variable name \"%s\" for StateTypeId %s -> skipping' % (variableName, stateType['id']))
|
printWarning('Duplicated variable name \"%s\" for StateTypeId %s -> skipping' % (variableName, stateType['id']))
|
||||||
|
|
||||||
# Create EventTypeId for this state
|
# Create EventTypeId for this state
|
||||||
variableName = '%sEventTypeId' % (stateType['name'])
|
variableName = '%s%sEventTypeId' % (deviceClassName, stateType['name'][0].capitalize() + stateType['name'][1:])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
addTranslationString(stateType['displayNameEvent'], 'The name of the autocreated EventType (%s)' % stateType['id'])
|
addTranslationString(stateType['displayNameEvent'], 'The name of the autocreated EventType (%s)' % stateType['id'])
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
@ -179,7 +179,7 @@ def extractStateTypes(stateTypes, deviceClassName):
|
|||||||
printWarning('Duplicated variable name \"%s\" for autocreated EventTypeId %s -> skipping' % (variableName, stateType['id']))
|
printWarning('Duplicated variable name \"%s\" for autocreated EventTypeId %s -> skipping' % (variableName, stateType['id']))
|
||||||
|
|
||||||
#ParamType for EventType/ActionType
|
#ParamType for EventType/ActionType
|
||||||
variableName = '%sStateParamTypeId' % (stateType['name'])
|
variableName = '%s%sStateParamTypeId' % (deviceClassName, stateType['name'][0].capitalize() + stateType['name'][1:])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
printInfo('Define ParamTypeId %s for StateType %s = %s' % (variableName, variableName, stateType['id']))
|
printInfo('Define ParamTypeId %s for StateType %s = %s' % (variableName, variableName, stateType['id']))
|
||||||
@ -192,7 +192,7 @@ def extractStateTypes(stateTypes, deviceClassName):
|
|||||||
|
|
||||||
# Create ActionTypeId if the state is writable
|
# Create ActionTypeId if the state is writable
|
||||||
if 'writable' in stateType and stateType['writable']:
|
if 'writable' in stateType and stateType['writable']:
|
||||||
variableName = '%sActionTypeId' % (stateType['name'])
|
variableName = '%s%sActionTypeId' % (deviceClassName, stateType['name'][0].capitalize() + stateType['name'][1:])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
printInfo('Define ActionTypeId for writable StateType %s = %s' % (variableName, stateType['id']))
|
printInfo('Define ActionTypeId for writable StateType %s = %s' % (variableName, stateType['id']))
|
||||||
@ -212,7 +212,7 @@ def extractActionTypes(actionTypes, deviceClassName):
|
|||||||
for actionType in actionTypes:
|
for actionType in actionTypes:
|
||||||
try:
|
try:
|
||||||
# Define ActionTypeId
|
# Define ActionTypeId
|
||||||
variableName = '%sActionTypeId' % (actionType['name'])
|
variableName = '%s%sActionTypeId' % (deviceClassName, actionType['name'][0].capitalize() + actionType['name'][1:])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
addTranslationString(actionType['displayName'], 'The name of the ActionType %s of deviceClass %s' % (actionType['id'], deviceClassName))
|
addTranslationString(actionType['displayName'], 'The name of the ActionType %s of deviceClass %s' % (actionType['id'], deviceClassName))
|
||||||
@ -235,7 +235,7 @@ def extractEventTypes(eventTypes, deviceClassName):
|
|||||||
for eventType in eventTypes:
|
for eventType in eventTypes:
|
||||||
try:
|
try:
|
||||||
# Define EventTypeId
|
# Define EventTypeId
|
||||||
variableName = '%sEventTypeId' % (eventType['name'])
|
variableName = '%s%sEventTypeId' % (deviceClassName, eventType['name'][0].capitalize() + eventType['name'][1:])
|
||||||
if not variableName in variableNames:
|
if not variableName in variableNames:
|
||||||
variableNames.append(variableName)
|
variableNames.append(variableName)
|
||||||
addTranslationString(eventType['displayName'], 'The name of the EventType %s of deviceClass %s' % (eventType['id'], deviceClassName))
|
addTranslationString(eventType['displayName'], 'The name of the EventType %s of deviceClass %s' % (eventType['id'], deviceClassName))
|
||||||
@ -320,9 +320,10 @@ def writePluginInfoFile():
|
|||||||
writeToFile('// Logging category')
|
writeToFile('// Logging category')
|
||||||
|
|
||||||
if 'name' in pluginMap:
|
if 'name' in pluginMap:
|
||||||
writeToFile('Q_DECLARE_LOGGING_CATEGORY(dc%s)' % pluginMap['name'])
|
debugCategoryName = pluginMap['name'][0].capitalize() + pluginMap['name'][1:]
|
||||||
writeToFile('Q_LOGGING_CATEGORY(dc%s, \"%s\")' % (pluginMap['name'], pluginMap['name']))
|
writeToFile('Q_DECLARE_LOGGING_CATEGORY(dc%s)' % debugCategoryName)
|
||||||
printInfo('Define logging category: \'dc%s\'' % pluginMap['name'])
|
writeToFile('Q_LOGGING_CATEGORY(dc%s, \"%s\")' % (debugCategoryName, debugCategoryName))
|
||||||
|
printInfo('Define logging category: \'dc%s\'' % debugCategoryName)
|
||||||
|
|
||||||
writeToFile('')
|
writeToFile('')
|
||||||
|
|
||||||
@ -359,7 +360,8 @@ def writeExternPluginInfoFile():
|
|||||||
writeToFile('// Logging category definition')
|
writeToFile('// Logging category definition')
|
||||||
|
|
||||||
if 'name' in pluginMap:
|
if 'name' in pluginMap:
|
||||||
writeToFile('Q_DECLARE_LOGGING_CATEGORY(dc%s)' % pluginMap['name'])
|
debugCategoryName = pluginMap['name'][0].capitalize() + pluginMap['name'][1:]
|
||||||
|
writeToFile('Q_DECLARE_LOGGING_CATEGORY(dc%s)' % debugCategoryName)
|
||||||
|
|
||||||
writeToFile('')
|
writeToFile('')
|
||||||
writeToFile('#endif // EXTERNPLUGININFO_H')
|
writeToFile('#endif // EXTERNPLUGININFO_H')
|
||||||
|
|||||||
@ -63,19 +63,19 @@ DevicePluginMock::~DevicePluginMock()
|
|||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginMock::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
DeviceManager::DeviceError DevicePluginMock::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||||
{
|
{
|
||||||
if (deviceClassId == mockDeviceClassId || deviceClassId == mockDeviceAutoDeviceClassId) {
|
if (deviceClassId == mockDeviceClassId) {
|
||||||
qCDebug(dcMockDevice) << "starting mock discovery:" << params;
|
qCDebug(dcMockDevice) << "starting mock discovery:" << params;
|
||||||
m_discoveredDeviceCount = params.paramValue(resultCountParamTypeId).toInt();
|
m_discoveredDeviceCount = params.paramValue(mockResultCountParamTypeId).toInt();
|
||||||
QTimer::singleShot(1000, this, SLOT(emitDevicesDiscovered()));
|
QTimer::singleShot(1000, this, SLOT(emitDevicesDiscovered()));
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else if (deviceClassId == mockPushButtonDeviceClassId) {
|
} else if (deviceClassId == mockPushButtonDeviceClassId) {
|
||||||
qCDebug(dcMockDevice) << "starting mock push button discovery:" << params;
|
qCDebug(dcMockDevice) << "starting mock push button discovery:" << params;
|
||||||
m_discoveredDeviceCount = params.paramValue(resultCountParamTypeId).toInt();
|
m_discoveredDeviceCount = params.paramValue(mockPushButtonResultCountParamTypeId).toInt();
|
||||||
QTimer::singleShot(1000, this, SLOT(emitPushButtonDevicesDiscovered()));
|
QTimer::singleShot(1000, this, SLOT(emitPushButtonDevicesDiscovered()));
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else if (deviceClassId == mockDisplayPinDeviceClassId) {
|
} else if (deviceClassId == mockDisplayPinDeviceClassId) {
|
||||||
qCDebug(dcMockDevice) << "starting mock display pin discovery:" << params;
|
qCDebug(dcMockDevice) << "starting mock display pin discovery:" << params;
|
||||||
m_discoveredDeviceCount = params.paramValue(resultCountParamTypeId).toInt();
|
m_discoveredDeviceCount = params.paramValue(mockDisplayPinResultCountParamTypeId).toInt();
|
||||||
QTimer::singleShot(1000, this, SLOT(emitDisplayPinDevicesDiscovered()));
|
QTimer::singleShot(1000, this, SLOT(emitDisplayPinDevicesDiscovered()));
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
}
|
}
|
||||||
@ -85,12 +85,17 @@ DeviceManager::DeviceError DevicePluginMock::discoverDevices(const DeviceClassId
|
|||||||
DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
if (device->deviceClassId() == mockDeviceClassId || device->deviceClassId() == mockDeviceAutoDeviceClassId) {
|
if (device->deviceClassId() == mockDeviceClassId || device->deviceClassId() == mockDeviceAutoDeviceClassId) {
|
||||||
qCDebug(dcMockDevice) << "Mockdevice created returning true"
|
bool async = false;
|
||||||
<< device->paramValue(httpportParamTypeId).toInt()
|
bool broken = false;
|
||||||
<< device->paramValue(asyncParamTypeId).toBool()
|
if (device->deviceClassId() == mockDeviceClassId) {
|
||||||
<< device->paramValue(brokenParamTypeId).toBool();
|
async = device->paramValue(mockAsyncParamTypeId).toBool();
|
||||||
|
broken = device->paramValue(mockBrokenParamTypeId).toBool();
|
||||||
|
} else {
|
||||||
|
async = device->paramValue(mockDeviceAutoAsyncParamTypeId).toBool();
|
||||||
|
broken = device->paramValue(mockDeviceAutoBrokenParamTypeId).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
if (device->paramValue(brokenParamTypeId).toBool()) {
|
if (broken) {
|
||||||
qCWarning(dcMockDevice) << "This device is intentionally broken.";
|
qCWarning(dcMockDevice) << "This device is intentionally broken.";
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
}
|
}
|
||||||
@ -108,7 +113,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
|
|||||||
// Keep this queued or it might happen that the HttpDaemon is deleted before it is able to reply to the caller
|
// Keep this queued or it might happen that the HttpDaemon is deleted before it is able to reply to the caller
|
||||||
connect(daemon, &HttpDaemon::disappear, this, &DevicePluginMock::onDisappear, Qt::QueuedConnection);
|
connect(daemon, &HttpDaemon::disappear, this, &DevicePluginMock::onDisappear, Qt::QueuedConnection);
|
||||||
|
|
||||||
if (device->paramValue(asyncParamTypeId).toBool()) {
|
if (async) {
|
||||||
m_asyncSetupDevices.append(device);
|
m_asyncSetupDevices.append(device);
|
||||||
QTimer::singleShot(1000, this, SLOT(emitDeviceSetupFinished()));
|
QTimer::singleShot(1000, this, SLOT(emitDeviceSetupFinished()));
|
||||||
return DeviceManager::DeviceSetupStatusAsync;
|
return DeviceManager::DeviceSetupStatusAsync;
|
||||||
@ -125,7 +130,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMock::setupDevice(Device *device)
|
|||||||
return DeviceManager::DeviceSetupStatusSuccess;
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
} else if (device->deviceClassId() == mockChildDeviceClassId) {
|
} else if (device->deviceClassId() == mockChildDeviceClassId) {
|
||||||
qCDebug(dcMockDevice) << "Setup Child mock device" << device->params();
|
qCDebug(dcMockDevice) << "Setup Child mock device" << device->params();
|
||||||
device->setParentId(DeviceId(device->params().paramValue(parentUuidParamTypeId).toString()));
|
device->setParentId(DeviceId(device->params().paramValue(mockChildParentUuidParamTypeId).toString()));
|
||||||
return DeviceManager::DeviceSetupStatusSuccess;
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
} else if (device->deviceClassId() == mockInputTypeDeviceClassId) {
|
} else if (device->deviceClassId() == mockInputTypeDeviceClassId) {
|
||||||
qCDebug(dcMockDevice) << "Setup InputType mock device" << device->params();
|
qCDebug(dcMockDevice) << "Setup InputType mock device" << device->params();
|
||||||
@ -166,7 +171,7 @@ void DevicePluginMock::startMonitoringAutoDevices()
|
|||||||
ParamList params;
|
ParamList params;
|
||||||
qsrand(QDateTime::currentMSecsSinceEpoch());
|
qsrand(QDateTime::currentMSecsSinceEpoch());
|
||||||
int port = 4242 + (qrand() % 1000);
|
int port = 4242 + (qrand() % 1000);
|
||||||
Param param(httpportParamTypeId, port);
|
Param param(mockDeviceAutoHttpportParamTypeId, port);
|
||||||
params.append(param);
|
params.append(param);
|
||||||
mockDescriptor.setParams(params);
|
mockDescriptor.setParams(params);
|
||||||
|
|
||||||
@ -218,50 +223,94 @@ DeviceManager::DeviceError DevicePluginMock::displayPin(const PairingTransaction
|
|||||||
|
|
||||||
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 (!myDevices().contains(device))
|
||||||
if (!myDevices().contains(device))
|
return DeviceManager::DeviceErrorDeviceNotFound;
|
||||||
return DeviceManager::DeviceErrorDeviceNotFound;
|
|
||||||
|
|
||||||
if (action.actionTypeId() == mockAsyncActionTypeId || action.actionTypeId() == mockAsyncFailingActionTypeId) {
|
if (device->deviceClassId() == mockDeviceClassId) {
|
||||||
|
if (action.actionTypeId() == mockMockAsyncActionTypeId || action.actionTypeId() == mockMockAsyncFailingActionTypeId) {
|
||||||
m_asyncActions.append(qMakePair<Action, Device*>(action, device));
|
m_asyncActions.append(qMakePair<Action, Device*>(action, device));
|
||||||
QTimer::singleShot(1000, this, SLOT(emitActionExecuted()));
|
QTimer::singleShot(1000, this, SLOT(emitActionExecuted()));
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.actionTypeId() == mockFailingActionTypeId)
|
if (action.actionTypeId() == mockMockFailingActionTypeId)
|
||||||
return DeviceManager::DeviceErrorSetupFailed;
|
return DeviceManager::DeviceErrorSetupFailed;
|
||||||
|
|
||||||
m_daemons.value(device)->actionExecuted(action.actionTypeId());
|
m_daemons.value(device)->actionExecuted(action.actionTypeId());
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
} else if (device->deviceClassId() == mockPushButtonDeviceClassId || device->deviceClassId() == mockDisplayPinDeviceClassId) {
|
} else if (device->deviceClassId() == mockDeviceAutoDeviceClassId) {
|
||||||
if (action.actionTypeId() == colorActionTypeId) {
|
if (action.actionTypeId() == mockDeviceAutoMockActionAsyncActionTypeId || action.actionTypeId() == mockDeviceAutoMockActionAsyncBrokenActionTypeId) {
|
||||||
QString colorString = action.param(colorStateParamTypeId).value().toString();
|
m_asyncActions.append(qMakePair<Action, Device*>(action, device));
|
||||||
|
QTimer::singleShot(1000, this, SLOT(emitActionExecuted()));
|
||||||
|
return DeviceManager::DeviceErrorAsync;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action.actionTypeId() == mockDeviceAutoMockActionBrokenActionTypeId)
|
||||||
|
return DeviceManager::DeviceErrorSetupFailed;
|
||||||
|
|
||||||
|
m_daemons.value(device)->actionExecuted(action.actionTypeId());
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
} else if (device->deviceClassId() == mockPushButtonDeviceClassId) {
|
||||||
|
if (action.actionTypeId() == mockPushButtonColorActionTypeId) {
|
||||||
|
QString colorString = action.param(mockPushButtonColorStateParamTypeId).value().toString();
|
||||||
QColor color(colorString);
|
QColor color(colorString);
|
||||||
if (!color.isValid()) {
|
if (!color.isValid()) {
|
||||||
qCWarning(dcMockDevice) << "Invalid color parameter";
|
qCWarning(dcMockDevice) << "Invalid color parameter";
|
||||||
return DeviceManager::DeviceErrorInvalidParameter;
|
return DeviceManager::DeviceErrorInvalidParameter;
|
||||||
}
|
}
|
||||||
device->setStateValue(colorStateTypeId, colorString);
|
device->setStateValue(mockPushButtonColorStateTypeId, colorString);
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
} else if (action.actionTypeId() == percentageActionTypeId) {
|
} else if (action.actionTypeId() == mockPushButtonPercentageActionTypeId) {
|
||||||
device->setStateValue(percentageStateTypeId, action.param(percentageStateParamTypeId).value().toInt());
|
device->setStateValue(mockPushButtonPercentageStateTypeId, action.param(mockPushButtonPercentageStateParamTypeId).value().toInt());
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
} else if (action.actionTypeId() == allowedValuesActionTypeId) {
|
} else if (action.actionTypeId() == mockPushButtonAllowedValuesActionTypeId) {
|
||||||
device->setStateValue(allowedValuesStateTypeId, action.param(allowedValuesStateParamTypeId).value().toString());
|
device->setStateValue(mockPushButtonAllowedValuesStateTypeId, action.param(mockPushButtonAllowedValuesStateParamTypeId).value().toString());
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
} else if (action.actionTypeId() == doubleActionTypeId) {
|
} else if (action.actionTypeId() == mockPushButtonDoubleActionTypeId) {
|
||||||
device->setStateValue(doubleStateTypeId, action.param(doubleStateParamTypeId).value().toDouble());
|
device->setStateValue(mockPushButtonDoubleStateTypeId, action.param(mockPushButtonDoubleStateParamTypeId).value().toDouble());
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
} else if (action.actionTypeId() == boolActionTypeId) {
|
} else if (action.actionTypeId() == mockPushButtonBoolActionTypeId) {
|
||||||
device->setStateValue(boolValueStateTypeId, action.param(boolValueStateParamTypeId).value().toBool());
|
device->setStateValue(mockPushButtonBoolStateTypeId, action.param(mockPushButtonBoolStateParamTypeId).value().toBool());
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
} else if (action.actionTypeId() == timeoutActionTypeId) {
|
} else if (action.actionTypeId() == mockPushButtonTimeoutActionTypeId) {
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
}
|
}
|
||||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
} else if (device->deviceClassId() == mockParentDeviceClassId || device->deviceClassId() == mockChildDeviceClassId) {
|
} else if (device->deviceClassId() == mockDisplayPinDeviceClassId) {
|
||||||
if (action.actionTypeId() == boolValueParentActionTypeId) {
|
if (action.actionTypeId() == mockDisplayPinColorActionTypeId) {
|
||||||
device->setStateValue(boolValueParentStateTypeId, action.param(boolValueParentStateParamTypeId).value().toBool());
|
QString colorString = action.param(mockDisplayPinColorStateParamTypeId).value().toString();
|
||||||
|
QColor color(colorString);
|
||||||
|
if (!color.isValid()) {
|
||||||
|
qCWarning(dcMockDevice) << "Invalid color parameter";
|
||||||
|
return DeviceManager::DeviceErrorInvalidParameter;
|
||||||
|
}
|
||||||
|
device->setStateValue(mockDisplayPinColorStateTypeId, colorString);
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
} else if (action.actionTypeId() == mockDisplayPinPercentageActionTypeId) {
|
||||||
|
device->setStateValue(mockDisplayPinPercentageStateTypeId, action.param(mockDisplayPinPercentageStateParamTypeId).value().toInt());
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
} else if (action.actionTypeId() == mockDisplayPinAllowedValuesActionTypeId) {
|
||||||
|
device->setStateValue(mockDisplayPinAllowedValuesStateTypeId, action.param(mockDisplayPinAllowedValuesStateParamTypeId).value().toString());
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
} else if (action.actionTypeId() == mockDisplayPinDoubleActionTypeId) {
|
||||||
|
device->setStateValue(mockDisplayPinDoubleStateTypeId, action.param(mockDisplayPinDoubleStateParamTypeId).value().toDouble());
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
} else if (action.actionTypeId() == mockDisplayPinBoolActionTypeId) {
|
||||||
|
device->setStateValue(mockDisplayPinBoolStateTypeId, action.param(mockDisplayPinBoolStateParamTypeId).value().toBool());
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
} else if (action.actionTypeId() == mockDisplayPinTimeoutActionTypeId) {
|
||||||
|
return DeviceManager::DeviceErrorAsync;
|
||||||
|
}
|
||||||
|
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
|
} else if (device->deviceClassId() == mockParentDeviceClassId) {
|
||||||
|
if (action.actionTypeId() == mockParentBoolValueParentActionTypeId) {
|
||||||
|
device->setStateValue(mockParentBoolValueParentStateTypeId, action.param(mockParentBoolValueParentStateParamTypeId).value().toBool());
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
}
|
||||||
|
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
|
} else if (device->deviceClassId() == mockChildDeviceClassId) {
|
||||||
|
if (action.actionTypeId() == mockChildBoolValueParentActionTypeId) {
|
||||||
|
device->setStateValue(mockChildBoolValueParentStateTypeId, action.param(mockChildBoolValueParentStateParamTypeId).value().toBool());
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
@ -311,7 +360,7 @@ void DevicePluginMock::emitDevicesDiscovered()
|
|||||||
if (m_discoveredDeviceCount > 0) {
|
if (m_discoveredDeviceCount > 0) {
|
||||||
DeviceDescriptor d1(mockDeviceClassId, "Mock Device 1 (Discovered)", "55555");
|
DeviceDescriptor d1(mockDeviceClassId, "Mock Device 1 (Discovered)", "55555");
|
||||||
ParamList params;
|
ParamList params;
|
||||||
Param httpParam(httpportParamTypeId, "55555");
|
Param httpParam(mockHttpportParamTypeId, "55555");
|
||||||
params.append(httpParam);
|
params.append(httpParam);
|
||||||
d1.setParams(params);
|
d1.setParams(params);
|
||||||
deviceDescriptors.append(d1);
|
deviceDescriptors.append(d1);
|
||||||
@ -320,7 +369,7 @@ void DevicePluginMock::emitDevicesDiscovered()
|
|||||||
if (m_discoveredDeviceCount > 1) {
|
if (m_discoveredDeviceCount > 1) {
|
||||||
DeviceDescriptor d2(mockDeviceClassId, "Mock Device 2 (Discovered)", "55556");
|
DeviceDescriptor d2(mockDeviceClassId, "Mock Device 2 (Discovered)", "55556");
|
||||||
ParamList params;
|
ParamList params;
|
||||||
Param httpParam(httpportParamTypeId, "55556");
|
Param httpParam(mockHttpportParamTypeId, "55556");
|
||||||
params.append(httpParam);
|
params.append(httpParam);
|
||||||
d2.setParams(params);
|
d2.setParams(params);
|
||||||
deviceDescriptors.append(d2);
|
deviceDescriptors.append(d2);
|
||||||
@ -376,7 +425,7 @@ void DevicePluginMock::emitDeviceSetupFinished()
|
|||||||
{
|
{
|
||||||
qCDebug(dcMockDevice) << "Emitting setup finised";
|
qCDebug(dcMockDevice) << "Emitting setup finised";
|
||||||
Device *device = m_asyncSetupDevices.takeFirst();
|
Device *device = m_asyncSetupDevices.takeFirst();
|
||||||
if (device->paramValue(brokenParamTypeId).toBool()) {
|
if (device->paramValue(mockBrokenParamTypeId).toBool()) {
|
||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure);
|
||||||
} else {
|
} else {
|
||||||
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
|
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess);
|
||||||
@ -386,10 +435,10 @@ void DevicePluginMock::emitDeviceSetupFinished()
|
|||||||
void DevicePluginMock::emitActionExecuted()
|
void DevicePluginMock::emitActionExecuted()
|
||||||
{
|
{
|
||||||
QPair<Action, Device*> action = m_asyncActions.takeFirst();
|
QPair<Action, Device*> action = m_asyncActions.takeFirst();
|
||||||
if (action.first.actionTypeId() == mockAsyncActionTypeId) {
|
if (action.first.actionTypeId() == mockMockAsyncActionTypeId) {
|
||||||
m_daemons.value(action.second)->actionExecuted(action.first.actionTypeId());
|
m_daemons.value(action.second)->actionExecuted(action.first.actionTypeId());
|
||||||
emit actionExecutionFinished(action.first.id(), DeviceManager::DeviceErrorNoError);
|
emit actionExecutionFinished(action.first.id(), DeviceManager::DeviceErrorNoError);
|
||||||
} else if (action.first.actionTypeId() == mockAsyncFailingActionTypeId) {
|
} else if (action.first.actionTypeId() == mockMockAsyncFailingActionTypeId) {
|
||||||
emit actionExecutionFinished(action.first.id(), DeviceManager::DeviceErrorSetupFailed);
|
emit actionExecutionFinished(action.first.id(), DeviceManager::DeviceErrorSetupFailed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -411,7 +460,7 @@ void DevicePluginMock::onChildDeviceDiscovered(const DeviceId &parentId)
|
|||||||
qCDebug(dcMockDevice) << "Child device discovered for parent" << parentId.toString();
|
qCDebug(dcMockDevice) << "Child device discovered for parent" << parentId.toString();
|
||||||
DeviceDescriptor mockDescriptor(mockChildDeviceClassId, "Child Mock Device (Auto created)");
|
DeviceDescriptor mockDescriptor(mockChildDeviceClassId, "Child Mock Device (Auto created)");
|
||||||
ParamList params;
|
ParamList params;
|
||||||
params.append(Param(parentUuidParamTypeId, parentId));
|
params.append(Param(mockChildParentUuidParamTypeId, parentId));
|
||||||
mockDescriptor.setParams(params);
|
mockDescriptor.setParams(params);
|
||||||
|
|
||||||
emit autoDevicesAppeared(mockChildDeviceClassId, QList<DeviceDescriptor>() << mockDescriptor);
|
emit autoDevicesAppeared(mockChildDeviceClassId, QList<DeviceDescriptor>() << mockDescriptor);
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
HttpDaemon::HttpDaemon(Device *device, DevicePlugin *parent):
|
HttpDaemon::HttpDaemon(Device *device, DevicePlugin *parent):
|
||||||
QTcpServer(parent), disabled(false), m_plugin(parent), m_device(device)
|
QTcpServer(parent), disabled(false), m_plugin(parent), m_device(device)
|
||||||
{
|
{
|
||||||
listen(QHostAddress::Any, device->paramValue(httpportParamTypeId).toInt());
|
listen(QHostAddress::Any, device->paramValue(mockHttpportParamTypeId).toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpDaemon::~HttpDaemon()
|
HttpDaemon::~HttpDaemon()
|
||||||
|
|||||||
@ -141,7 +141,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QHash<QString, bool> loggingFiltersPlugins;
|
QHash<QString, bool> loggingFiltersPlugins;
|
||||||
foreach (const QJsonObject &pluginMetadata, DeviceManager::pluginsMetadata()) {
|
foreach (const QJsonObject &pluginMetadata, DeviceManager::pluginsMetadata()) {
|
||||||
loggingFiltersPlugins.insert(pluginMetadata.value("name").toString(), false);
|
QString pluginName = pluginMetadata.value("name").toString();
|
||||||
|
loggingFiltersPlugins.insert(pluginName.left(1).toUpper() + pluginName.mid(1), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translator for the server application
|
// Translator for the server application
|
||||||
|
|||||||
Reference in New Issue
Block a user