publish keypad command result

This commit is contained in:
technyon
2022-08-12 23:04:04 +02:00
parent 2f2825eeed
commit 54d4d8b341
5 changed files with 27 additions and 7 deletions

View File

@@ -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"

View File

@@ -286,6 +286,11 @@ void NetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries,
}
}
void NetworkLock::publishKeypadCommandResult(const char* result)
{
publishString(mqtt_topic_keypad_command_enabled, result);
}
void NetworkLock::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *))
{
_lockActionReceivedCallback = lockActionReceivedCallback;

View File

@@ -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<NukiLock::KeypadEntry>& 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));

View File

@@ -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()