Merge remote-tracking branch 'upstream/master' into import-config
This commit is contained in:
@@ -54,6 +54,7 @@ set(SRCFILES
|
|||||||
../src/NukiOfficial.cpp
|
../src/NukiOfficial.cpp
|
||||||
../src/NukiPublisher.cpp
|
../src/NukiPublisher.cpp
|
||||||
../src/EspMillis.h
|
../src/EspMillis.h
|
||||||
|
../src/enums/NukiPinState.h
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB_RECURSE SRCFILESREC
|
file(GLOB_RECURSE SRCFILESREC
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "RestartReason.h"
|
#include "RestartReason.h"
|
||||||
#include <NukiOpenerUtils.h>
|
#include <NukiOpenerUtils.h>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include "enums/NukiPinState.h"
|
||||||
|
#include "enums/NukiPinState.h"
|
||||||
#include "hal/wdt_hal.h"
|
#include "hal/wdt_hal.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "esp_sntp.h"
|
#include "esp_sntp.h"
|
||||||
@@ -436,7 +438,7 @@ void NukiOpenerWrapper::deactivateCM()
|
|||||||
|
|
||||||
bool NukiOpenerWrapper::isPinValid()
|
bool NukiOpenerWrapper::isPinValid()
|
||||||
{
|
{
|
||||||
return _preferences->getInt(preference_opener_pin_status, 4) == 1;
|
return _preferences->getInt(preference_opener_pin_status, (int)NukiPinState::NotConfigured) == (int)NukiPinState::Valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiOpenerWrapper::setPin(const uint16_t pin)
|
void NukiOpenerWrapper::setPin(const uint16_t pin)
|
||||||
@@ -635,7 +637,7 @@ void NukiOpenerWrapper::updateConfig()
|
|||||||
updateAuth(false);
|
updateAuth(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int pinStatus = _preferences->getInt(preference_opener_pin_status, 4);
|
const int pinStatus = _preferences->getInt(preference_opener_pin_status, (int)NukiPinState::NotConfigured);
|
||||||
|
|
||||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
@@ -659,7 +661,7 @@ void NukiOpenerWrapper::updateConfig()
|
|||||||
Log->println("Nuki opener PIN is invalid or not set");
|
Log->println("Nuki opener PIN is invalid or not set");
|
||||||
if(pinStatus != 2)
|
if(pinStatus != 2)
|
||||||
{
|
{
|
||||||
_preferences->putInt(preference_opener_pin_status, 2);
|
_preferences->putInt(preference_opener_pin_status, (int)NukiPinState::Invalid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -667,7 +669,7 @@ void NukiOpenerWrapper::updateConfig()
|
|||||||
Log->println("Nuki opener PIN is valid");
|
Log->println("Nuki opener PIN is valid");
|
||||||
if(pinStatus != 1)
|
if(pinStatus != 1)
|
||||||
{
|
{
|
||||||
_preferences->putInt(preference_opener_pin_status, 1);
|
_preferences->putInt(preference_opener_pin_status, (int)NukiPinState::Valid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4061,7 +4063,7 @@ void NukiOpenerWrapper::notify(Nuki::EventType eventType)
|
|||||||
}
|
}
|
||||||
else if(eventType == Nuki::EventType::ERROR_BAD_PIN)
|
else if(eventType == Nuki::EventType::ERROR_BAD_PIN)
|
||||||
{
|
{
|
||||||
_preferences->putInt(preference_lock_pin_status, 2);
|
_preferences->putInt(preference_lock_pin_status, (int)NukiPinState::Invalid);
|
||||||
}
|
}
|
||||||
else if(eventType == Nuki::EventType::BLE_ERROR_ON_DISCONNECT)
|
else if(eventType == Nuki::EventType::BLE_ERROR_ON_DISCONNECT)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "RestartReason.h"
|
#include "RestartReason.h"
|
||||||
#include <NukiLockUtils.h>
|
#include <NukiLockUtils.h>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include "enums/NukiPinState.h"
|
||||||
#include "hal/wdt_hal.h"
|
#include "hal/wdt_hal.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "esp_sntp.h"
|
#include "esp_sntp.h"
|
||||||
@@ -454,7 +455,7 @@ void NukiWrapper::lockngounlatch()
|
|||||||
|
|
||||||
bool NukiWrapper::isPinValid()
|
bool NukiWrapper::isPinValid()
|
||||||
{
|
{
|
||||||
return _preferences->getInt(preference_lock_pin_status, 4) == 1;
|
return _preferences->getInt(preference_lock_pin_status, (int)NukiPinState::NotConfigured) == (int)NukiPinState::Valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiWrapper::setPin(const uint16_t pin)
|
void NukiWrapper::setPin(const uint16_t pin)
|
||||||
@@ -648,7 +649,7 @@ void NukiWrapper::updateConfig()
|
|||||||
updateAuth(false);
|
updateAuth(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int pinStatus = _preferences->getInt(preference_lock_pin_status, 4);
|
const int pinStatus = _preferences->getInt(preference_lock_pin_status, (int)NukiPinState::NotConfigured);
|
||||||
|
|
||||||
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
Nuki::CmdResult result = (Nuki::CmdResult)-1;
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
@@ -671,7 +672,7 @@ void NukiWrapper::updateConfig()
|
|||||||
Log->println("Nuki Lock PIN is invalid or not set");
|
Log->println("Nuki Lock PIN is invalid or not set");
|
||||||
if(pinStatus != 2)
|
if(pinStatus != 2)
|
||||||
{
|
{
|
||||||
_preferences->putInt(preference_lock_pin_status, 2);
|
_preferences->putInt(preference_lock_pin_status, (int)NukiPinState::Invalid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -679,7 +680,7 @@ void NukiWrapper::updateConfig()
|
|||||||
Log->println("Nuki Lock PIN is valid");
|
Log->println("Nuki Lock PIN is valid");
|
||||||
if(pinStatus != 1)
|
if(pinStatus != 1)
|
||||||
{
|
{
|
||||||
_preferences->putInt(preference_lock_pin_status, 1);
|
_preferences->putInt(preference_lock_pin_status, (int)NukiPinState::Valid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4167,7 +4168,7 @@ void NukiWrapper::notify(Nuki::EventType eventType)
|
|||||||
}
|
}
|
||||||
else if(eventType == Nuki::EventType::ERROR_BAD_PIN)
|
else if(eventType == Nuki::EventType::ERROR_BAD_PIN)
|
||||||
{
|
{
|
||||||
_preferences->putInt(preference_lock_pin_status, 2);
|
_preferences->putInt(preference_lock_pin_status, (int)NukiPinState::Invalid);
|
||||||
}
|
}
|
||||||
else if(eventType == Nuki::EventType::BLE_ERROR_ON_DISCONNECT)
|
else if(eventType == Nuki::EventType::BLE_ERROR_ON_DISCONNECT)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4297,12 +4297,12 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request, PsychicResponse* resp
|
|||||||
|
|
||||||
if(_nuki->isPaired())
|
if(_nuki->isPaired())
|
||||||
{
|
{
|
||||||
String lockState = pinStateToString(_preferences->getInt(preference_lock_pin_status, 4));
|
const String lockState = pinStateToString((NukiPinState)_preferences->getInt(preference_lock_pin_status, (int)NukiPinState::NotConfigured));
|
||||||
printParameter(&response, "Nuki Lock PIN status", lockState.c_str(), "", "lockPin");
|
printParameter(&response, "Nuki Lock PIN status", lockState.c_str(), "", "lockPin");
|
||||||
|
|
||||||
if(_preferences->getBool(preference_official_hybrid_enabled, false))
|
if(_preferences->getBool(preference_official_hybrid_enabled, false))
|
||||||
{
|
{
|
||||||
String offConnected = _nuki->offConnected() ? "Yes": "No";
|
const String offConnected = _nuki->offConnected() ? "Yes": "No";
|
||||||
printParameter(&response, "Nuki Lock hybrid mode connected", offConnected.c_str(), "", "lockHybrid");
|
printParameter(&response, "Nuki Lock hybrid mode connected", offConnected.c_str(), "", "lockHybrid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4323,7 +4323,7 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request, PsychicResponse* resp
|
|||||||
}
|
}
|
||||||
if(_nukiOpener->isPaired())
|
if(_nukiOpener->isPaired())
|
||||||
{
|
{
|
||||||
String openerState = pinStateToString(_preferences->getInt(preference_opener_pin_status, 4));
|
String openerState = pinStateToString((NukiPinState)_preferences->getInt(preference_opener_pin_status, (int)NukiPinState::NotConfigured));
|
||||||
printParameter(&response, "Nuki Opener PIN status", openerState.c_str(), "", "openerPin");
|
printParameter(&response, "Nuki Opener PIN status", openerState.c_str(), "", "openerPin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4876,7 +4876,7 @@ esp_err_t WebCfgServer::buildStatusHtml(PsychicRequest *request, PsychicResponse
|
|||||||
|
|
||||||
if(_nuki->isPaired())
|
if(_nuki->isPaired())
|
||||||
{
|
{
|
||||||
json["lockPin"] = pinStateToString(_preferences->getInt(preference_lock_pin_status, 4));
|
json["lockPin"] = pinStateToString((NukiPinState)_preferences->getInt(preference_lock_pin_status, (int)NukiPinState::NotConfigured));
|
||||||
if(strcmp(lockStateArr, "undefined") != 0)
|
if(strcmp(lockStateArr, "undefined") != 0)
|
||||||
{
|
{
|
||||||
lockDone = true;
|
lockDone = true;
|
||||||
@@ -4910,7 +4910,7 @@ esp_err_t WebCfgServer::buildStatusHtml(PsychicRequest *request, PsychicResponse
|
|||||||
|
|
||||||
if(_nukiOpener->isPaired())
|
if(_nukiOpener->isPaired())
|
||||||
{
|
{
|
||||||
json["openerPin"] = pinStateToString(_preferences->getInt(preference_opener_pin_status, 4));
|
json["openerPin"] = pinStateToString((NukiPinState)_preferences->getInt(preference_opener_pin_status, (int)NukiPinState::NotConfigured));
|
||||||
if(strcmp(openerStateArr, "undefined") != 0)
|
if(strcmp(openerStateArr, "undefined") != 0)
|
||||||
{
|
{
|
||||||
openerDone = true;
|
openerDone = true;
|
||||||
@@ -4943,18 +4943,19 @@ esp_err_t WebCfgServer::buildStatusHtml(PsychicRequest *request, PsychicResponse
|
|||||||
return resp->send();
|
return resp->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
String WebCfgServer::pinStateToString(uint8_t value)
|
const String WebCfgServer::pinStateToString(const NukiPinState& value) const
|
||||||
{
|
{
|
||||||
switch(value)
|
switch(value)
|
||||||
{
|
{
|
||||||
case 0:
|
case NukiPinState::NotSet:
|
||||||
return String("PIN not set");
|
return String("PIN not set");
|
||||||
case 1:
|
case NukiPinState::Valid:
|
||||||
return String("PIN valid");
|
return String("PIN valid");
|
||||||
case 2:
|
case NukiPinState::Invalid:
|
||||||
return String("PIN invalid or not set");
|
return String("PIN set but invalid");
|
||||||
default:
|
case NukiPinState::NotConfigured:
|
||||||
return String("Unknown");
|
default:
|
||||||
|
return String("Unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6030,12 +6031,12 @@ esp_err_t WebCfgServer::processUnpair(PsychicRequest *request, PsychicResponse*
|
|||||||
if(!opener && _nuki != nullptr)
|
if(!opener && _nuki != nullptr)
|
||||||
{
|
{
|
||||||
_nuki->unpair();
|
_nuki->unpair();
|
||||||
_preferences->putInt(preference_lock_pin_status, 4);
|
_preferences->putInt(preference_lock_pin_status, (int)NukiPinState::NotConfigured);
|
||||||
}
|
}
|
||||||
if(opener && _nukiOpener != nullptr)
|
if(opener && _nukiOpener != nullptr)
|
||||||
{
|
{
|
||||||
_nukiOpener->unpair();
|
_nukiOpener->unpair();
|
||||||
_preferences->putInt(preference_opener_pin_status, 4);
|
_preferences->putInt(preference_opener_pin_status, (int)NukiPinState::NotConfigured);
|
||||||
}
|
}
|
||||||
|
|
||||||
_network->disableHASS();
|
_network->disableHASS();
|
||||||
@@ -6381,7 +6382,7 @@ const std::vector<std::pair<String, String>> WebCfgServer::getGpioOptions() cons
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
String WebCfgServer::getPreselectionForGpio(const uint8_t &pin)
|
const String WebCfgServer::getPreselectionForGpio(const uint8_t &pin) const
|
||||||
{
|
{
|
||||||
const std::vector<PinEntry>& pinConfiguration = _gpio->pinConfiguration();
|
const std::vector<PinEntry>& pinConfiguration = _gpio->pinConfiguration();
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
#include <PsychicHttp.h>
|
#include <PsychicHttp.h>
|
||||||
|
#include "enums/NukiPinState.h"
|
||||||
|
|
||||||
#ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE
|
#ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE
|
||||||
#include <PsychicHttpsServer.h>
|
#include <PsychicHttpsServer.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -85,8 +87,8 @@ private:
|
|||||||
const std::vector<std::pair<String, String>> getNetworkCustomCLKOptions() const;
|
const std::vector<std::pair<String, String>> getNetworkCustomCLKOptions() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String getPreselectionForGpio(const uint8_t& pin);
|
const String getPreselectionForGpio(const uint8_t& pin) const;
|
||||||
String pinStateToString(uint8_t value);
|
const String pinStateToString(const NukiPinState& value) const;
|
||||||
|
|
||||||
void printParameter(PsychicStreamResponse *response, const char* description, const char* value, const char *link = "", const char *id = "");
|
void printParameter(PsychicStreamResponse *response, const char* description, const char* value, const char *link = "", const char *id = "");
|
||||||
|
|
||||||
|
|||||||
9
src/enums/NukiPinState.h
Normal file
9
src/enums/NukiPinState.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum class NukiPinState
|
||||||
|
{
|
||||||
|
NotSet = 0,
|
||||||
|
Valid = 1,
|
||||||
|
Invalid = 2,
|
||||||
|
NotConfigured = 4 // default value used for preferences.getInt() when not configured by user
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user