From 0c63dc696ed5dea460d41c0b80843de278ddf3aa Mon Sep 17 00:00:00 2001 From: John Date: Sat, 7 Oct 2023 19:42:05 +0200 Subject: [PATCH] use readable message counter part only for writable message with multiple fields in definition topic if integration does not combine them --- src/ebusd/mqtthandler.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index 54b4a760..19029c06 100755 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -838,11 +838,21 @@ void MqttHandler::run() { if (filterPriority > 0 && (message->getPollPriority() == 0 || message->getPollPriority() > filterPriority)) { continue; } - if (includeActiveWrite && !message->isWrite()) { - // check for existance of write message with same name - Message* write = m_messages->find(message->getCircuit(), message->getName(), "", true); - if (write) { - continue; // avoid sending definition of read AND write message with the same key + if (includeActiveWrite) { + if (message->isWrite()) { + bool skipMultiFieldWrite = (!m_hasDefinitionFieldsPayload || m_publishByField) && !message->isPassive() && message->getFieldCount() > 1; + if (skipMultiFieldWrite) { + continue; // multi-field message is not writable when publishing by field or combining multiple fields in one definition, so skip it + } + } else { + // check for existance of write message with same name + Message* write = m_messages->find(message->getCircuit(), message->getName(), "", true); + if (write) { + bool skipMultiFieldWrite = (!m_hasDefinitionFieldsPayload || m_publishByField) && write->getFieldCount() > 1; + if (!skipMultiFieldWrite) { + continue; // avoid sending definition of read AND write message with the same key + } // else: multi-field write message is not writable when publishing by field or combining multiple fields in one definition, so skip it + } } } StringReplacers msgValues = m_replacers; // need a copy here as the contents are manipulated