apply astylerc
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include "MqttTopics.h"
|
||||
|
||||
HomeAssistantDiscovery::HomeAssistantDiscovery(NetworkDevice* device, Preferences *preferences, char* buffer, size_t bufferSize)
|
||||
: _device(device),
|
||||
: _device(device),
|
||||
_preferences(preferences),
|
||||
_buffer(buffer),
|
||||
_bufferSize(bufferSize)
|
||||
|
||||
@@ -199,7 +199,10 @@ bool NukiNetwork::wifiConnected()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else return _device->isConnected();
|
||||
else
|
||||
{
|
||||
return _device->isConnected();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NUKI_HUB_UPDATER
|
||||
@@ -376,7 +379,8 @@ bool NukiNetwork::update()
|
||||
{
|
||||
_mqttConnectCounter = 0;
|
||||
|
||||
if(_firstDisconnected) {
|
||||
if(_firstDisconnected)
|
||||
{
|
||||
_firstDisconnected = false;
|
||||
_device->mqttDisconnect(true);
|
||||
}
|
||||
@@ -421,7 +425,10 @@ bool NukiNetwork::update()
|
||||
delay(200);
|
||||
restartEsp(RestartReason::ReconfigureWebServer);
|
||||
}
|
||||
else if(!_webEnabled) forceEnableWebServer = false;
|
||||
else if(!_webEnabled)
|
||||
{
|
||||
forceEnableWebServer = false;
|
||||
}
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
@@ -429,7 +436,10 @@ bool NukiNetwork::update()
|
||||
{
|
||||
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 ...");
|
||||
delay(200);
|
||||
restartEsp(RestartReason::NetworkTimeoutWatchdog);
|
||||
@@ -630,7 +640,8 @@ bool NukiNetwork::reconnect()
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
if(_mqttConnectedTs == -1 || (millis() - _mqttConnectedTs < 2000)) return;
|
||||
if(_mqttConnectedTs == -1 || (millis() - _mqttConnectedTs < 2000))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
parseGpioTopics(properties, topic, payload, len, index, total);
|
||||
|
||||
|
||||
@@ -2666,7 +2666,8 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
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))
|
||||
{
|
||||
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
|
||||
@@ -2720,7 +2721,8 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
|
||||
while(retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
if(strcmp(action, "delete") == 0) {
|
||||
if(strcmp(action, "delete") == 0)
|
||||
{
|
||||
if(idExists)
|
||||
{
|
||||
result = _nukiOpener.deleteKeypadEntry(codeId);
|
||||
@@ -2857,13 +2859,34 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
}
|
||||
}
|
||||
|
||||
if(allowedWeekdays.indexOf("mon") >= 0) allowedWeekdaysInt += 64;
|
||||
if(allowedWeekdays.indexOf("tue") >= 0) 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(allowedWeekdays.indexOf("mon") >= 0)
|
||||
{
|
||||
allowedWeekdaysInt += 64;
|
||||
}
|
||||
if(allowedWeekdays.indexOf("tue") >= 0)
|
||||
{
|
||||
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)
|
||||
@@ -2938,17 +2961,32 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
|
||||
for(const auto& entry : entries)
|
||||
{
|
||||
if (codeId != entry.codeId) continue;
|
||||
else foundExisting = true;
|
||||
if (codeId != entry.codeId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
foundExisting = true;
|
||||
}
|
||||
|
||||
if(name.length() < 1)
|
||||
{
|
||||
memset(oldName, 0, sizeof(oldName));
|
||||
memcpy(oldName, entry.name, sizeof(entry.name));
|
||||
}
|
||||
if(code == 12) code = entry.code;
|
||||
if(enabled == 2) enabled = entry.enabled;
|
||||
if(timeLimited == 2) timeLimited = entry.timeLimited;
|
||||
if(code == 12)
|
||||
{
|
||||
code = entry.code;
|
||||
}
|
||||
if(enabled == 2)
|
||||
{
|
||||
enabled = entry.enabled;
|
||||
}
|
||||
if(timeLimited == 2)
|
||||
{
|
||||
timeLimited = entry.timeLimited;
|
||||
}
|
||||
if(allowedFrom.length() < 1)
|
||||
{
|
||||
allowedFrom = "old";
|
||||
@@ -2969,7 +3007,10 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
allowedUntilAr[4] = entry.allowedUntilMin;
|
||||
allowedUntilAr[5] = entry.allowedUntilSec;
|
||||
}
|
||||
if(allowedWeekdays.length() < 1) allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
if(allowedWeekdays.length() < 1)
|
||||
{
|
||||
allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
}
|
||||
if(allowedFromTime.length() < 1)
|
||||
{
|
||||
allowedFromTime = "old";
|
||||
@@ -3068,10 +3109,14 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
return;
|
||||
}
|
||||
|
||||
if(result != Nuki::CmdResult::Success) {
|
||||
if(result != Nuki::CmdResult::Success)
|
||||
{
|
||||
++retryCount;
|
||||
}
|
||||
else break;
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
updateKeypad(false);
|
||||
|
||||
@@ -2710,7 +2710,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
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))
|
||||
{
|
||||
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
|
||||
@@ -2765,7 +2766,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
|
||||
while(retryCount < _nrOfRetries + 1)
|
||||
{
|
||||
if(strcmp(action, "delete") == 0) {
|
||||
if(strcmp(action, "delete") == 0)
|
||||
{
|
||||
if(idExists)
|
||||
{
|
||||
result = _nukiLock.deleteKeypadEntry(codeId);
|
||||
@@ -2902,13 +2904,34 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
}
|
||||
}
|
||||
|
||||
if(allowedWeekdays.indexOf("mon") >= 0) allowedWeekdaysInt += 64;
|
||||
if(allowedWeekdays.indexOf("tue") >= 0) 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(allowedWeekdays.indexOf("mon") >= 0)
|
||||
{
|
||||
allowedWeekdaysInt += 64;
|
||||
}
|
||||
if(allowedWeekdays.indexOf("tue") >= 0)
|
||||
{
|
||||
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)
|
||||
@@ -2983,17 +3006,32 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
|
||||
for(const auto& entry : entries)
|
||||
{
|
||||
if (codeId != entry.codeId) continue;
|
||||
else foundExisting = true;
|
||||
if (codeId != entry.codeId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
foundExisting = true;
|
||||
}
|
||||
|
||||
if(name.length() < 1)
|
||||
{
|
||||
memset(oldName, 0, sizeof(oldName));
|
||||
memcpy(oldName, entry.name, sizeof(entry.name));
|
||||
}
|
||||
if(code == 12) code = entry.code;
|
||||
if(enabled == 2) enabled = entry.enabled;
|
||||
if(timeLimited == 2) timeLimited = entry.timeLimited;
|
||||
if(code == 12)
|
||||
{
|
||||
code = entry.code;
|
||||
}
|
||||
if(enabled == 2)
|
||||
{
|
||||
enabled = entry.enabled;
|
||||
}
|
||||
if(timeLimited == 2)
|
||||
{
|
||||
timeLimited = entry.timeLimited;
|
||||
}
|
||||
if(allowedFrom.length() < 1)
|
||||
{
|
||||
allowedFrom = "old";
|
||||
@@ -3014,7 +3052,10 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
allowedUntilAr[4] = entry.allowedUntilMin;
|
||||
allowedUntilAr[5] = entry.allowedUntilSec;
|
||||
}
|
||||
if(allowedWeekdays.length() < 1) allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
if(allowedWeekdays.length() < 1)
|
||||
{
|
||||
allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
}
|
||||
if(allowedFromTime.length() < 1)
|
||||
{
|
||||
allowedFromTime = "old";
|
||||
@@ -3113,10 +3154,14 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
||||
return;
|
||||
}
|
||||
|
||||
if(result != Nuki::CmdResult::Success) {
|
||||
if(result != Nuki::CmdResult::Success)
|
||||
{
|
||||
++retryCount;
|
||||
}
|
||||
else break;
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
updateKeypad(false);
|
||||
|
||||
@@ -25,7 +25,8 @@ void NetworkDevice::init()
|
||||
_mqttClientSecure->setCertificate(_cert);
|
||||
_mqttClientSecure->setPrivateKey(_key);
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->println(F("MQTT without TLS."));
|
||||
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
|
||||
@@ -35,9 +36,18 @@ void NetworkDevice::init()
|
||||
{
|
||||
MqttLoggerMode mode;
|
||||
|
||||
if(_preferences->getBool(preference_mqtt_log_enabled, false) && _preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::MqttAndSerialAndWeb;
|
||||
else if (_preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::SerialAndWeb;
|
||||
else mode = MqttLoggerMode::MqttAndSerial;
|
||||
if(_preferences->getBool(preference_mqtt_log_enabled, false) && _preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
mode = MqttLoggerMode::MqttAndSerialAndWeb;
|
||||
}
|
||||
else if (_preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
mode = MqttLoggerMode::SerialAndWeb;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode = MqttLoggerMode::MqttAndSerial;
|
||||
}
|
||||
|
||||
_path = new char[200];
|
||||
memset(_path, 0, sizeof(_path));
|
||||
|
||||
@@ -250,7 +250,10 @@ void WifiDevice::onConnected()
|
||||
|
||||
void WifiDevice::onDisconnected()
|
||||
{
|
||||
if (!_connected) return;
|
||||
if (!_connected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_connected = false;
|
||||
|
||||
Log->println("Wi-Fi disconnected");
|
||||
|
||||
Reference in New Issue
Block a user