fix pointer error

This commit is contained in:
Simon Stürz 2016-03-12 16:45:32 +01:00 committed by Michael Zanetti
parent 941abee1f0
commit c01ba09b33
2 changed files with 11 additions and 6 deletions

View File

@ -119,6 +119,7 @@ void DevicePluginAwattar::deviceRemoved(Device *device)
{ {
Q_UNUSED(device) Q_UNUSED(device)
qDeleteAll(m_heatPumps); qDeleteAll(m_heatPumps);
m_heatPumps.clear();
m_device = 0; m_device = 0;
} }
@ -393,10 +394,8 @@ void DevicePluginAwattar::processPumpSearchData(const QByteArray &data)
continue; continue;
// check if we already created this heat pump // check if we already created this heat pump
if (heatPumpExists(pumpAddress)) { if (heatPumpExists(pumpAddress))
qCWarning(dcAwattar) << "Could not read pump address" << line;
continue; continue;
}
qCDebug(dcAwattar) << "New heat pump found at" << pumpAddress.toString(); qCDebug(dcAwattar) << "New heat pump found at" << pumpAddress.toString();
QPointer<HeatPump> pump = new HeatPump(pumpAddress, this); QPointer<HeatPump> pump = new HeatPump(pumpAddress, this);
@ -407,6 +406,9 @@ void DevicePluginAwattar::processPumpSearchData(const QByteArray &data)
void DevicePluginAwattar::setSgMode(const int &sgMode) void DevicePluginAwattar::setSgMode(const int &sgMode)
{ {
if (m_device.isNull())
return;
switch (sgMode) { switch (sgMode) {
case 1: case 1:
m_device->setStateValue(sgModeStateTypeId, "1 - Off"); m_device->setStateValue(sgModeStateTypeId, "1 - Off");
@ -425,7 +427,10 @@ void DevicePluginAwattar::setSgMode(const int &sgMode)
return; return;
} }
foreach (HeatPump *pump, m_heatPumps) { foreach (QPointer<HeatPump> pump, m_heatPumps) {
if (pump.isNull())
continue;
pump->setSgMode(sgMode); pump->setSgMode(sgMode);
} }
} }

View File

@ -59,10 +59,10 @@ bool HeatPump::reachable() const
void HeatPump::setSgMode(const int &sgMode) 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) { if (m_sgMode != sgMode) {
m_sgMode = sgMode; m_sgMode = sgMode;
qCDebug(dcAwattar) << "Setting sg-mode to" << 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; QUrl url;
@ -70,7 +70,7 @@ void HeatPump::setSgMode(const int &sgMode)
url.setHost(m_address.toString()); url.setHost(m_address.toString());
url.setPath("/a/sg_mode"); 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); CoapReply *reply = m_coap->post(CoapRequest(url), payload);
if (reply->error() != CoapReply::NoError) { if (reply->error() != CoapReply::NoError) {