From b8f914c3587ca9e0c310c1e6379b7f19c783d7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20K=C3=B6pp?= Date: Fri, 1 Nov 2024 20:44:51 +0100 Subject: [PATCH] Fix: Do NOT Send when Updating KO Failed on Value Conversion --- src/knx/group_object.cpp | 18 ++++++++++++++---- src/knx/group_object.h | 12 ++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index e1e069b..3865d4a 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -226,8 +226,11 @@ GroupObjectUpdatedHandler GroupObject::callback() void GroupObject::value(const KNXValue& value, const Dpt& type) { - valueNoSend(value, type); - objectWritten(); + if (_valueNoSend(value, type)) + { + // write on successful conversion/setting value only + objectWritten(); + } } @@ -281,12 +284,20 @@ void GroupObject::valueNoSend(const KNXValue& value) #endif void GroupObject::valueNoSend(const KNXValue& value, const Dpt& type) +{ + // ignore actual updating TODO check replacing valueNoSend with _valueNoSend + _valueNoSend(value, type); +} + +bool GroupObject::_valueNoSend(const KNXValue& value, const Dpt& type) { const bool encodingDone = KNX_Encode_Value(value, _data, _dataLength, type); // initialize on succesful conversion only if (encodingDone && _commFlagEx.uninitialized) commFlag(Ok); + + return encodingDone; } bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) @@ -294,8 +305,7 @@ bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) if (_commFlagEx.uninitialized) { // always set first value - this->valueNoSend(value, type); - return true; + return _valueNoSend(value, type); } else { diff --git a/src/knx/group_object.h b/src/knx/group_object.h index 02bd0c3..80133a0 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -284,4 +284,16 @@ class GroupObject GroupObjectUpdatedHandler _updateHandler; Dpt _datapointType; #endif + + /** + * set the current value of the group object and show success. + * @param value the value the group object is set to + * @param type the datapoint type used for the conversion. + * + * The parameters must fit the group object. Otherwise it will stay unchanged. + * + * @returns true if the value of the group object was updated after successful conversion. + */ + bool _valueNoSend(const KNXValue& value, const Dpt& type); + };