From f4b0badfd8f865d01f8c5eb2fff88d1b4ac73d2e Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 3 Apr 2020 18:13:44 +0200 Subject: [PATCH] Fix occationally lost button events --- philipshue/hueremote.cpp | 8 +++++--- philipshue/hueremote.h | 1 + philipshue/integrationpluginphilipshue.cpp | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/philipshue/hueremote.cpp b/philipshue/hueremote.cpp index 1b6f3069..e0a43ae5 100644 --- a/philipshue/hueremote.cpp +++ b/philipshue/hueremote.cpp @@ -66,10 +66,12 @@ void HueRemote::updateStates(const QVariantMap &statesMap, const QVariantMap &co m_lastUpdate = lastUpdate; } - if (m_lastUpdate != lastUpdate) { - m_lastUpdate = lastUpdate; + int buttonCode = statesMap.value("buttonevent").toInt(); + + if (m_lastUpdate != lastUpdate || m_lastButtonCode != buttonCode) { + m_lastUpdate = lastUpdate; + m_lastButtonCode = buttonCode; - int buttonCode = statesMap.value("buttonevent").toInt(); qCDebug(dcPhilipsHue) << "button pressed" << buttonCode; emit buttonPressed(buttonCode); diff --git a/philipshue/hueremote.h b/philipshue/hueremote.h index 25519cbd..c59839d9 100644 --- a/philipshue/hueremote.h +++ b/philipshue/hueremote.h @@ -54,6 +54,7 @@ public: private: int m_battery; QString m_lastUpdate; + int m_lastButtonCode = -1; signals: void stateChanged(); diff --git a/philipshue/integrationpluginphilipshue.cpp b/philipshue/integrationpluginphilipshue.cpp index 41428ae1..abb8e1ae 100644 --- a/philipshue/integrationpluginphilipshue.cpp +++ b/philipshue/integrationpluginphilipshue.cpp @@ -1371,9 +1371,9 @@ void IntegrationPluginPhilipsHue::processBridgeSensorDiscoveryResponse(Thing *th QString uuid = sensorMap.value("uniqueid").toString(); QString model = sensorMap.value("modelid").toString(); - qCDebug(dcPhilipsHue()) << "Found sensor on bridge:" << model << uuid; +// qCDebug(dcPhilipsHue()) << "Found sensor on bridge:" << model << uuid; foreach (HueRemote* remote, remotesToRemove) { - qCDebug(dcPhilipsHue()) << " - Checking remote to remove" << remote->modelId() << remote->uuid(); +// qCDebug(dcPhilipsHue()) << " - Checking remote to remove" << remote->modelId() << remote->uuid(); if (remote->uuid() == uuid) { remotesToRemove.removeAll(remote); break;