Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call configuration_key_changed_callback when set_custom_configuration_key finished successfully #427

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/ocpp/v16/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ class ChargePoint {
const std::function<void(const int32_t connector, const int32_t transaction_id)>& callback);

/// \brief registers a \p callback function that can be used to react on changed configuration keys. This
/// callback is called when a configuration key has been changed by the CSMS
/// callback is called when a configuration key has been successfully changed by the CSMS or internally using the
/// set_custom_configuration_key function
/// \param key the configuration key for which the callback is registered
/// \param callback executed when this configuration key changed
void register_configuration_key_changed_callback(const CiString<50>& key,
Expand Down
16 changes: 15 additions & 1 deletion lib/ocpp/v16/charge_point_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3658,7 +3658,21 @@ GetConfigurationResponse ChargePointImpl::get_configuration_key(const GetConfigu
}

ConfigurationStatus ChargePointImpl::set_custom_configuration_key(CiString<50> key, CiString<500> value) {
return this->configuration->setCustomKey(key, value, true);
// attempt to set the custom key
const auto result = this->configuration->setCustomKey(key, value, true);
if (result != ConfigurationStatus::Accepted) {
// return immediately if not "Accepted"
return result;
}

// notify callback if registered and change was accepted
if (this->configuration_key_changed_callbacks.count(key) and
this->configuration_key_changed_callbacks[key] != nullptr and result == ConfigurationStatus::Accepted) {
KeyValue kv = {key, false, value};
this->configuration_key_changed_callbacks[key](kv);
}

return result;
}

} // namespace v16
Expand Down
Loading