Skip to content

Commit 72a7db4

Browse files
committed
Merge branch 'bugfix/persist_param_cb' into 'master'
bugfix: Callback for persistent parameters wasn't getting invoked See merge request app-frameworks/esp-rainmaker!181
2 parents 44467bc + 12fd24f commit 72a7db4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

components/esp_rainmaker/src/core/esp_rmaker_device.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,19 @@ esp_err_t esp_rmaker_device_add_param(const esp_rmaker_device_t *device, const e
136136
}
137137
}
138138
_new_param->val = stored_val;
139-
if (_device->write_cb && (_new_param->type && strcmp(_new_param->type, ESP_RMAKER_PARAM_NAME) != 0)) {
140-
esp_rmaker_write_ctx_t ctx = {
141-
.src = ESP_RMAKER_REQ_SRC_INIT,
142-
};
143-
_device->write_cb(device, param, stored_val, _device->priv_data, &ctx);
139+
/* The device callback should be invoked once with the stored value, so
140+
* that applications can do initialisations as required.
141+
*/
142+
if (_device->write_cb) {
143+
/* However, the callback should be invoked, only if the parameter is not
144+
* of type ESP_RMAKER_PARAM_NAME, as it has special handling internally.
145+
*/
146+
if (!(_new_param->type && strcmp(_new_param->type, ESP_RMAKER_PARAM_NAME) == 0)) {
147+
esp_rmaker_write_ctx_t ctx = {
148+
.src = ESP_RMAKER_REQ_SRC_INIT,
149+
};
150+
_device->write_cb(device, param, stored_val, _device->priv_data, &ctx);
151+
}
144152
}
145153
} else {
146154
esp_rmaker_param_store_value(_new_param);

0 commit comments

Comments
 (0)