add config entries for keypad

This commit is contained in:
technyon
2022-08-12 20:12:21 +02:00
parent fc794429a4
commit 2f2825eeed
5 changed files with 47 additions and 4 deletions

View File

@@ -41,12 +41,14 @@ void NukiWrapper::initialize()
_intervalLockstate = _preferences->getInt(preference_query_interval_lockstate);
_intervalBattery = _preferences->getInt(preference_query_interval_battery);
_intervalKeypad = _preferences->getInt(preference_query_interval_keypad);
_keypadEnabled = _preferences->getBool(preference_keypad_control_enabled);
_publishAuthData = _preferences->getBool(preference_publish_authdata);
_maxKeypadCodeCount = _preferences->getUInt(preference_max_keypad_code_count);
if(_intervalLockstate == 0)
{
_intervalLockstate = 60 * 5;
_intervalLockstate = 60 * 30;
_preferences->putInt(preference_query_interval_lockstate, _intervalLockstate);
}
if(_intervalBattery == 0)
@@ -54,6 +56,11 @@ void NukiWrapper::initialize()
_intervalBattery = 60 * 30;
_preferences->putInt(preference_query_interval_battery, _intervalBattery);
}
if(_intervalKeypad == 0)
{
_intervalKeypad = 60 * 30;
_preferences->putInt(preference_query_interval_keypad, _intervalKeypad);
}
_nukiLock.setEventHandler(this);
@@ -107,9 +114,9 @@ void NukiWrapper::update()
_nextConfigUpdateTs = ts + _intervalConfig * 1000;
updateConfig();
}
if(_hasKeypad && (_nextKeypadUpdateTs == 0 || ts > _nextKeypadUpdateTs))
if(_hasKeypad && _keypadEnabled && (_nextKeypadUpdateTs == 0 || ts > _nextKeypadUpdateTs))
{
_nextKeypadUpdateTs = ts + 60 * 60 * 1000;
_nextKeypadUpdateTs = ts + _intervalKeypad * 1000;
updateKeypad();
}
@@ -346,13 +353,18 @@ 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)
{
if(!_hasKeypad)
if(!_hasKeypad || !_keypadEnabled)
{
return;
}
if(strcmp(command, "add") == 0)
{
if(name == "")
{
return;
}
NukiLock::NewKeypadEntry entry;
memset(&entry, 0, sizeof(entry));
size_t nameLen = name.length();
@@ -370,6 +382,11 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
}
if(strcmp(command, "update") == 0)
{
if(name == "")
{
return;
}
NukiLock::UpdatedKeypadEntry entry;
memset(&entry, 0, sizeof(entry));
entry.codeId = id;
@@ -393,6 +410,11 @@ const bool NukiWrapper::isPaired()
return _paired;
}
const bool NukiWrapper::hasKeypad()
{
return _hasKeypad;
}
void NukiWrapper::notify(Nuki::EventType eventType)
{
if(eventType == Nuki::EventType::KeyTurnerStatusUpdated)

View File

@@ -26,6 +26,7 @@ public:
const NukiLock::KeyTurnerState& keyTurnerState();
const bool isPaired();
const bool hasKeypad();
void notify(Nuki::EventType eventType) override;
@@ -57,6 +58,7 @@ private:
int _intervalLockstate = 0; // seconds
int _intervalBattery = 0; // seconds
int _intervalConfig = 60 * 60; // seconds
int _intervalKeypad = 0; // seconds
bool _publishAuthData = false;
bool _clearAuthData = false;
@@ -76,6 +78,7 @@ private:
bool _paired = false;
bool _statusUpdated = false;
bool _hasKeypad = false;
bool _keypadEnabled = false;
uint _maxKeypadCodeCount = 0;
unsigned long _nextLockStateUpdateTs = 0;
unsigned long _nextBatteryReportTs = 0;

View File

@@ -21,6 +21,8 @@
#define preference_restart_timer "resttmr"
#define preference_query_interval_lockstate "lockStInterval"
#define preference_query_interval_battery "batInterval"
#define preference_query_interval_keypad "kpInterval"
#define preference_keypad_control_enabled "kpEnabled"
#define preference_cred_user "crdusr"
#define preference_cred_password "crdpass"
#define preference_publish_authdata "pubauth"

View File

@@ -286,6 +286,16 @@ bool WebCfgServer::processArgs(String& message)
_preferences->putInt(preference_query_interval_battery, value.toInt());
configChanged = true;
}
else if(key == "KPINT")
{
_preferences->putInt(preference_query_interval_keypad, value.toInt());
configChanged = true;
}
else if(key == "KPENA")
{
_preferences->putBool(preference_keypad_control_enabled, (value == "1"));
configChanged = true;
}
else if(key == "PRDTMO")
{
_preferences->putInt(preference_presence_detection_timeout, value.toInt());
@@ -589,6 +599,11 @@ void WebCfgServer::buildNukiConfigHtml(String &response)
}
printInputField(response, "LSTINT", "Query interval lock state (seconds)", _preferences->getInt(preference_query_interval_lockstate), 10);
printInputField(response, "BATINT", "Query interval battery (seconds)", _preferences->getInt(preference_query_interval_battery), 10);
if(_nuki->hasKeypad())
{
printInputField(response, "KPINT", "Query interval keypad (seconds)", _preferences->getInt(preference_query_interval_keypad), 10);
printCheckBox(response, "KPENA", "Enabled keypad control via MQTT", _preferences->getBool(preference_keypad_control_enabled));
}
printCheckBox(response, "PUBAUTH", "Publish auth data (May reduce battery life)", _preferences->getBool(preference_publish_authdata));
printCheckBox(response, "GPLCK", "Enable control via GPIO", _preferences->getBool(preference_gpio_locking_enabled));
printInputField(response, "PRDTMO", "Presence detection timeout (seconds; -1 to disable)", _preferences->getInt(preference_presence_detection_timeout), 10);

View File

@@ -148,6 +148,7 @@ void initPreferences()
{
preferences->putBool(preference_started_befores, true);
preferences->putBool(preference_lock_enabled, true);
preferences->putBool(preference_keypad_control_enabled, true);
}
if(preferences->getInt(preference_restart_timer) == 0)