From 8cb6e727016081063ef9b107168a86fea5789ff3 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Mon, 26 Mar 2018 20:06:30 +0200 Subject: [PATCH] drop logic to mark hue as unreachable if it doesn't reply in time. instead, always wait for the reply and mark it as gone if the reply is bad --- philipshue/devicepluginphilipshue.cpp | 17 ++++++----------- philipshue/hueremote.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/philipshue/devicepluginphilipshue.cpp b/philipshue/devicepluginphilipshue.cpp index 5832061e..137a3f55 100644 --- a/philipshue/devicepluginphilipshue.cpp +++ b/philipshue/devicepluginphilipshue.cpp @@ -290,6 +290,8 @@ void DevicePluginPhilipsHue::networkManagerReplyReady() QNetworkReply *reply = static_cast(sender()); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); +// qCDebug(dcPhilipsHue()) << "Hue reply:" << status << reply->error() << reply->errorString(); + // create user finished if (m_pairingRequests.contains(reply)) { PairingInfo *pairingInfo = m_pairingRequests.take(reply); @@ -440,7 +442,7 @@ void DevicePluginPhilipsHue::networkManagerReplyReady() } processSetNameResponse(device, reply->readAll()); } else { - qCWarning(dcPhilipsHue()) << "Unhandled bridge reply" << reply->readAll(); + qCWarning(dcPhilipsHue()) << "Unhandled bridge reply" << reply->error() << reply->readAll(); } reply->deleteLater(); } @@ -726,16 +728,8 @@ void DevicePluginPhilipsHue::refreshLight(Device *device) void DevicePluginPhilipsHue::refreshBridge(Device *device) { - if (m_bridgeRefreshRequests.values().contains(device)) { - qCWarning(dcPhilipsHue()) << "Old bridge refresh call pending. Cleaning up and marking device as unreachable."; - QNetworkReply *reply = m_bridgeRefreshRequests.key(device); - reply->abort(); - m_bridgeRefreshRequests.remove(reply); - reply->deleteLater(); - bridgeReachableChanged(device, false); - } - HueBridge *bridge = m_bridges.key(device); +// qCDebug(dcPhilipsHue()) << "refreshing bridge"; QNetworkRequest request(QUrl("http://" + bridge->hostAddress().toString() + "/api/" + bridge->apiKey() + "/config")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); @@ -747,6 +741,7 @@ void DevicePluginPhilipsHue::refreshBridge(Device *device) void DevicePluginPhilipsHue::refreshLights(HueBridge *bridge) { Device *device = m_bridges.value(bridge); +// qCDebug(dcPhilipsHue()) << "refreshing lights"; QNetworkRequest request(QUrl("http://" + bridge->hostAddress().toString() + "/api/" + bridge->apiKey() + "/lights")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); @@ -758,6 +753,7 @@ void DevicePluginPhilipsHue::refreshLights(HueBridge *bridge) void DevicePluginPhilipsHue::refreshSensors(HueBridge *bridge) { Device *device = m_bridges.value(bridge); +// qCDebug(dcPhilipsHue()) << "refreshing sensors"; QNetworkRequest request(QUrl("http://" + bridge->hostAddress().toString() + "/api/" + bridge->apiKey() + "/sensors")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); @@ -1094,7 +1090,6 @@ void DevicePluginPhilipsHue::processSensorsRefreshResponse(Device *device, const QVariantMap sensorMap = sensorsMap.value(sensorId).toMap(); foreach (HueRemote *remote, m_remotes.keys()) { if (remote->id() == sensorId.toInt() && m_remotes.value(remote)->parentId() == device->id()) { - qCDebug(dcPhilipsHue) << "update remote" << remote->id() << remote->name(); remote->updateStates(sensorMap.value("state").toMap(), sensorMap.value("config").toMap()); } } diff --git a/philipshue/hueremote.cpp b/philipshue/hueremote.cpp index 4ff69d69..95489a2c 100644 --- a/philipshue/hueremote.cpp +++ b/philipshue/hueremote.cpp @@ -52,6 +52,12 @@ void HueRemote::updateStates(const QVariantMap &statesMap, const QVariantMap &co emit stateChanged(); QString lastUpdate = statesMap.value("lastupdated").toString(); + + // If we never polled, just store the lastUpdate time and not emit a falsely button pressed event + if (m_lastUpdate.isEmpty()) { + m_lastUpdate = lastUpdate; + } + if (m_lastUpdate != lastUpdate) { m_lastUpdate = lastUpdate;