From 54d4d8b3418351a1e4ae45db5a09c3adf38ef8f2 Mon Sep 17 00:00:00 2001 From: technyon Date: Fri, 12 Aug 2022 23:04:04 +0200 Subject: [PATCH] publish keypad command result --- MqttTopics.h | 1 + NetworkLock.cpp | 5 +++++ NetworkLock.h | 1 + NukiWrapper.cpp | 25 +++++++++++++++++++------ lib/nuki_ble | 2 +- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/MqttTopics.h b/MqttTopics.h index 010412e..a342aac 100644 --- a/MqttTopics.h +++ b/MqttTopics.h @@ -32,6 +32,7 @@ #define mqtt_topic_keypad_command_name "/keypad/command/name" #define mqtt_topic_keypad_command_code "/keypad/command/code" #define mqtt_topic_keypad_command_enabled "/keypad/command/enabled" +#define mqtt_topic_keypad_command_enabled "/keypad/command/commandResult" #define mqtt_topic_presence "/presence/devices" diff --git a/NetworkLock.cpp b/NetworkLock.cpp index a9a350c..c54a63e 100644 --- a/NetworkLock.cpp +++ b/NetworkLock.cpp @@ -286,6 +286,11 @@ void NetworkLock::publishKeypad(const std::list& entries, } } +void NetworkLock::publishKeypadCommandResult(const char* result) +{ + publishString(mqtt_topic_keypad_command_enabled, result); +} + void NetworkLock::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *)) { _lockActionReceivedCallback = lockActionReceivedCallback; diff --git a/NetworkLock.h b/NetworkLock.h index ff4a03f..0457bc0 100644 --- a/NetworkLock.h +++ b/NetworkLock.h @@ -30,6 +30,7 @@ public: void publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState); void removeHASSConfig(char* uidString); void publishKeypad(const std::list& entries, uint maxKeypadCodeCount); + void publishKeypadCommandResult(const char* result); void setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char* value)); void setConfigUpdateReceivedCallback(void (*configUpdateReceivedCallback)(const char* path, const char* value)); diff --git a/NukiWrapper.cpp b/NukiWrapper.cpp index 5d11b5d..101f556 100644 --- a/NukiWrapper.cpp +++ b/NukiWrapper.cpp @@ -358,6 +358,8 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c return; } + NukiLock::CmdResult result = (NukiLock::CmdResult)-1; + if(strcmp(command, "add") == 0) { if(name == "") @@ -370,14 +372,14 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c size_t nameLen = name.length(); memcpy(&entry.name, name.c_str(), nameLen > 20 ? 20 : nameLen); entry.code = code.toInt(); - const auto r = _nukiLock.addKeypadEntry(entry); - Serial.print("Add keypad code: "); Serial.println((int)r); + result = _nukiLock.addKeypadEntry(entry); + Serial.print("Add keypad code: "); Serial.println((int)result); updateKeypad(); } else if(strcmp(command, "delete") == 0) { - const auto r = _nukiLock.deleteKeypadEntry(id); - Serial.print("Delete keypad code: "); Serial.println((int)r); + result = _nukiLock.deleteKeypadEntry(id); + Serial.print("Delete keypad code: "); Serial.println((int)result); updateKeypad(); } if(strcmp(command, "update") == 0) @@ -394,10 +396,21 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c memcpy(&entry.name, name.c_str(), nameLen > 20 ? 20 : nameLen); entry.code = code.toInt(); entry.enabled = enabled == 0 ? 0 : 1; - const auto r = _nukiLock.updateKeypadEntry(entry); - Serial.print("Update keypad code: "); Serial.println((int)r); + result = _nukiLock.updateKeypadEntry(entry); + Serial.print("Update keypad code: "); Serial.println((int)result); updateKeypad(); } + + if((int)result != -1) + { + char resultStr[15]; + memset(&resultStr, 0, sizeof(resultStr)); + NukiLock::cmdResultToString(result, resultStr); + _network->publishKeypadCommandResult(resultStr); + } else + { + _network->publishKeypadCommandResult("UnknownCommand"); + } } const NukiLock::KeyTurnerState &NukiWrapper::keyTurnerState() diff --git a/lib/nuki_ble b/lib/nuki_ble index 822fd64..1d78e91 160000 --- a/lib/nuki_ble +++ b/lib/nuki_ble @@ -1 +1 @@ -Subproject commit 822fd645af574613d0c19a5ef38738d1052ce1ec +Subproject commit 1d78e91750ed88f5a0fb136043ad8b5573bbbccd