add keypad command sanity checks
This commit is contained in:
@@ -32,7 +32,7 @@
|
|||||||
#define mqtt_topic_keypad_command_name "/keypad/command/name"
|
#define mqtt_topic_keypad_command_name "/keypad/command/name"
|
||||||
#define mqtt_topic_keypad_command_code "/keypad/command/code"
|
#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/enabled"
|
||||||
#define mqtt_topic_keypad_command_enabled "/keypad/command/commandResult"
|
#define mqtt_topic_keypad_command_result "/keypad/command/commandResult"
|
||||||
|
|
||||||
#define mqtt_topic_presence "/presence/devices"
|
#define mqtt_topic_presence "/presence/devices"
|
||||||
|
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ void NetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries,
|
|||||||
|
|
||||||
void NetworkLock::publishKeypadCommandResult(const char* result)
|
void NetworkLock::publishKeypadCommandResult(const char* result)
|
||||||
{
|
{
|
||||||
publishString(mqtt_topic_keypad_command_enabled, result);
|
publishString(mqtt_topic_keypad_command_result, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkLock::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *))
|
void NetworkLock::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *))
|
||||||
|
|||||||
@@ -262,6 +262,13 @@ void NukiWrapper::updateKeypad()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_network->publishKeypad(entries, _maxKeypadCodeCount);
|
_network->publishKeypad(entries, _maxKeypadCodeCount);
|
||||||
|
|
||||||
|
_keypadCodeIds.clear();
|
||||||
|
_keypadCodeIds.reserve(entries.size());
|
||||||
|
for(const auto& entry : entries)
|
||||||
|
{
|
||||||
|
_keypadCodeIds.push_back(entry.codeId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,12 +365,14 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), id) != _keypadCodeIds.end();
|
||||||
NukiLock::CmdResult result = (NukiLock::CmdResult)-1;
|
NukiLock::CmdResult result = (NukiLock::CmdResult)-1;
|
||||||
|
|
||||||
if(strcmp(command, "add") == 0)
|
if(strcmp(command, "add") == 0)
|
||||||
{
|
{
|
||||||
if(name == "")
|
if(name == "")
|
||||||
{
|
{
|
||||||
|
_network->publishKeypadCommandResult("MissingParameterName");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,14 +387,25 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
|||||||
}
|
}
|
||||||
else if(strcmp(command, "delete") == 0)
|
else if(strcmp(command, "delete") == 0)
|
||||||
{
|
{
|
||||||
|
if(!idExists)
|
||||||
|
{
|
||||||
|
_network->publishKeypadCommandResult("UnknownId");
|
||||||
|
return;
|
||||||
|
}
|
||||||
result = _nukiLock.deleteKeypadEntry(id);
|
result = _nukiLock.deleteKeypadEntry(id);
|
||||||
Serial.print("Delete keypad code: "); Serial.println((int)result);
|
Serial.print("Delete keypad code: "); Serial.println((int)result);
|
||||||
updateKeypad();
|
updateKeypad();
|
||||||
}
|
}
|
||||||
if(strcmp(command, "update") == 0)
|
else if(strcmp(command, "update") == 0)
|
||||||
{
|
{
|
||||||
if(name == "")
|
if(name == "")
|
||||||
{
|
{
|
||||||
|
_network->publishKeypadCommandResult("MissingParameterName");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!idExists)
|
||||||
|
{
|
||||||
|
_network->publishKeypadCommandResult("UnknownId");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,6 +420,11 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
|||||||
Serial.print("Update keypad code: "); Serial.println((int)result);
|
Serial.print("Update keypad code: "); Serial.println((int)result);
|
||||||
updateKeypad();
|
updateKeypad();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_network->publishKeypadCommandResult("UnknownCommand");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if((int)result != -1)
|
if((int)result != -1)
|
||||||
{
|
{
|
||||||
@@ -407,9 +432,6 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
|||||||
memset(&resultStr, 0, sizeof(resultStr));
|
memset(&resultStr, 0, sizeof(resultStr));
|
||||||
NukiLock::cmdResultToString(result, resultStr);
|
NukiLock::cmdResultToString(result, resultStr);
|
||||||
_network->publishKeypadCommandResult(resultStr);
|
_network->publishKeypadCommandResult(resultStr);
|
||||||
} else
|
|
||||||
{
|
|
||||||
_network->publishKeypadCommandResult("UnknownCommand");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ private:
|
|||||||
int _intervalKeypad = 0; // seconds
|
int _intervalKeypad = 0; // seconds
|
||||||
bool _publishAuthData = false;
|
bool _publishAuthData = false;
|
||||||
bool _clearAuthData = false;
|
bool _clearAuthData = false;
|
||||||
|
std::vector<uint16_t> _keypadCodeIds;
|
||||||
|
|
||||||
NukiLock::KeyTurnerState _lastKeyTurnerState;
|
NukiLock::KeyTurnerState _lastKeyTurnerState;
|
||||||
NukiLock::KeyTurnerState _keyTurnerState;
|
NukiLock::KeyTurnerState _keyTurnerState;
|
||||||
@@ -84,6 +85,5 @@ private:
|
|||||||
unsigned long _nextBatteryReportTs = 0;
|
unsigned long _nextBatteryReportTs = 0;
|
||||||
unsigned long _nextConfigUpdateTs = 0;
|
unsigned long _nextConfigUpdateTs = 0;
|
||||||
unsigned long _nextKeypadUpdateTs = 0;
|
unsigned long _nextKeypadUpdateTs = 0;
|
||||||
unsigned long _nextPairTs = 0;
|
|
||||||
NukiLock::LockAction _nextLockAction = (NukiLock::LockAction)0xff;
|
NukiLock::LockAction _nextLockAction = (NukiLock::LockAction)0xff;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user