From 809517483e4e81ac449d3f40822251429ff141fc Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 21 Oct 2017 00:45:48 +0200 Subject: [PATCH] update hue plugin to follow lights interfaces --- philipshue/devicepluginphilipshue.cpp | 46 ++++++++++++++------------ philipshue/devicepluginphilipshue.json | 14 ++++---- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/philipshue/devicepluginphilipshue.cpp b/philipshue/devicepluginphilipshue.cpp index db8b78d4..3bfc3b40 100644 --- a/philipshue/devicepluginphilipshue.cpp +++ b/philipshue/devicepluginphilipshue.cpp @@ -352,7 +352,7 @@ void DevicePluginPhilipsHue::networkManagerReplyReady() // check HTTP status code if (status != 200 || reply->error() != QNetworkReply::NoError) { - if (device->stateValue(hueLightHueReachableStateTypeId).toBool()) { + if (device->stateValue(hueLightReachableStateTypeId).toBool()) { qCWarning(dcPhilipsHue) << "Refresh Hue lights request error:" << status << reply->errorString(); bridgeReachableChanged(device, false); } @@ -416,20 +416,20 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device, return DeviceManager::DeviceErrorHardwareNotAvailable; } - if (action.actionTypeId() == hueLightHuePowerActionTypeId) { - QPair request = light->createSetPowerRequest(action.param(hueLightHuePowerStateParamTypeId).value().toBool()); + if (action.actionTypeId() == hueLightPowerActionTypeId) { + QPair request = light->createSetPowerRequest(action.param(hueLightPowerStateParamTypeId).value().toBool()); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); m_asyncActions.insert(reply, QPair(device, action.id())); return DeviceManager::DeviceErrorAsync; - } else if (action.actionTypeId() == hueLightHueColorActionTypeId) { - QPair request = light->createSetColorRequest(action.param(hueLightHueColorStateParamTypeId).value().value()); + } else if (action.actionTypeId() == hueLightColorActionTypeId) { + QPair request = light->createSetColorRequest(action.param(hueLightColorStateParamTypeId).value().value()); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); m_asyncActions.insert(reply,QPair(device, action.id())); return DeviceManager::DeviceErrorAsync; - } else if (action.actionTypeId() == hueLightHueBrightnessActionTypeId) { - QPair request = light->createSetBrightnessRequest(percentageToBrightness(action.param(hueLightHueBrightnessStateParamTypeId).value().toInt())); + } else if (action.actionTypeId() == hueLightBrightnessActionTypeId) { + QPair request = light->createSetBrightnessRequest(percentageToBrightness(action.param(hueLightBrightnessStateParamTypeId).value().toInt())); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); m_asyncActions.insert(reply, QPair(device, action.id())); @@ -446,8 +446,8 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device, connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); m_asyncActions.insert(reply, QPair(device, action.id())); return DeviceManager::DeviceErrorAsync; - } else if (action.actionTypeId() == hueLightHueTemperatureActionTypeId) { - QPair request = light->createSetTemperatureRequest(action.param(hueLightHueTemperatureStateParamTypeId).value().toInt()); + } else if (action.actionTypeId() == hueLightColorTemperatureActionTypeId) { + QPair request = light->createSetTemperatureRequest(action.param(hueLightColorTemperatureStateParamTypeId).value().toInt()); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); m_asyncActions.insert(reply, QPair(device, action.id())); @@ -465,14 +465,14 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device, return DeviceManager::DeviceErrorHardwareNotAvailable; } - if (action.actionTypeId() == hueWhiteLightHuePowerActionTypeId) { - QPair request = light->createSetPowerRequest(action.param(hueWhiteLightHuePowerStateParamTypeId).value().toBool()); + if (action.actionTypeId() == hueWhiteLightPowerActionTypeId) { + QPair request = light->createSetPowerRequest(action.param(hueWhiteLightPowerStateParamTypeId).value().toBool()); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); m_asyncActions.insert(reply, QPair(device, action.id())); return DeviceManager::DeviceErrorAsync; - } else if (action.actionTypeId() == hueWhiteLightHueBrightnessActionTypeId) { - QPair request = light->createSetBrightnessRequest(percentageToBrightness(action.param(hueWhiteLightHueBrightnessStateParamTypeId).value().toInt())); + } else if (action.actionTypeId() == hueWhiteLightBrightnessActionTypeId) { + QPair request = light->createSetBrightnessRequest(percentageToBrightness(action.param(hueWhiteLightBrightnessStateParamTypeId).value().toInt())); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); m_asyncActions.insert(reply, QPair(device, action.id())); @@ -526,16 +526,16 @@ void DevicePluginPhilipsHue::lightStateChanged() } if (device->deviceClassId() == hueLightDeviceClassId) { - device->setStateValue(hueLightHueReachableStateTypeId, light->reachable()); - device->setStateValue(hueLightHueColorStateTypeId, QVariant::fromValue(light->color())); - device->setStateValue(hueLightHuePowerStateTypeId, light->power()); - device->setStateValue(hueLightHueBrightnessStateTypeId, brightnessToPercentage(light->brightness())); - device->setStateValue(hueLightHueTemperatureStateTypeId, light->ct()); + device->setStateValue(hueLightReachableStateTypeId, light->reachable()); + device->setStateValue(hueLightColorStateTypeId, QVariant::fromValue(light->color())); + device->setStateValue(hueLightPowerStateTypeId, light->power()); + device->setStateValue(hueLightBrightnessStateTypeId, brightnessToPercentage(light->brightness())); + device->setStateValue(hueLightColorTemperatureStateTypeId, light->ct()); device->setStateValue(hueLightHueEffectStateTypeId, light->effect()); } else if (device->deviceClassId() == hueWhiteLightDeviceClassId) { device->setStateValue(hueWhiteLightHueReachableStateTypeId, light->reachable()); - device->setStateValue(hueWhiteLightHuePowerStateTypeId, light->power()); - device->setStateValue(hueWhiteLightHueBrightnessStateTypeId, brightnessToPercentage(light->brightness())); + device->setStateValue(hueWhiteLightPowerStateTypeId, light->power()); + device->setStateValue(hueWhiteLightBrightnessStateTypeId, brightnessToPercentage(light->brightness())); } } @@ -1193,7 +1193,11 @@ void DevicePluginPhilipsHue::bridgeReachableChanged(Device *device, const bool & foreach (HueLight *light, m_lights.keys()) { if (light->bridgeId() == device->id()) { light->setReachable(false); - m_lights.value(light)->setStateValue(hueLightHueReachableStateTypeId, false); + if (m_lights.value(light)->deviceClassId() == hueLightDeviceClassId) { + m_lights.value(light)->setStateValue(hueLightReachableStateTypeId, false); + } else if (m_lights.value(light)->deviceClassId() == hueWhiteLightDeviceClassId) { + m_lights.value(light)->setStateValue(hueWhiteLightHueReachableStateTypeId, false); + } } } diff --git a/philipshue/devicepluginphilipshue.json b/philipshue/devicepluginphilipshue.json index b42ba95b..05f6467f 100644 --- a/philipshue/devicepluginphilipshue.json +++ b/philipshue/devicepluginphilipshue.json @@ -217,7 +217,7 @@ "stateTypes": [ { "id": "19bb8d10-1b28-4ba3-99b7-a634138dcfde", - "name": "hueReachable", + "name": "reachable", "displayName": "reachable", "displayNameEvent": "reachable changed", "defaultValue": false, @@ -225,7 +225,7 @@ }, { "id": "90aaffe5-6a76-47d2-a14a-550f60390245", - "name": "huePower", + "name": "power", "displayName": "power", "displayNameEvent": "power changed", "displayNameAction": "Set power", @@ -235,7 +235,7 @@ }, { "id": "c0f4206f-f219-4f06-93c4-4ca515a56f79", - "name": "hueTemperature", + "name": "colorTemperature", "displayName": "color temperature", "displayNameEvent": "color temperature changed", "displayNameAction": "Set color temperature", @@ -250,7 +250,7 @@ }, { "id": "d25423e7-b924-4b20-80b6-77eecc65d089", - "name": "hueColor", + "name": "color", "displayName": "color", "displayNameEvent": "color changed", "displayNameAction": "Set color", @@ -263,7 +263,7 @@ }, { "id": "90e91f64-a208-468c-a5a2-7f47e08859e2", - "name": "hueBrightness", + "name": "brightness", "displayName": "brightness", "displayNameEvent": "brightness changed", "displayNameAction": "Set brigtness", @@ -399,7 +399,7 @@ }, { "id": "90aaffe5-6a76-47d2-a14a-550f60390245", - "name": "huePower", + "name": "power", "displayName": "power", "displayNameEvent": "power changed", "displayNameAction": "Set power", @@ -409,7 +409,7 @@ }, { "id": "90e91f64-a208-468c-a5a2-7f47e08859e2", - "name": "hueBrightness", + "name": "brightness", "displayName": "brightness", "displayNameEvent": "brightness changed", "displayNameAction": "Set brightness",