From aaaafb7f39cb17dca85de13b7c714eb4d2601037 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 25 Jun 2014 00:15:52 +0200 Subject: [PATCH] add reachable state to hue lights --- .../philipshue/devicepluginphilipshue.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/deviceplugins/philipshue/devicepluginphilipshue.cpp b/plugins/deviceplugins/philipshue/devicepluginphilipshue.cpp index e5b2e5d9..c27552e9 100644 --- a/plugins/deviceplugins/philipshue/devicepluginphilipshue.cpp +++ b/plugins/deviceplugins/philipshue/devicepluginphilipshue.cpp @@ -42,6 +42,8 @@ ActionTypeId hueSetPowerActionTypeId = ActionTypeId("7782d91e-d73a-4321-8828-da7 StateTypeId hueBrightnessStateTypeId = StateTypeId("411f489c-4bc9-42f7-b47d-b0581dc0c29e"); ActionTypeId hueSetBrightnessActionTypeId = ActionTypeId("3bc95552-cba0-4222-abd5-9b668132e442"); +StateTypeId hueReachableStateTypeId = StateTypeId("15794d26-fde8-4a61-8f83-d7830534975f"); + DevicePluginPhilipsHue::DevicePluginPhilipsHue(): m_discovery(new Discovery(this)) { @@ -82,6 +84,11 @@ QList DevicePluginPhilipsHue::supportedDevices() const QList hueStates; + StateType reachableState(hueReachableStateTypeId); + reachableState.setName("reachable"); + reachableState.setType(QVariant::Bool); + hueStates.append(reachableState); + StateType colorState(hueColorStateTypeId); colorState.setName("color"); colorState.setType(QVariant::Color); @@ -126,7 +133,6 @@ QList DevicePluginPhilipsHue::supportedDevices() const ParamType actionParamSetBrightness("brightness", QVariant::Int); actionParamSetBrightness.setMinValue(0); actionParamSetBrightness.setMaxValue(255); - actionParamSetBrightness.setDefaultValue(255); actionParamsSetBrightness.append(actionParamSetBrightness); setBrightnessAction.setParameters(actionParamsSetBrightness); hueActons.append(setBrightnessAction); @@ -270,6 +276,10 @@ QPair DevicePluginPhilipsHue::executeAction return report(DeviceManager::DeviceErrorDeviceNotFound, device->id().toString()); } + if (!light->reachable()) { + return report(DeviceManager::DeviceErrorSetupFailed, "This light is currently not reachable."); + } + if (action.actionTypeId() == hueSetColorActionTypeId) { light->setColor(action.param("color").value().value()); } else if (action.actionTypeId() == hueSetPowerActionTypeId) { @@ -363,6 +373,7 @@ void DevicePluginPhilipsHue::lightStateChanged() if (!device) { return; } + device->setStateValue(hueReachableStateTypeId, light->reachable()); device->setStateValue(hueColorStateTypeId, QVariant::fromValue(light->color())); device->setStateValue(huePowerStateTypeId, light->on()); device->setStateValue(hueBrightnessStateTypeId, light->bri());