@@ -44,7 +44,8 @@ Property::Property()
4444 _last_cloud_change_timestamp(0 ),
4545 _identifier(0 ),
4646 _attributeIdentifier(0 ),
47- _lightPayload(false ) {
47+ _lightPayload(false ),
48+ _update_requested(false ) {
4849}
4950
5051/* *****************************************************************************
@@ -79,6 +80,11 @@ Property & Property::publishEvery(unsigned long const seconds) {
7980 return (*this );
8081}
8182
83+ Property & Property::publishOnDemand () {
84+ _update_policy = UpdatePolicy::OnDemand;
85+ return (*this );
86+ }
87+
8288bool Property::shouldBeUpdated () {
8389 if (!_has_been_updated_once) {
8490 return true ;
@@ -93,11 +99,18 @@ bool Property::shouldBeUpdated() {
9399 return (isDifferentFromCloud () && ((millis () - _last_updated_millis) >= (_min_time_between_updates_millis)));
94100 } else if (_update_policy == UpdatePolicy::TimeInterval) {
95101 return ((millis () - _last_updated_millis) >= _update_interval_millis);
102+ } else if (_update_policy == UpdatePolicy::OnDemand) {
103+ return _update_requested;
96104 } else {
97105 return false ;
98106 }
99107}
100108
109+ void Property::requestUpdate ()
110+ {
111+ _update_requested = true ;
112+ }
113+
101114void Property::execCallbackOnChange () {
102115 if (_update_callback_func != NULL ) {
103116 _update_callback_func ();
@@ -119,6 +132,7 @@ void Property::append(CborEncoder *encoder, bool lightPayload) {
119132 appendAttributesToCloudReal (encoder);
120133 fromLocalToCloud ();
121134 _has_been_updated_once = true ;
135+ _update_requested = false ;
122136 _last_updated_millis = millis ();
123137}
124138
0 commit comments