Skip to content

Commit

Permalink
configuration_key_changed_callback function is now also called when s…
Browse files Browse the repository at this point in the history
…et_custom_configuration_key finished successfully (#427)

Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried authored Jan 30, 2024
1 parent ac0538e commit aae98f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit aae98f5

Please sign in to comment.