@@ -75,8 +75,10 @@ zwave_frame_generator frame_generator(COMMAND_CLASS_USER_CREDENTIAL);
7575
7676// Callbacks
7777std::set<user_credential_slot_changed_callback_t > user_credential_slot_changed_callback;
78+ std::set<user_credential_slot_message_callback_t > user_credential_slot_message_callback;
7879}
7980
81+
8082// ///////////////////////////////////////////////////////////////////////////
8183// Callbacks
8284// ///////////////////////////////////////////////////////////////////////////
@@ -88,6 +90,26 @@ void zwave_command_class_user_credential_set_uuic_slot_changed_callback(
8890 }
8991}
9092
93+ void zwave_command_class_user_credential_set_message_callback (
94+ user_credential_slot_message_callback_t callback)
95+ {
96+ if (callback != nullptr ) {
97+ user_credential_slot_message_callback.insert (callback);
98+ }
99+ }
100+
101+ void send_message_to_mqtt (sl_log_level level, const std::string &message)
102+ {
103+ if (level == SL_LOG_DEBUG) {
104+ sl_log_critical (LOG_TAG, " Debug message should not be sent to MQTT" );
105+ return ;
106+ }
107+ sl_log (LOG_TAG, level, " %s" , message.c_str ());
108+
109+ for (auto &callback: user_credential_slot_message_callback) {
110+ callback (level, message);
111+ }
112+ }
91113
92114// ///////////////////////////////////////////////////////////////////////////
93115// Version & Attribute Creation
@@ -1206,19 +1228,21 @@ sl_status_t zwave_command_class_user_credential_uuic_association_report(
12061228 // If something went wrong end device side, log the error and return
12071229 // This should handle the slot already taken case
12081230 if (association_status != USER_CREDENTIAL_ASSOCIATION_REPORT_SUCCESS) {
1209- sl_log_error (LOG_TAG,
1210- " User Unique Identifier Credential Association error. "
1211- " Reported status code : %d" ,
1212- association_status);
1231+ send_message_to_mqtt (SL_LOG_ERROR,
1232+ " User Unique Identifier Credential Association error. "
1233+ " Reported status code : " + std::to_string (association_status));
12131234 return SL_STATUS_OK;
12141235 }
12151236
1216- sl_log_info (LOG_TAG,
1217- " Moving slot %d (user %d) to slot %d (user %d)" ,
1218- source_credential_slot,
1219- source_user_id,
1220- destination_credential_slot,
1221- destination_user_id);
1237+ send_message_to_mqtt (
1238+ SL_LOG_INFO,
1239+ (boost::format (" Credential Slot %1% for type %2% (user %3%) moved to "
1240+ " Credential slot %4% (user %5%)" )
1241+ % source_credential_slot
1242+ % static_cast <unsigned int >(source_credential_type) % source_user_id
1243+ % destination_credential_slot % destination_user_id)
1244+ .str ());
1245+
12221246 source_credential_slot_node.set_reported (destination_credential_slot);
12231247
12241248 // Need to move to new user
@@ -1239,13 +1263,13 @@ sl_status_t zwave_command_class_user_credential_uuic_association_report(
12391263 sl_status_t result = source_credential_slot_node.change_parent (
12401264 destination_credential_type_node);
12411265 if (result != SL_STATUS_OK) {
1242- sl_log_error (
1243- LOG_TAG ,
1244- " Error while moving slot %d (user %d) to slot %d (user %d) " ,
1245- source_credential_slot,
1246- source_user_id,
1247- destination_credential_slot,
1248- destination_user_id );
1266+ send_message_to_mqtt (
1267+ SL_LOG_ERROR ,
1268+ ( boost::format (
1269+ " Error while moving slot %1% (user %2%) to slot %3% (user %4%) " )
1270+ % source_credential_slot % source_user_id
1271+ % destination_credential_slot % destination_user_id)
1272+ . str () );
12491273 return result;
12501274 }
12511275 }
0 commit comments