From 1ac51e6ff093c5f2a1dc0c10dcf5c8f3f94ac4e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 6 Oct 2015 15:36:56 +0200 Subject: [PATCH] add hue debug messages --- meta/guhd-wrapper.sh | 2 +- .../philipshue/devicepluginphilipshue.cpp | 88 +++++++++++++------ 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/meta/guhd-wrapper.sh b/meta/guhd-wrapper.sh index ea1ced7c..5bea6ff8 100755 --- a/meta/guhd-wrapper.sh +++ b/meta/guhd-wrapper.sh @@ -2,4 +2,4 @@ export QT_PLUGIN_PATH=$SNAP_APP_PATH/usr/lib/qt5/plugins export LD_LIBRARY_PATH=$SNAP_APP_PATH/usr/lib:$LD_LIBRARY_PATH -$SNAP_APP_PATH/usr/bin/guhd -n -d LogEngine +$SNAP_APP_PATH/usr/bin/guhd -n -d PhilipsHue diff --git a/plugins/deviceplugins/philipshue/devicepluginphilipshue.cpp b/plugins/deviceplugins/philipshue/devicepluginphilipshue.cpp index 58cbdeb7..ba926a8d 100644 --- a/plugins/deviceplugins/philipshue/devicepluginphilipshue.cpp +++ b/plugins/deviceplugins/philipshue/devicepluginphilipshue.cpp @@ -91,6 +91,7 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::discoverDevices(const DeviceC Q_UNUSED(deviceClassId) Q_UNUSED(params) + qCDebug(dcPhilipsHue) << "Start discovering Hue Bridges..."; upnpDiscover("libhue:idl"); return DeviceManager::DeviceErrorAsync; } @@ -111,9 +112,26 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev device->setParamValue("id", b->id()); device->setParamValue("mac address", b->macAddress()); m_bridges.insert(b, device); - device->setStateValue(bridgeReachableStateTypeId, true); - discoverBridgeDevices(b); - m_timer->start(); + + // now add the child lights from this bridge as auto device + QList descriptors; + foreach (HueLight *light, b->lights()) { + DeviceDescriptor descriptor(hueLightDeviceClassId, "Philips Hue Light", light->name()); + ParamList params; + params.append(Param("name", light->name())); + params.append(Param("api key", light->apiKey())); + params.append(Param("bridge", device->id().toString())); + params.append(Param("host address", light->hostAddress().toString())); + params.append(Param("model id", light->modelId())); + params.append(Param("light id", light->lightId())); + descriptor.setParams(params); + descriptors.append(descriptor); + qCDebug(dcPhilipsHue) << "Emit auto device appeared: light" << light->name(); + } + + emit autoDevicesAppeared(hueLightDeviceClassId, descriptors); + + qCDebug(dcPhilipsHue) << "Adding Hue bridge" << b->hostAddress().toString(); return DeviceManager::DeviceSetupStatusSuccess; } } @@ -130,7 +148,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev bridge->setZigbeeChannel(device->paramValue("zigbee channel").toInt()); m_bridges.insert(bridge, device); - m_timer->start(); + qCDebug(dcPhilipsHue) << "Setup Hue bridge success" << bridge->hostAddress().toString(); return DeviceManager::DeviceSetupStatusSuccess; } @@ -176,8 +194,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev connect(hueLight, &HueLight::stateChanged, this, &DevicePluginPhilipsHue::lightStateChanged); m_lights.insert(hueLight, device); - refreshLight(device); - + qCDebug(dcPhilipsHue) << "Setup hue light" << hueLight->name(); setLightName(device, device->paramValue("name").toString()); return DeviceManager::DeviceSetupStatusSuccess; } @@ -254,6 +271,7 @@ void DevicePluginPhilipsHue::upnpDiscoveryFinished(const QListpairingTransactionId(), DeviceManager::DeviceSetupStatusSuccess); - pairingInfo->deleteLater(); + // create Lights + QVariantMap lightsMap = response.value("lights").toMap(); + foreach (QString lightId, lightsMap.keys()) { + QVariantMap lightMap = lightsMap.value(lightId).toMap(); + HueLight *hueLight = new HueLight(lightId.toInt(), + bridge->hostAddress(), + lightMap.value("name").toString(), + pairingInfo.apiKey, + lightMap.value("modelid").toString(), + DeviceId(), + this); + + hueLight->updateStates(lightMap.value("state").toMap()); + + bridge->addLight(hueLight); + m_unconfiguredLights.append(hueLight); + + connect(hueLight, &HueLight::stateChanged, this, &DevicePluginPhilipsHue::lightStateChanged); + } + qCDebug(dcPhilipsHue) << "Emit pairing finished"; + emit pairingFinished(pairingInfo.pairingTransactionId, DeviceManager::DeviceSetupStatusSuccess); } void DevicePluginPhilipsHue::processActionResponse(Device *device, const ActionId actionId, const QByteArray &data) @@ -1152,25 +1199,14 @@ void DevicePluginPhilipsHue::processActionResponse(Device *device, const ActionI void DevicePluginPhilipsHue::bridgeReachableChanged(Device *device, const bool &reachable) { - if (reachable) { - device->setStateValue(bridgeReachableStateTypeId, true); - } else { - // mark bridge and corresponding hue devices unreachable - if (device->deviceClassId() == hueBridgeDeviceClassId) { - device->setStateValue(bridgeReachableStateTypeId, false); + qCWarning(dcPhilipsHue) << "Bridge error happend" << device->id().toString(); - foreach (HueLight *light, m_lights.keys()) { - if (light->bridgeId() == device->id()) { - light->setReachable(false); - m_lights.value(light)->setStateValue(hueReachableStateTypeId, false); - } - } - - foreach (HueRemote *remote, m_remotes.keys()) { - if (remote->bridgeId() == device->id()) { - remote->setReachable(false); - m_remotes.value(remote)->setStateValue(hueReachableStateTypeId, false); - } + // mark bridge and lamps unreachable + if (device->deviceClassId() == hueBridgeDeviceClassId) { + device->setStateValue(bridgeReachableStateTypeId, false); + foreach (HueLight *light, m_lights.keys()) { + if (light->bridgeId() == device->id()) { + device->setStateValue(hueReachableStateTypeId, false); } } }