From 1f48651dee304f76ddea56ee8f858d021d0834c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sun, 26 Apr 2015 21:44:11 +0200 Subject: [PATCH] fixed tune execute action --- libguh/devicemanager.cpp | 4 ++-- plugins/deviceplugins/tune/deviceplugintune.cpp | 14 +++++++++----- plugins/deviceplugins/tune/jsonrpcserver.cpp | 10 +++++----- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index 8b0f2480..436aecc3 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -1085,12 +1085,12 @@ DeviceManager::DeviceError DeviceManager::verifyParam(const ParamType ¶mType return DeviceErrorInvalidParameter; } - if (paramType.maxValue().isValid() && param.value() > paramType.maxValue()) { + if (paramType.maxValue().isValid() && param.value().convert(paramType.type()) > paramType.maxValue().convert(paramType.type())) { qWarning() << "Value out of range for param" << param.name() << " Got:" << param.value() << " Max:" << paramType.maxValue(); return DeviceErrorInvalidParameter; } if (paramType.minValue().isValid() && param.value() < paramType.minValue()) { - qWarning() << "Value out of range for param" << param.name() << " Got:" << param.value() << " Min:" << paramType.minValue(); + qWarning() << "Value out of range for param" << param.name() << " Got:" << param.value().convert(paramType.type()) << " Min:" << paramType.minValue().convert(paramType.type()); return DeviceErrorInvalidParameter; } if (!paramType.allowedValues().isEmpty() && !paramType.allowedValues().contains(param.value())) { diff --git a/plugins/deviceplugins/tune/deviceplugintune.cpp b/plugins/deviceplugins/tune/deviceplugintune.cpp index 276546b1..bcfd8e10 100644 --- a/plugins/deviceplugins/tune/deviceplugintune.cpp +++ b/plugins/deviceplugins/tune/deviceplugintune.cpp @@ -175,7 +175,7 @@ void DevicePluginTune::updateTune(const QVariantMap &message) void DevicePluginTune::processActionResponse(const QVariantMap &message) { bool success = message.value("success").toBool(); - ActionId actionId = ActionId(message.value("params").toMap().value("actionId").toString()); + ActionId actionId = ActionId(message.value("actionId").toString()); if (success) { emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorNoError); } else { @@ -189,16 +189,20 @@ DeviceManager::DeviceError DevicePluginTune::executeAction(Device *device, const return DeviceManager::DeviceErrorHardwareNotAvailable; } - if (device->deviceClassId() != moodDeviceClassId || device->deviceClassId() != tuneDeviceClassId) { + // check DeviceClassId + if (device->deviceClassId() != moodDeviceClassId && device->deviceClassId() != tuneDeviceClassId) { return DeviceManager::DeviceErrorDeviceClassNotFound; } - if (action.actionTypeId() != powerActionTypeId || - action.actionTypeId() != brightnessActionTypeId || - action.actionTypeId() != valueActionTypeId){ + // check ActionTypeId + if (action.actionTypeId() != powerActionTypeId && + action.actionTypeId() != brightnessActionTypeId && + action.actionTypeId() != valueActionTypeId && + action.actionTypeId() != activeActionTypeId){ return DeviceManager::DeviceErrorActionTypeNotFound; } + // request the action execution on tune m_server->executeAction(device, action); return DeviceManager::DeviceErrorAsync; } diff --git a/plugins/deviceplugins/tune/jsonrpcserver.cpp b/plugins/deviceplugins/tune/jsonrpcserver.cpp index 984242d0..3bee46de 100644 --- a/plugins/deviceplugins/tune/jsonrpcserver.cpp +++ b/plugins/deviceplugins/tune/jsonrpcserver.cpp @@ -110,13 +110,13 @@ void JsonRpcServer::executeAction(Device *device, const Action &action) QVariantMap message; QVariantMap params; - params.insert("deviceId", device->deviceClassId()); + params.insert("deviceId", device->id()); params.insert("actionId", action.id()); if (device->deviceClassId() == moodDeviceClassId) { message.insert("method", "Mood.ExecuteAction"); if (action.actionTypeId() == valueActionTypeId) { - params.insert("value", action.param("percentage").value().toInt()); + params.insert("value", action.param("value").value().toInt()); params.insert("active", device->stateValue(activeStateTypeId).toBool()); } else if (action.actionTypeId() == activeActionTypeId) { params.insert("value", device->stateValue(valueStateTypeId).toInt()); @@ -124,10 +124,10 @@ void JsonRpcServer::executeAction(Device *device, const Action &action) } } else if(device->deviceClassId() == tuneDeviceClassId) { message.insert("method", "Tune.ExecuteAction"); - if (action.actionTypeId() == valueActionTypeId) { + if (action.actionTypeId() == brightnessActionTypeId) { params.insert("brightness", action.param("brightness").value().toInt()); params.insert("power", device->stateValue(powerStateTypeId).toBool()); - } else if (action.actionTypeId() == activeActionTypeId) { + } else if (action.actionTypeId() == powerActionTypeId) { params.insert("brightness", device->stateValue(brightnessStateTypeId).toInt()); params.insert("power", action.param("power").value().toBool()); } @@ -173,7 +173,7 @@ void JsonRpcServer::handleResponse(const QVariantMap &response) return; } - // remove it request since we have a response now... + // remove it request because we have a response now... QVariantMap request = m_requests.take(responseId); // Note: maby we have to do something if any request fails