apply astylerc

This commit is contained in:
technyon
2024-11-23 16:55:59 +01:00
parent a426d955a3
commit 27fa67f9b1
11 changed files with 288 additions and 171 deletions

View File

@@ -199,7 +199,10 @@ bool NukiNetwork::wifiConnected()
{ {
return true; return true;
} }
else return _device->isConnected(); else
{
return _device->isConnected();
}
} }
#ifdef NUKI_HUB_UPDATER #ifdef NUKI_HUB_UPDATER
@@ -376,7 +379,8 @@ bool NukiNetwork::update()
{ {
_mqttConnectCounter = 0; _mqttConnectCounter = 0;
if(_firstDisconnected) { if(_firstDisconnected)
{
_firstDisconnected = false; _firstDisconnected = false;
_device->mqttDisconnect(true); _device->mqttDisconnect(true);
} }
@@ -421,7 +425,10 @@ bool NukiNetwork::update()
delay(200); delay(200);
restartEsp(RestartReason::ReconfigureWebServer); restartEsp(RestartReason::ReconfigureWebServer);
} }
else if(!_webEnabled) forceEnableWebServer = false; else if(!_webEnabled)
{
forceEnableWebServer = false;
}
delay(2000); delay(2000);
} }
@@ -429,7 +436,10 @@ bool NukiNetwork::update()
{ {
if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000) && ts > 60000) if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000) && ts > 60000)
{ {
if(!_webEnabled) forceEnableWebServer = true; if(!_webEnabled)
{
forceEnableWebServer = true;
}
Log->println("Network timeout has been reached, restarting ..."); Log->println("Network timeout has been reached, restarting ...");
delay(200); delay(200);
restartEsp(RestartReason::NetworkTimeoutWatchdog); restartEsp(RestartReason::NetworkTimeoutWatchdog);
@@ -630,7 +640,8 @@ bool NukiNetwork::reconnect()
} }
else else
{ {
Log->print(F("MQTT: Connecting with user: ")); Log->println(_mqttUser); Log->print(F("MQTT: Connecting with user: "));
Log->println(_mqttUser);
_device->mqttSetCredentials(_mqttUser, _mqttPass); _device->mqttSetCredentials(_mqttUser, _mqttPass);
} }
@@ -858,7 +869,10 @@ void NukiNetwork::onMqttDataReceivedCallback(const espMqttClientTypes::MessagePr
void NukiNetwork::onMqttDataReceived(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t& len, size_t& index, size_t& total) void NukiNetwork::onMqttDataReceived(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t& len, size_t& index, size_t& total)
{ {
if(_mqttConnectedTs == -1 || (millis() - _mqttConnectedTs < 2000)) return; if(_mqttConnectedTs == -1 || (millis() - _mqttConnectedTs < 2000))
{
return;
}
parseGpioTopics(properties, topic, payload, len, index, total); parseGpioTopics(properties, topic, payload, len, index, total);

View File

@@ -2666,7 +2666,8 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end(); idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end();
} }
if(strcmp(action, "check") == 0) { if(strcmp(action, "check") == 0)
{
if(!_preferences->getBool(preference_keypad_check_code_enabled, false)) if(!_preferences->getBool(preference_keypad_check_code_enabled, false))
{ {
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled"); _network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
@@ -2720,7 +2721,8 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
while(retryCount < _nrOfRetries + 1) while(retryCount < _nrOfRetries + 1)
{ {
if(strcmp(action, "delete") == 0) { if(strcmp(action, "delete") == 0)
{
if(idExists) if(idExists)
{ {
result = _nukiOpener.deleteKeypadEntry(codeId); result = _nukiOpener.deleteKeypadEntry(codeId);
@@ -2857,13 +2859,34 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
} }
} }
if(allowedWeekdays.indexOf("mon") >= 0) allowedWeekdaysInt += 64; if(allowedWeekdays.indexOf("mon") >= 0)
if(allowedWeekdays.indexOf("tue") >= 0) allowedWeekdaysInt += 32; {
if(allowedWeekdays.indexOf("wed") >= 0) allowedWeekdaysInt += 16; allowedWeekdaysInt += 64;
if(allowedWeekdays.indexOf("thu") >= 0) allowedWeekdaysInt += 8; }
if(allowedWeekdays.indexOf("fri") >= 0) allowedWeekdaysInt += 4; if(allowedWeekdays.indexOf("tue") >= 0)
if(allowedWeekdays.indexOf("sat") >= 0) allowedWeekdaysInt += 2; {
if(allowedWeekdays.indexOf("sun") >= 0) allowedWeekdaysInt += 1; allowedWeekdaysInt += 32;
}
if(allowedWeekdays.indexOf("wed") >= 0)
{
allowedWeekdaysInt += 16;
}
if(allowedWeekdays.indexOf("thu") >= 0)
{
allowedWeekdaysInt += 8;
}
if(allowedWeekdays.indexOf("fri") >= 0)
{
allowedWeekdaysInt += 4;
}
if(allowedWeekdays.indexOf("sat") >= 0)
{
allowedWeekdaysInt += 2;
}
if(allowedWeekdays.indexOf("sun") >= 0)
{
allowedWeekdaysInt += 1;
}
} }
if(strcmp(action, "add") == 0) if(strcmp(action, "add") == 0)
@@ -2938,17 +2961,32 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
for(const auto& entry : entries) for(const auto& entry : entries)
{ {
if (codeId != entry.codeId) continue; if (codeId != entry.codeId)
else foundExisting = true; {
continue;
}
else
{
foundExisting = true;
}
if(name.length() < 1) if(name.length() < 1)
{ {
memset(oldName, 0, sizeof(oldName)); memset(oldName, 0, sizeof(oldName));
memcpy(oldName, entry.name, sizeof(entry.name)); memcpy(oldName, entry.name, sizeof(entry.name));
} }
if(code == 12) code = entry.code; if(code == 12)
if(enabled == 2) enabled = entry.enabled; {
if(timeLimited == 2) timeLimited = entry.timeLimited; code = entry.code;
}
if(enabled == 2)
{
enabled = entry.enabled;
}
if(timeLimited == 2)
{
timeLimited = entry.timeLimited;
}
if(allowedFrom.length() < 1) if(allowedFrom.length() < 1)
{ {
allowedFrom = "old"; allowedFrom = "old";
@@ -2969,7 +3007,10 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
allowedUntilAr[4] = entry.allowedUntilMin; allowedUntilAr[4] = entry.allowedUntilMin;
allowedUntilAr[5] = entry.allowedUntilSec; allowedUntilAr[5] = entry.allowedUntilSec;
} }
if(allowedWeekdays.length() < 1) allowedWeekdaysInt = entry.allowedWeekdays; if(allowedWeekdays.length() < 1)
{
allowedWeekdaysInt = entry.allowedWeekdays;
}
if(allowedFromTime.length() < 1) if(allowedFromTime.length() < 1)
{ {
allowedFromTime = "old"; allowedFromTime = "old";
@@ -3068,10 +3109,14 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
return; return;
} }
if(result != Nuki::CmdResult::Success) { if(result != Nuki::CmdResult::Success)
{
++retryCount; ++retryCount;
} }
else break; else
{
break;
}
} }
updateKeypad(false); updateKeypad(false);

View File

@@ -2710,7 +2710,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end(); idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end();
} }
if(strcmp(action, "check") == 0) { if(strcmp(action, "check") == 0)
{
if(!_preferences->getBool(preference_keypad_check_code_enabled, false)) if(!_preferences->getBool(preference_keypad_check_code_enabled, false))
{ {
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled"); _network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
@@ -2765,7 +2766,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
while(retryCount < _nrOfRetries + 1) while(retryCount < _nrOfRetries + 1)
{ {
if(strcmp(action, "delete") == 0) { if(strcmp(action, "delete") == 0)
{
if(idExists) if(idExists)
{ {
result = _nukiLock.deleteKeypadEntry(codeId); result = _nukiLock.deleteKeypadEntry(codeId);
@@ -2902,13 +2904,34 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
} }
} }
if(allowedWeekdays.indexOf("mon") >= 0) allowedWeekdaysInt += 64; if(allowedWeekdays.indexOf("mon") >= 0)
if(allowedWeekdays.indexOf("tue") >= 0) allowedWeekdaysInt += 32; {
if(allowedWeekdays.indexOf("wed") >= 0) allowedWeekdaysInt += 16; allowedWeekdaysInt += 64;
if(allowedWeekdays.indexOf("thu") >= 0) allowedWeekdaysInt += 8; }
if(allowedWeekdays.indexOf("fri") >= 0) allowedWeekdaysInt += 4; if(allowedWeekdays.indexOf("tue") >= 0)
if(allowedWeekdays.indexOf("sat") >= 0) allowedWeekdaysInt += 2; {
if(allowedWeekdays.indexOf("sun") >= 0) allowedWeekdaysInt += 1; allowedWeekdaysInt += 32;
}
if(allowedWeekdays.indexOf("wed") >= 0)
{
allowedWeekdaysInt += 16;
}
if(allowedWeekdays.indexOf("thu") >= 0)
{
allowedWeekdaysInt += 8;
}
if(allowedWeekdays.indexOf("fri") >= 0)
{
allowedWeekdaysInt += 4;
}
if(allowedWeekdays.indexOf("sat") >= 0)
{
allowedWeekdaysInt += 2;
}
if(allowedWeekdays.indexOf("sun") >= 0)
{
allowedWeekdaysInt += 1;
}
} }
if(strcmp(action, "add") == 0) if(strcmp(action, "add") == 0)
@@ -2983,17 +3006,32 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
for(const auto& entry : entries) for(const auto& entry : entries)
{ {
if (codeId != entry.codeId) continue; if (codeId != entry.codeId)
else foundExisting = true; {
continue;
}
else
{
foundExisting = true;
}
if(name.length() < 1) if(name.length() < 1)
{ {
memset(oldName, 0, sizeof(oldName)); memset(oldName, 0, sizeof(oldName));
memcpy(oldName, entry.name, sizeof(entry.name)); memcpy(oldName, entry.name, sizeof(entry.name));
} }
if(code == 12) code = entry.code; if(code == 12)
if(enabled == 2) enabled = entry.enabled; {
if(timeLimited == 2) timeLimited = entry.timeLimited; code = entry.code;
}
if(enabled == 2)
{
enabled = entry.enabled;
}
if(timeLimited == 2)
{
timeLimited = entry.timeLimited;
}
if(allowedFrom.length() < 1) if(allowedFrom.length() < 1)
{ {
allowedFrom = "old"; allowedFrom = "old";
@@ -3014,7 +3052,10 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
allowedUntilAr[4] = entry.allowedUntilMin; allowedUntilAr[4] = entry.allowedUntilMin;
allowedUntilAr[5] = entry.allowedUntilSec; allowedUntilAr[5] = entry.allowedUntilSec;
} }
if(allowedWeekdays.length() < 1) allowedWeekdaysInt = entry.allowedWeekdays; if(allowedWeekdays.length() < 1)
{
allowedWeekdaysInt = entry.allowedWeekdays;
}
if(allowedFromTime.length() < 1) if(allowedFromTime.length() < 1)
{ {
allowedFromTime = "old"; allowedFromTime = "old";
@@ -3113,10 +3154,14 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
return; return;
} }
if(result != Nuki::CmdResult::Success) { if(result != Nuki::CmdResult::Success)
{
++retryCount; ++retryCount;
} }
else break; else
{
break;
}
} }
updateKeypad(false); updateKeypad(false);

View File

@@ -25,7 +25,8 @@ void NetworkDevice::init()
_mqttClientSecure->setCertificate(_cert); _mqttClientSecure->setCertificate(_cert);
_mqttClientSecure->setPrivateKey(_key); _mqttClientSecure->setPrivateKey(_key);
} }
} else }
else
{ {
Log->println(F("MQTT without TLS.")); Log->println(F("MQTT without TLS."));
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO); _mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
@@ -35,9 +36,18 @@ void NetworkDevice::init()
{ {
MqttLoggerMode mode; MqttLoggerMode mode;
if(_preferences->getBool(preference_mqtt_log_enabled, false) && _preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::MqttAndSerialAndWeb; if(_preferences->getBool(preference_mqtt_log_enabled, false) && _preferences->getBool(preference_webserial_enabled, false))
else if (_preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::SerialAndWeb; {
else mode = MqttLoggerMode::MqttAndSerial; mode = MqttLoggerMode::MqttAndSerialAndWeb;
}
else if (_preferences->getBool(preference_webserial_enabled, false))
{
mode = MqttLoggerMode::SerialAndWeb;
}
else
{
mode = MqttLoggerMode::MqttAndSerial;
}
_path = new char[200]; _path = new char[200];
memset(_path, 0, sizeof(_path)); memset(_path, 0, sizeof(_path));

View File

@@ -250,7 +250,10 @@ void WifiDevice::onConnected()
void WifiDevice::onDisconnected() void WifiDevice::onDisconnected()
{ {
if (!_connected) return; if (!_connected)
{
return;
}
_connected = false; _connected = false;
Log->println("Wi-Fi disconnected"); Log->println("Wi-Fi disconnected");