Merge branch 'gpio' of github.com:technyon/nuki_hub into gpio

This commit is contained in:
technyon
2023-06-03 21:20:33 +02:00
24 changed files with 338 additions and 108 deletions

View File

@@ -7,15 +7,20 @@
#include <NukiLockUtils.h>
NukiWrapper* nukiInst;
AccessLevel NukiWrapper::_accessLevel = AccessLevel::ReadOnly;
NukiWrapper::NukiWrapper(const std::string& deviceName, uint32_t id, BleScanner::Scanner* scanner, NetworkLock* network, Gpio* gpio, Preferences* preferences)
NukiWrapper::NukiWrapper(const std::string& deviceName, NukiDeviceId* deviceId, BleScanner::Scanner* scanner, NetworkLock* network, Gpio* gpio, Preferences* preferences)
: _deviceName(deviceName),
_deviceId(deviceId),
_bleScanner(scanner),
_nukiLock(deviceName, id),
_nukiLock(deviceName, _deviceId->get()),
_network(network),
_gpio(gpio),
_preferences(preferences)
{
Log->print("Device id lock: ");
Log->println(_deviceId->get());
nukiInst = this;
memset(&_lastKeyTurnerState, sizeof(NukiLock::KeyTurnerState), 0);
@@ -56,6 +61,7 @@ void NukiWrapper::initialize(const bool& firstStart)
_nrOfRetries = _preferences->getInt(preference_command_nr_of_retries);
_retryDelay = _preferences->getInt(preference_command_retry_delay);
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000;
_accessLevel = (AccessLevel)_preferences->getInt(preference_access_level);
if(firstStart)
{
@@ -115,7 +121,7 @@ void NukiWrapper::update()
{
if (!_paired)
{
Log->println(F("Nuki start pairing"));
Log->println(F("Nuki lock start pairing"));
_network->publishBleAddress("");
Nuki::AuthorizationIdType idType = _preferences->getBool(preference_register_as_app) ?
@@ -284,6 +290,7 @@ void NukiWrapper::setPin(const uint16_t pin)
void NukiWrapper::unpair()
{
_nukiLock.unPairNuki();
_deviceId->assignNewId();
_paired = false;
}
@@ -433,11 +440,34 @@ NukiLock::LockAction NukiWrapper::lockActionToEnum(const char *str)
return (NukiLock::LockAction)0xff;
}
bool NukiWrapper::onLockActionReceivedCallback(const char *value)
LockActionResult NukiWrapper::onLockActionReceivedCallback(const char *value)
{
NukiLock::LockAction action = nukiInst->lockActionToEnum(value);
nukiInst->_nextLockAction = action;
return (int)action != 0xff;
if((int)action == 0xff)
{
return LockActionResult::UnknownAction;
}
switch(_accessLevel)
{
case AccessLevel::Full:
nukiInst->_nextLockAction = action;
return LockActionResult::Success;
break;
case AccessLevel::LockOnly:
if(action == NukiLock::LockAction::Lock)
{
nukiInst->_nextLockAction = action;
return LockActionResult::Success;
}
return LockActionResult::AccessDenied;
break;
case AccessLevel::ReadOnly:
default:
return LockActionResult::AccessDenied;
break;
}
}
void NukiWrapper::onConfigUpdateReceivedCallback(const char *topic, const char *value)
@@ -468,6 +498,8 @@ void NukiWrapper::gpioActionCallback(const GpioAction &action, const int& pin)
void NukiWrapper::onConfigUpdateReceived(const char *topic, const char *value)
{
if(_accessLevel != AccessLevel::Full) return;
if(strcmp(topic, mqtt_topic_config_button_enabled) == 0)
{
bool newValue = atoi(value) > 0;
@@ -521,6 +553,8 @@ 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(_accessLevel != AccessLevel::Full) return;
if(!_hasKeypad)
{
if(_configRead)