diff --git a/libnymea-core/hardware/network/mqtt/mqttproviderimplementation.cpp b/libnymea-core/hardware/network/mqtt/mqttproviderimplementation.cpp index cbd878c2..c1f9c235 100644 --- a/libnymea-core/hardware/network/mqtt/mqttproviderimplementation.cpp +++ b/libnymea-core/hardware/network/mqtt/mqttproviderimplementation.cpp @@ -111,6 +111,11 @@ MqttClient *MqttProviderImplementation::createInternalClient(const DeviceId &dev client->setPassword(policy.password); client->setAutoReconnect(false); + connect(client, &MqttClient::destroyed, this, [this, clientId]() { + qCDebug(dcMqtt) << "Internal MQTT client destroyed. Removing policy"; + m_broker->removePolicy(clientId); + }); + if (preferredConfig.address == QHostAddress::Any || preferredConfig.address == QHostAddress::AnyIPv4 || preferredConfig.address == QHostAddress::LocalHost) {