Skip to content

Commit 591224e

Browse files
committed
Make more explicit and clear that properties are echoed back to the cloud even if not changed in callback
1 parent bb33feb commit 591224e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/property/Property.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Property::Property()
4949
, _lightPayload{false}
5050
, _update_requested{false}
5151
, _encode_timestamp{false}
52+
, _echo_requested{false}
5253
, _timestamp{0}
5354
{
5455

@@ -115,6 +116,10 @@ bool Property::shouldBeUpdated() {
115116
return true;
116117
}
117118

119+
if (_echo_requested) {
120+
return true;
121+
}
122+
118123
if (_update_policy == UpdatePolicy::OnChange) {
119124
return (isDifferentFromCloud() && ((millis() - _last_updated_millis) >= (_min_time_between_updates_millis)));
120125
} else if (_update_policy == UpdatePolicy::TimeInterval) {
@@ -131,6 +136,11 @@ void Property::requestUpdate()
131136
_update_requested = true;
132137
}
133138

139+
void Property::provideEcho()
140+
{
141+
_echo_requested = true;
142+
}
143+
134144
void Property::appendCompleted()
135145
{
136146
if (_has_been_appended_but_not_sended) {
@@ -142,7 +152,7 @@ void Property::execCallbackOnChange() {
142152
if (_update_callback_func != nullptr) {
143153
_update_callback_func();
144154
}
145-
if (!isDifferentFromCloud()) {
155+
if (isDifferentFromCloud()) {
146156
_has_been_modified_in_callback = true;
147157
}
148158
}
@@ -161,6 +171,7 @@ CborError Property::append(CborEncoder *encoder, bool lightPayload) {
161171
_has_been_updated_once = true;
162172
_has_been_modified_in_callback = false;
163173
_update_requested = false;
174+
_echo_requested = false;
164175
_has_been_appended_but_not_sended = true;
165176
_last_updated_millis = millis();
166177
return CborNoError;

src/property/Property.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class Property
175175
bool shouldBeUpdated();
176176
void requestUpdate();
177177
void appendCompleted();
178+
void provideEcho();
178179
void execCallbackOnChange();
179180
void execCallbackOnSync();
180181
void setLastCloudChangeTimestamp(unsigned long cloudChangeTime);
@@ -248,6 +249,8 @@ class Property
248249
bool _update_requested;
249250
/* Indicates whether the timestamp shall be encoded in the property or not */
250251
bool _encode_timestamp;
252+
/* Indicates if the property shall be echoed back to the cloud even if unchanged */
253+
bool _echo_requested;
251254
unsigned long _timestamp;
252255
};
253256

src/property/PropertyContainer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void updateProperty(PropertyContainer & prop_cont, String propertyName, unsigned
123123
} else {
124124
property->fromCloudToLocal();
125125
property->execCallbackOnChange();
126+
property->provideEcho();
126127
}
127128
}
128129
}

0 commit comments

Comments
 (0)