disable keypad control by default; add more sanity checks
This commit is contained in:
@@ -54,16 +54,19 @@ void NetworkLock::initialize()
|
|||||||
_network->subscribe(_mqttPath, mqtt_topic_reset);
|
_network->subscribe(_mqttPath, mqtt_topic_reset);
|
||||||
_network->initTopic(_mqttPath, mqtt_topic_reset, "0");
|
_network->initTopic(_mqttPath, mqtt_topic_reset, "0");
|
||||||
|
|
||||||
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_action);
|
if(_preferences->getBool(preference_keypad_control_enabled))
|
||||||
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_id);
|
{
|
||||||
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_name);
|
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_action);
|
||||||
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_code);
|
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_id);
|
||||||
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_enabled);
|
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_name);
|
||||||
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_action, "--");
|
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_code);
|
||||||
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_id, "0");
|
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_enabled);
|
||||||
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_name, "--");
|
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_action, "--");
|
||||||
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_code, "000000");
|
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_id, "0");
|
||||||
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_enabled, "1");
|
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_name, "--");
|
||||||
|
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_code, "000000");
|
||||||
|
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_enabled, "1");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkLock::update()
|
void NetworkLock::update()
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ void NukiWrapper::updateConfig()
|
|||||||
{
|
{
|
||||||
readConfig();
|
readConfig();
|
||||||
readAdvancedConfig();
|
readAdvancedConfig();
|
||||||
|
_configRead = true;
|
||||||
_hasKeypad = _nukiConfig.hasKeypad > 0;
|
_hasKeypad = _nukiConfig.hasKeypad > 0;
|
||||||
_network->publishConfig(_nukiConfig);
|
_network->publishConfig(_nukiConfig);
|
||||||
_network->publishAdvancedConfig(_nukiAdvancedConfig);
|
_network->publishAdvancedConfig(_nukiAdvancedConfig);
|
||||||
@@ -362,7 +363,15 @@ void NukiWrapper::onConfigUpdateReceived(const char *topic, const char *value)
|
|||||||
|
|
||||||
void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, const String &name, const String &code, const int& enabled)
|
void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, const String &name, const String &code, const int& enabled)
|
||||||
{
|
{
|
||||||
if(!_hasKeypad || !_keypadEnabled)
|
if(!_hasKeypad)
|
||||||
|
{
|
||||||
|
if(_configRead)
|
||||||
|
{
|
||||||
|
_network->publishKeypadCommandResult("KeypadNotAvailable");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!_keypadEnabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -444,6 +453,10 @@ 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 if(command == "--")
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_network->publishKeypadCommandResult("UnknownCommand");
|
_network->publishKeypadCommandResult("UnknownCommand");
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ private:
|
|||||||
bool _statusUpdated = false;
|
bool _statusUpdated = false;
|
||||||
bool _hasKeypad = false;
|
bool _hasKeypad = false;
|
||||||
bool _keypadEnabled = false;
|
bool _keypadEnabled = false;
|
||||||
|
bool _configRead = false;
|
||||||
uint _maxKeypadCodeCount = 0;
|
uint _maxKeypadCodeCount = 0;
|
||||||
unsigned long _nextLockStateUpdateTs = 0;
|
unsigned long _nextLockStateUpdateTs = 0;
|
||||||
unsigned long _nextBatteryReportTs = 0;
|
unsigned long _nextBatteryReportTs = 0;
|
||||||
|
|||||||
@@ -118,7 +118,8 @@ NOTE: MQTT Discovery uses retained MQTT messages to store devices configurations
|
|||||||
## Keypad control (optional)
|
## Keypad control (optional)
|
||||||
|
|
||||||
If a keypad is connected to the lock, keypad codes can be added, updated and removed.
|
If a keypad is connected to the lock, keypad codes can be added, updated and removed.
|
||||||
Information about codes is published under "keypad/code_x", x starting from 0 up the number of configured codes.
|
This has to enabled first in the configuration portal. Check "Enabled keypad control via MQTT" and save the configuration.
|
||||||
|
After enabling keypad control, information about codes is published under "keypad/code_x", x starting from 0 up the number of configured codes.
|
||||||
<br>
|
<br>
|
||||||
For security reasons, the code itself is not published. To modify keypad codes, a command
|
For security reasons, the code itself is not published. To modify keypad codes, a command
|
||||||
structure is setup under keypad/command:
|
structure is setup under keypad/command:
|
||||||
|
|||||||
1
main.cpp
1
main.cpp
@@ -148,7 +148,6 @@ void initPreferences()
|
|||||||
{
|
{
|
||||||
preferences->putBool(preference_started_befores, true);
|
preferences->putBool(preference_started_befores, true);
|
||||||
preferences->putBool(preference_lock_enabled, true);
|
preferences->putBool(preference_lock_enabled, true);
|
||||||
preferences->putBool(preference_keypad_control_enabled, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(preferences->getInt(preference_restart_timer) == 0)
|
if(preferences->getInt(preference_restart_timer) == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user