From c01ba09b3322ad69736b913bcb8e5ece9b2cd7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sat, 12 Mar 2016 16:45:32 +0100 Subject: [PATCH] fix pointer error --- .../deviceplugins/awattar/devicepluginawattar.cpp | 13 +++++++++---- plugins/deviceplugins/awattar/heatpump.cpp | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/deviceplugins/awattar/devicepluginawattar.cpp b/plugins/deviceplugins/awattar/devicepluginawattar.cpp index db7de8f7..a8702768 100644 --- a/plugins/deviceplugins/awattar/devicepluginawattar.cpp +++ b/plugins/deviceplugins/awattar/devicepluginawattar.cpp @@ -119,6 +119,7 @@ void DevicePluginAwattar::deviceRemoved(Device *device) { Q_UNUSED(device) qDeleteAll(m_heatPumps); + m_heatPumps.clear(); m_device = 0; } @@ -393,10 +394,8 @@ void DevicePluginAwattar::processPumpSearchData(const QByteArray &data) continue; // check if we already created this heat pump - if (heatPumpExists(pumpAddress)) { - qCWarning(dcAwattar) << "Could not read pump address" << line; + if (heatPumpExists(pumpAddress)) continue; - } qCDebug(dcAwattar) << "New heat pump found at" << pumpAddress.toString(); QPointer pump = new HeatPump(pumpAddress, this); @@ -407,6 +406,9 @@ void DevicePluginAwattar::processPumpSearchData(const QByteArray &data) void DevicePluginAwattar::setSgMode(const int &sgMode) { + if (m_device.isNull()) + return; + switch (sgMode) { case 1: m_device->setStateValue(sgModeStateTypeId, "1 - Off"); @@ -425,7 +427,10 @@ void DevicePluginAwattar::setSgMode(const int &sgMode) return; } - foreach (HeatPump *pump, m_heatPumps) { + foreach (QPointer pump, m_heatPumps) { + if (pump.isNull()) + continue; + pump->setSgMode(sgMode); } } diff --git a/plugins/deviceplugins/awattar/heatpump.cpp b/plugins/deviceplugins/awattar/heatpump.cpp index 30a178de..2aceee43 100644 --- a/plugins/deviceplugins/awattar/heatpump.cpp +++ b/plugins/deviceplugins/awattar/heatpump.cpp @@ -59,10 +59,10 @@ bool HeatPump::reachable() const void HeatPump::setSgMode(const int &sgMode) { + // Note: always try to set sg-mode, to make sure the pump is still reachable (like a ping) if (m_sgMode != sgMode) { m_sgMode = sgMode; qCDebug(dcAwattar) << "Setting sg-mode to" << sgMode; - // Note: always try to set sg-mode, to make sure the pump is still reachable (like a ping) } QUrl url; @@ -70,7 +70,7 @@ void HeatPump::setSgMode(const int &sgMode) url.setHost(m_address.toString()); url.setPath("/a/sg_mode"); - QByteArray payload = QString("mode=%1").arg(QString::number(sgMode)).toUtf8(); + QByteArray payload = QString("mode=%1").arg(QString::number(m_sgMode)).toUtf8(); CoapReply *reply = m_coap->post(CoapRequest(url), payload); if (reply->error() != CoapReply::NoError) {