add enum for PIN state
This commit is contained in:
@@ -54,6 +54,7 @@ set(SRCFILES
|
||||
../src/NukiOfficial.cpp
|
||||
../src/NukiPublisher.cpp
|
||||
../src/EspMillis.h
|
||||
../src/enums/NukiPinState.h
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE SRCFILESREC
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#define NUKI_HUB_VERSION "9.09"
|
||||
#define NUKI_HUB_VERSION_INT (uint32_t)909
|
||||
#define NUKI_HUB_BUILD "unknownbuildnr"
|
||||
#define NUKI_HUB_DATE "2025-01-28"
|
||||
#define NUKI_HUB_DATE "2025-02-03"
|
||||
|
||||
#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
|
||||
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "RestartReason.h"
|
||||
#include <NukiOpenerUtils.h>
|
||||
#include "Config.h"
|
||||
#include "enums/NukiPinState.h"
|
||||
#include "enums/NukiPinState.h"
|
||||
#include "hal/wdt_hal.h"
|
||||
#include <time.h>
|
||||
#include "esp_sntp.h"
|
||||
@@ -439,7 +441,7 @@ bool NukiOpenerWrapper::isPinSet()
|
||||
|
||||
bool NukiOpenerWrapper::isPinValid()
|
||||
{
|
||||
return _preferences->getInt(preference_opener_pin_status, 4) == 1;
|
||||
return _preferences->getInt(preference_opener_pin_status, (int)NukiPinState::NotConfigured) == 1;
|
||||
}
|
||||
|
||||
void NukiOpenerWrapper::setPin(const uint16_t pin)
|
||||
@@ -638,7 +640,7 @@ void NukiOpenerWrapper::updateConfig()
|
||||
updateAuth(false);
|
||||
}
|
||||
|
||||
const int pinStatus = _preferences->getInt(preference_opener_pin_status, 4);
|
||||
const int pinStatus = _preferences->getInt(preference_opener_pin_status, (int)NukiPinState::NotConfigured);
|
||||
|
||||
if(isPinSet())
|
||||
{
|
||||
@@ -665,7 +667,7 @@ void NukiOpenerWrapper::updateConfig()
|
||||
Log->println(("Nuki opener PIN is invalid"));
|
||||
if(pinStatus != 2)
|
||||
{
|
||||
_preferences->putInt(preference_opener_pin_status, 2);
|
||||
_preferences->putInt(preference_opener_pin_status, (int)NukiPinState::Invalid);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -673,7 +675,7 @@ void NukiOpenerWrapper::updateConfig()
|
||||
Log->println(("Nuki opener PIN is valid"));
|
||||
if(pinStatus != 1)
|
||||
{
|
||||
_preferences->putInt(preference_opener_pin_status, 1);
|
||||
_preferences->putInt(preference_opener_pin_status, (int)NukiPinState::Valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -682,7 +684,7 @@ void NukiOpenerWrapper::updateConfig()
|
||||
Log->println(("Nuki opener PIN is not set"));
|
||||
if(pinStatus != 0)
|
||||
{
|
||||
_preferences->putInt(preference_opener_pin_status, 0);
|
||||
_preferences->putInt(preference_opener_pin_status, (int)NukiPinState::NotSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4078,7 +4080,7 @@ void NukiOpenerWrapper::notify(Nuki::EventType eventType)
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "RestartReason.h"
|
||||
#include <NukiLockUtils.h>
|
||||
#include "Config.h"
|
||||
#include "enums/NukiPinState.h"
|
||||
#include "hal/wdt_hal.h"
|
||||
#include <time.h>
|
||||
#include "esp_sntp.h"
|
||||
@@ -464,7 +465,7 @@ bool NukiWrapper::isPinSet()
|
||||
|
||||
bool NukiWrapper::isPinValid()
|
||||
{
|
||||
return _preferences->getInt(preference_lock_pin_status, 4) == 1;
|
||||
return _preferences->getInt(preference_lock_pin_status, (int)NukiPinState::NotConfigured) == 1;
|
||||
}
|
||||
|
||||
void NukiWrapper::setPin(const uint16_t pin)
|
||||
@@ -658,7 +659,7 @@ void NukiWrapper::updateConfig()
|
||||
updateAuth(false);
|
||||
}
|
||||
|
||||
const int pinStatus = _preferences->getInt(preference_lock_pin_status, 4);
|
||||
const int pinStatus = _preferences->getInt(preference_lock_pin_status, (int)NukiPinState::NotConfigured);
|
||||
|
||||
if(isPinSet())
|
||||
{
|
||||
@@ -684,7 +685,7 @@ void NukiWrapper::updateConfig()
|
||||
Log->println(("Nuki Lock PIN is invalid"));
|
||||
if(pinStatus != 2)
|
||||
{
|
||||
_preferences->putInt(preference_lock_pin_status, 2);
|
||||
_preferences->putInt(preference_lock_pin_status, (int)NukiPinState::Invalid);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -692,7 +693,7 @@ void NukiWrapper::updateConfig()
|
||||
Log->println(("Nuki Lock PIN is valid"));
|
||||
if(pinStatus != 1)
|
||||
{
|
||||
_preferences->putInt(preference_lock_pin_status, 1);
|
||||
_preferences->putInt(preference_lock_pin_status, (int)NukiPinState::Valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -701,7 +702,7 @@ void NukiWrapper::updateConfig()
|
||||
Log->println(("Nuki Lock PIN is not set"));
|
||||
if(pinStatus != 0)
|
||||
{
|
||||
_preferences->putInt(preference_lock_pin_status, 0);
|
||||
_preferences->putInt(preference_lock_pin_status, (int)NukiPinState::NotSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4194,7 +4195,7 @@ void NukiWrapper::notify(Nuki::EventType eventType)
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -4970,12 +4970,12 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request, PsychicResponse* resp
|
||||
|
||||
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");
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -4996,7 +4996,7 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request, PsychicResponse* resp
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -5549,7 +5549,7 @@ esp_err_t WebCfgServer::buildStatusHtml(PsychicRequest *request, PsychicResponse
|
||||
|
||||
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)
|
||||
{
|
||||
lockDone = true;
|
||||
@@ -5583,7 +5583,7 @@ esp_err_t WebCfgServer::buildStatusHtml(PsychicRequest *request, PsychicResponse
|
||||
|
||||
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)
|
||||
{
|
||||
openerDone = true;
|
||||
@@ -5616,18 +5616,19 @@ esp_err_t WebCfgServer::buildStatusHtml(PsychicRequest *request, PsychicResponse
|
||||
return resp->send();
|
||||
}
|
||||
|
||||
String WebCfgServer::pinStateToString(uint8_t value)
|
||||
const String WebCfgServer::pinStateToString(const NukiPinState& value) const
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case 0:
|
||||
return String("PIN not set");
|
||||
case 1:
|
||||
return String("PIN valid");
|
||||
case 2:
|
||||
return String("PIN set but invalid");
|
||||
default:
|
||||
return String("Unknown");
|
||||
case NukiPinState::NotSet:
|
||||
return String("PIN not set");
|
||||
case NukiPinState::Valid:
|
||||
return String("PIN valid");
|
||||
case NukiPinState::Invalid:
|
||||
return String("PIN set but invalid");
|
||||
case NukiPinState::NotConfigured:
|
||||
default:
|
||||
return String("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6701,12 +6702,12 @@ esp_err_t WebCfgServer::processUnpair(PsychicRequest *request, PsychicResponse*
|
||||
if(!opener && _nuki != nullptr)
|
||||
{
|
||||
_nuki->unpair();
|
||||
_preferences->putInt(preference_lock_pin_status, 4);
|
||||
_preferences->putInt(preference_lock_pin_status, (int)NukiPinState::NotConfigured);
|
||||
}
|
||||
if(opener && _nukiOpener != nullptr)
|
||||
{
|
||||
_nukiOpener->unpair();
|
||||
_preferences->putInt(preference_opener_pin_status, 4);
|
||||
_preferences->putInt(preference_opener_pin_status, (int)NukiPinState::NotConfigured);
|
||||
}
|
||||
|
||||
_network->disableHASS();
|
||||
@@ -7052,7 +7053,7 @@ const std::vector<std::pair<String, String>> WebCfgServer::getGpioOptions() cons
|
||||
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();
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <Preferences.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include "enums/NukiPinState.h"
|
||||
|
||||
#ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE
|
||||
#include <PsychicHttpsServer.h>
|
||||
#endif
|
||||
@@ -83,8 +85,8 @@ private:
|
||||
const std::vector<std::pair<String, String>> getNetworkCustomCLKOptions() const;
|
||||
#endif
|
||||
|
||||
String getPreselectionForGpio(const uint8_t& pin);
|
||||
String pinStateToString(uint8_t value);
|
||||
const String getPreselectionForGpio(const uint8_t& pin) const;
|
||||
const String pinStateToString(const NukiPinState& value) const;
|
||||
|
||||
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