Merge branch 'master' into separate-config

This commit is contained in:
iranl
2024-05-04 21:04:00 +02:00
committed by GitHub
4 changed files with 44 additions and 32 deletions

View File

@@ -13,8 +13,9 @@ NetworkLock::NetworkLock(Network* network, Preferences* preferences, char* buffe
_buffer(buffer), _buffer(buffer),
_bufferSize(bufferSize) _bufferSize(bufferSize)
{ {
memset(_authName, 0, sizeof(_authName));
_authName[0] = '\0';
memset(authName, 0, sizeof(authName));
_network->registerMqttReceiver(this); _network->registerMqttReceiver(this);
} }
@@ -317,8 +318,8 @@ void NetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurne
} }
} }
json["auth_id"] = authId; json["auth_id"] = _authId;
json["auth_name"] = authName; json["auth_name"] = _authName;
serializeJson(json, _buffer, _bufferSize); serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_lock_json, _buffer); publishString(mqtt_topic_lock_json, _buffer);
@@ -364,8 +365,10 @@ void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>&
{ {
char str[50]; char str[50];
bool authFound = false; _authId = 0;
memset(authName, 0, sizeof(authName)); memset(_authName, 0, sizeof(_authName));
_authName[0] = '\0';
_authFound = false;
JsonDocument json; JsonDocument json;
@@ -377,18 +380,20 @@ void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>&
break; break;
} }
--i; --i;
if((log.loggingType == NukiLock::LoggingType::LockAction || log.loggingType == NukiLock::LoggingType::KeypadAction) && ! authFound) if((log.loggingType == NukiLock::LoggingType::LockAction || log.loggingType == NukiLock::LoggingType::KeypadAction) && ! _authFound)
{ {
authFound = true; _authFound = true;
authId = log.authId; _authId = log.authId;
memcpy(authName, log.name, sizeof(log.name)); int sizeName = sizeof(log.name);
memcpy(_authName, log.name, sizeName);
if(_authName[sizeName - 1] != '\0') _authName[sizeName] = '\0';
} }
auto entry = json.add(); auto entry = json.add();
entry["index"] = log.index; entry["index"] = log.index;
entry["authorizationId"] = log.authId; entry["authorizationId"] = log.authId;
entry["authorizationName"] = log.name; entry["authorizationName"] = _authName;
entry["timeYear"] = log.timeStampYear; entry["timeYear"] = log.timeStampYear;
entry["timeMonth"] = log.timeStampMonth; entry["timeMonth"] = log.timeStampMonth;
entry["timeDay"] = log.timeStampDay; entry["timeDay"] = log.timeStampDay;
@@ -454,10 +459,10 @@ void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>&
serializeJson(json, _buffer, _bufferSize); serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_lock_log, _buffer); publishString(mqtt_topic_lock_log, _buffer);
if(authFound) if(_authFound)
{ {
publishUInt(mqtt_topic_lock_auth_id, authId); publishUInt(mqtt_topic_lock_auth_id, _authId);
publishString(mqtt_topic_lock_auth_name, authName); publishString(mqtt_topic_lock_auth_name, _authName);
} }
} }

View File

@@ -91,8 +91,9 @@ private:
uint _keypadCommandId = 0; uint _keypadCommandId = 0;
int _keypadCommandEnabled = 1; int _keypadCommandEnabled = 1;
uint8_t _queryCommands = 0; uint8_t _queryCommands = 0;
uint32_t authId = 0; uint32_t _authId = 0;
char authName[33]; char _authName[33];
bool _authFound = false;
char* _buffer; char* _buffer;
size_t _bufferSize; size_t _bufferSize;

View File

@@ -12,8 +12,9 @@ NetworkOpener::NetworkOpener(Network* network, Preferences* preferences, char* b
_buffer(buffer), _buffer(buffer),
_bufferSize(bufferSize) _bufferSize(bufferSize)
{ {
memset(_authName, 0, sizeof(_authName));
_authName[0] = '\0';
memset(authName, 0, sizeof(authName));
_network->registerMqttReceiver(this); _network->registerMqttReceiver(this);
} }
@@ -292,8 +293,8 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
publishBool(mqtt_topic_battery_critical, critical); publishBool(mqtt_topic_battery_critical, critical);
} }
json["auth_id"] = authId; json["auth_id"] = _authId;
json["auth_name"] = authName; json["auth_name"] = _authName;
serializeJson(json, _buffer, _bufferSize); serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_lock_json, _buffer); publishString(mqtt_topic_lock_json, _buffer);
@@ -354,8 +355,10 @@ void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntr
{ {
char str[50]; char str[50];
bool authFound = false; _authId = 0;
memset(authName, 0, sizeof(authName)); memset(_authName, 0, sizeof(_authName));
_authName[0] = '\0';
_authFound = false;
JsonDocument json; JsonDocument json;
@@ -368,18 +371,20 @@ void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntr
} }
--i; --i;
if((log.loggingType == NukiOpener::LoggingType::LockAction || log.loggingType == NukiOpener::LoggingType::KeypadAction) && ! authFound) if((log.loggingType == NukiOpener::LoggingType::LockAction || log.loggingType == NukiOpener::LoggingType::KeypadAction) && ! _authFound)
{ {
authFound = true; _authFound = true;
authId = log.authId; _authId = log.authId;
memcpy(authName, log.name, sizeof(log.name)); int sizeName = sizeof(log.name);
memcpy(_authName, log.name, sizeName);
if(_authName[sizeName - 1] != '\0') _authName[sizeName] = '\0';
} }
auto entry = json.add(); auto entry = json.add();
entry["index"] = log.index; entry["index"] = log.index;
entry["authorizationId"] = log.authId; entry["authorizationId"] = log.authId;
entry["authorizationName"] = log.name; entry["authorizationName"] = _authName;
entry["timeYear"] = log.timeStampYear; entry["timeYear"] = log.timeStampYear;
entry["timeMonth"] = log.timeStampMonth; entry["timeMonth"] = log.timeStampMonth;
entry["timeDay"] = log.timeStampDay; entry["timeDay"] = log.timeStampDay;
@@ -470,10 +475,10 @@ void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntr
serializeJson(json, _buffer, _bufferSize); serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_lock_log, _buffer); publishString(mqtt_topic_lock_log, _buffer);
if(authFound) if(_authFound)
{ {
publishUInt(mqtt_topic_lock_auth_id, authId); publishUInt(mqtt_topic_lock_auth_id, _authId);
publishString(mqtt_topic_lock_auth_name, authName); publishString(mqtt_topic_lock_auth_name, _authName);
} }
} }

View File

@@ -94,8 +94,9 @@ private:
int _keypadCommandEnabled = 1; int _keypadCommandEnabled = 1;
unsigned long _resetRingStateTs = 0; unsigned long _resetRingStateTs = 0;
uint8_t _queryCommands = 0; uint8_t _queryCommands = 0;
uint32_t authId = 0; uint32_t _authId = 0;
char authName[33]; char _authName[33];
bool _authFound = false;
NukiOpener::LockState _currentLockState = NukiOpener::LockState::Undefined; NukiOpener::LockState _currentLockState = NukiOpener::LockState::Undefined;