add astylerc and apply code formatting
This commit is contained in:
@@ -15,11 +15,11 @@ extern const uint8_t x509_crt_imported_bundle_bin_start[] asm("_binary_x509_crt_
|
||||
extern const uint8_t x509_crt_imported_bundle_bin_end[] asm("_binary_x509_crt_bundle_end");
|
||||
|
||||
NukiNetworkLock::NukiNetworkLock(NukiNetwork* network, NukiOfficial* nukiOfficial, Preferences* preferences, char* buffer, size_t bufferSize)
|
||||
: _network(network),
|
||||
_nukiOfficial(nukiOfficial),
|
||||
_preferences(preferences),
|
||||
_buffer(buffer),
|
||||
_bufferSize(bufferSize)
|
||||
: _network(network),
|
||||
_nukiOfficial(nukiOfficial),
|
||||
_preferences(preferences),
|
||||
_buffer(buffer),
|
||||
_bufferSize(bufferSize)
|
||||
{
|
||||
_nukiPublisher = new NukiPublisher(network, _mqttPath);
|
||||
_nukiOfficial->setPublisher(_nukiPublisher);
|
||||
@@ -201,21 +201,26 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
JsonDocument doc;
|
||||
|
||||
NetworkClientSecure *client = new NetworkClientSecure;
|
||||
if (client) {
|
||||
if (client)
|
||||
{
|
||||
client->setCACertBundle(x509_crt_imported_bundle_bin_start, x509_crt_imported_bundle_bin_end - x509_crt_imported_bundle_bin_start);
|
||||
{
|
||||
HTTPClient https;
|
||||
https.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||
https.useHTTP10(true);
|
||||
|
||||
if (https.begin(*client, GITHUB_OTA_MANIFEST_URL)) {
|
||||
if (https.begin(*client, GITHUB_OTA_MANIFEST_URL))
|
||||
{
|
||||
int httpResponseCode = https.GET();
|
||||
|
||||
if (httpResponseCode == HTTP_CODE_OK || httpResponseCode == HTTP_CODE_MOVED_PERMANENTLY)
|
||||
{
|
||||
DeserializationError jsonError = deserializeJson(doc, https.getStream());
|
||||
|
||||
if (!jsonError) { otaManifestSuccess = true; }
|
||||
if (!jsonError)
|
||||
{
|
||||
otaManifestSuccess = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
https.end();
|
||||
@@ -296,18 +301,27 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
else if(comparePrefixedPath(topic, mqtt_topic_webserver_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 ||
|
||||
strcmp(data, "--") == 0) return;
|
||||
strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(data, "1") == 0)
|
||||
{
|
||||
if(_preferences->getBool(preference_webserver_enabled, true) || forceEnableWebServer) return;
|
||||
if(_preferences->getBool(preference_webserver_enabled, true) || forceEnableWebServer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Log->println(F("Webserver enabled, restarting."));
|
||||
_preferences->putBool(preference_webserver_enabled, true);
|
||||
|
||||
}
|
||||
else if (strcmp(data, "0") == 0)
|
||||
{
|
||||
if(!_preferences->getBool(preference_webserver_enabled, true) && !forceEnableWebServer) return;
|
||||
if(!_preferences->getBool(preference_webserver_enabled, true) && !forceEnableWebServer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Log->println(F("Webserver disabled, restarting."));
|
||||
_preferences->putBool(preference_webserver_enabled, false);
|
||||
}
|
||||
@@ -320,9 +334,15 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
else if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last))
|
||||
{
|
||||
if(strcmp(data, "") == 0 ||
|
||||
strcmp(data, "--") == 0) return;
|
||||
strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(atoi(data) > 0 && atoi(data) > _lastRollingLog) _lastRollingLog = atoi(data);
|
||||
if(atoi(data) > 0 && atoi(data) > _lastRollingLog)
|
||||
{
|
||||
_lastRollingLog = atoi(data);
|
||||
}
|
||||
}
|
||||
|
||||
if(_nukiOfficial->getOffEnabled())
|
||||
@@ -342,11 +362,14 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
if(comparePrefixedPath(topic, mqtt_topic_lock_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 ||
|
||||
strcmp(data, "--") == 0 ||
|
||||
strcmp(data, "ack") == 0 ||
|
||||
strcmp(data, "unknown_action") == 0 ||
|
||||
strcmp(data, "denied") == 0 ||
|
||||
strcmp(data, "error") == 0) return;
|
||||
strcmp(data, "--") == 0 ||
|
||||
strcmp(data, "ack") == 0 ||
|
||||
strcmp(data, "unknown_action") == 0 ||
|
||||
strcmp(data, "denied") == 0 ||
|
||||
strcmp(data, "error") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log->print(F("Lock action received: "));
|
||||
Log->println(data);
|
||||
@@ -358,18 +381,18 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
switch(lockActionResult)
|
||||
{
|
||||
case LockActionResult::Success:
|
||||
publishString(mqtt_topic_lock_action, "ack", false);
|
||||
break;
|
||||
case LockActionResult::UnknownAction:
|
||||
publishString(mqtt_topic_lock_action, "unknown_action", false);
|
||||
break;
|
||||
case LockActionResult::AccessDenied:
|
||||
publishString(mqtt_topic_lock_action, "denied", false);
|
||||
break;
|
||||
case LockActionResult::Failed:
|
||||
publishString(mqtt_topic_lock_action, "error", false);
|
||||
break;
|
||||
case LockActionResult::Success:
|
||||
publishString(mqtt_topic_lock_action, "ack", false);
|
||||
break;
|
||||
case LockActionResult::UnknownAction:
|
||||
publishString(mqtt_topic_lock_action, "unknown_action", false);
|
||||
break;
|
||||
case LockActionResult::AccessDenied:
|
||||
publishString(mqtt_topic_lock_action, "denied", false);
|
||||
break;
|
||||
case LockActionResult::Failed:
|
||||
publishString(mqtt_topic_lock_action, "error", false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,7 +402,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
{
|
||||
if(_keypadCommandReceivedReceivedCallback != nullptr)
|
||||
{
|
||||
if(strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_keypadCommandReceivedReceivedCallback(data, _keypadCommandId, _keypadCommandName, _keypadCommandCode, _keypadCommandEnabled);
|
||||
|
||||
@@ -439,7 +465,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_config_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_configUpdateReceivedCallback != NULL)
|
||||
{
|
||||
@@ -451,7 +480,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_keypad_json_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_keypadJsonCommandReceivedReceivedCallback != NULL)
|
||||
{
|
||||
@@ -463,7 +495,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_timeControlCommandReceivedReceivedCallback != NULL)
|
||||
{
|
||||
@@ -475,7 +510,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_auth_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_authCommandReceivedReceivedCallback != NULL)
|
||||
{
|
||||
@@ -633,39 +671,39 @@ void NukiNetworkLock::publishState(NukiLock::LockState lockState)
|
||||
{
|
||||
switch(lockState)
|
||||
{
|
||||
case NukiLock::LockState::Locked:
|
||||
publishString(mqtt_topic_lock_ha_state, "locked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Locking:
|
||||
publishString(mqtt_topic_lock_ha_state, "locking", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlocking:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocking", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlocked:
|
||||
case NukiLock::LockState::UnlockedLnga:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlatched:
|
||||
publishString(mqtt_topic_lock_ha_state, "open", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlatching:
|
||||
publishString(mqtt_topic_lock_ha_state, "opening", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Uncalibrated:
|
||||
case NukiLock::LockState::Calibration:
|
||||
case NukiLock::LockState::BootRun:
|
||||
case NukiLock::LockState::MotorBlocked:
|
||||
publishString(mqtt_topic_lock_ha_state, "jammed", true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case NukiLock::LockState::Locked:
|
||||
publishString(mqtt_topic_lock_ha_state, "locked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Locking:
|
||||
publishString(mqtt_topic_lock_ha_state, "locking", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlocking:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocking", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlocked:
|
||||
case NukiLock::LockState::UnlockedLnga:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlatched:
|
||||
publishString(mqtt_topic_lock_ha_state, "open", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlatching:
|
||||
publishString(mqtt_topic_lock_ha_state, "opening", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Uncalibrated:
|
||||
case NukiLock::LockState::Calibration:
|
||||
case NukiLock::LockState::BootRun:
|
||||
case NukiLock::LockState::MotorBlocked:
|
||||
publishString(mqtt_topic_lock_ha_state, "jammed", true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,7 +724,10 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
{
|
||||
int sizeName = sizeof(log.name);
|
||||
memcpy(authName, log.name, sizeName);
|
||||
if(authName[sizeName - 1] != '\0') authName[sizeName] = '\0';
|
||||
if(authName[sizeName - 1] != '\0')
|
||||
{
|
||||
authName[sizeName] = '\0';
|
||||
}
|
||||
|
||||
if(log.index > authIndex)
|
||||
{
|
||||
@@ -712,7 +753,7 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
|
||||
if(entry["authorizationName"].as<String>().length() == 0 && _authEntries.count(log.authId) > 0)
|
||||
{
|
||||
entry["authorizationName"] = _authEntries[log.authId];
|
||||
entry["authorizationName"] = _authEntries[log.authId];
|
||||
}
|
||||
|
||||
entry["timeYear"] = log.timeStampYear;
|
||||
@@ -728,69 +769,75 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
|
||||
switch(log.loggingType)
|
||||
{
|
||||
case NukiLock::LoggingType::LockAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
case NukiLock::LoggingType::LockAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::triggerToString((NukiLock::Trigger)log.data[1], str);
|
||||
entry["trigger"] = str;
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::triggerToString((NukiLock::Trigger)log.data[1], str);
|
||||
entry["trigger"] = str;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
|
||||
entry["completionStatus"] = str;
|
||||
break;
|
||||
case NukiLock::LoggingType::KeypadAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
switch(log.data[1])
|
||||
{
|
||||
case 0:
|
||||
entry["trigger"] = "arrowkey";
|
||||
break;
|
||||
case 1:
|
||||
entry["trigger"] = "code";
|
||||
break;
|
||||
case 2:
|
||||
entry["trigger"] = "fingerprint";
|
||||
break;
|
||||
default:
|
||||
entry["trigger"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
|
||||
if(log.data[2] == 9)
|
||||
{
|
||||
entry["completionStatus"] = "notAuthorized";
|
||||
}
|
||||
else if (log.data[2] == 224)
|
||||
{
|
||||
entry["completionStatus"] = "invalidCode";
|
||||
}
|
||||
else
|
||||
{
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||
entry["completionStatus"] = str;
|
||||
}
|
||||
|
||||
entry["codeId"] = 256U*log.data[4]+log.data[3];
|
||||
break;
|
||||
case NukiLock::LoggingType::DoorSensor:
|
||||
switch(log.data[0])
|
||||
{
|
||||
case 0:
|
||||
entry["action"] = "DoorOpened";
|
||||
break;
|
||||
case NukiLock::LoggingType::KeypadAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
switch(log.data[1])
|
||||
{
|
||||
case 0:
|
||||
entry["trigger"] = "arrowkey";
|
||||
break;
|
||||
case 1:
|
||||
entry["trigger"] = "code";
|
||||
break;
|
||||
case 2:
|
||||
entry["trigger"] = "fingerprint";
|
||||
break;
|
||||
default:
|
||||
entry["trigger"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
|
||||
if(log.data[2] == 9) entry["completionStatus"] = "notAuthorized";
|
||||
else if (log.data[2] == 224) entry["completionStatus"] = "invalidCode";
|
||||
else
|
||||
{
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||
entry["completionStatus"] = str;
|
||||
}
|
||||
|
||||
entry["codeId"] = 256U*log.data[4]+log.data[3];
|
||||
case 1:
|
||||
entry["action"] = "DoorClosed";
|
||||
break;
|
||||
case NukiLock::LoggingType::DoorSensor:
|
||||
switch(log.data[0])
|
||||
{
|
||||
case 0:
|
||||
entry["action"] = "DoorOpened";
|
||||
break;
|
||||
case 1:
|
||||
entry["action"] = "DoorClosed";
|
||||
break;
|
||||
case 2:
|
||||
entry["action"] = "SensorJammed";
|
||||
break;
|
||||
default:
|
||||
entry["action"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
entry["action"] = "SensorJammed";
|
||||
break;
|
||||
default:
|
||||
entry["action"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(log.index > _lastRollingLog)
|
||||
@@ -804,8 +851,14 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
|
||||
serializeJson(json, _buffer, _bufferSize);
|
||||
|
||||
if(latest) publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
||||
else publishString(mqtt_topic_lock_log, _buffer, true);
|
||||
if(latest)
|
||||
{
|
||||
publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
publishString(mqtt_topic_lock_log, _buffer, true);
|
||||
}
|
||||
|
||||
if(authIndex > 0)
|
||||
{
|
||||
@@ -1013,7 +1066,10 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
||||
|
||||
jsonEntry["codeId"] = entry.codeId;
|
||||
|
||||
if(publishCode) jsonEntry["code"] = entry.code;
|
||||
if(publishCode)
|
||||
{
|
||||
jsonEntry["code"] = entry.code;
|
||||
}
|
||||
jsonEntry["enabled"] = entry.enabled;
|
||||
jsonEntry["name"] = entry.name;
|
||||
char createdDT[20];
|
||||
@@ -1034,7 +1090,8 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||
|
||||
while(allowedWeekdaysInt > 0) {
|
||||
while(allowedWeekdaysInt > 0)
|
||||
{
|
||||
if(allowedWeekdaysInt >= 64)
|
||||
{
|
||||
weekdays.add("mon");
|
||||
@@ -1111,24 +1168,26 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
||||
std::string displayName = std::string("Keypad - ") + std::string((char*)codeName) + " - " + std::to_string(entry.codeId);
|
||||
|
||||
_network->publishHassTopic("switch",
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_keypad_json_action,
|
||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }});
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_keypad_json_action,
|
||||
{
|
||||
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }
|
||||
});
|
||||
}
|
||||
|
||||
++index;
|
||||
@@ -1202,7 +1261,10 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
||||
|
||||
void NukiNetworkLock::publishKeypadEntry(const String topic, NukiLock::KeypadEntry entry)
|
||||
{
|
||||
if(_disableNonJSON) return;
|
||||
if(_disableNonJSON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char codeName[sizeof(entry.name) + 1];
|
||||
memset(codeName, 0, sizeof(codeName));
|
||||
@@ -1245,7 +1307,8 @@ void NukiNetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEn
|
||||
uint8_t weekdaysInt = entry.weekdays;
|
||||
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
|
||||
|
||||
while(weekdaysInt > 0) {
|
||||
while(weekdaysInt > 0)
|
||||
{
|
||||
if(weekdaysInt >= 64)
|
||||
{
|
||||
weekdays.add("mon");
|
||||
@@ -1319,24 +1382,26 @@ void NukiNetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEn
|
||||
std::string displayName = std::string("Timecontrol - ") + std::to_string(entry.entryId);
|
||||
|
||||
_network->publishHassTopic("switch",
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_timecontrol_action,
|
||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }});
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_timecontrol_action,
|
||||
{
|
||||
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }
|
||||
});
|
||||
}
|
||||
|
||||
++index;
|
||||
@@ -1393,7 +1458,8 @@ void NukiNetworkLock::publishAuth(const std::list<NukiLock::AuthorizationEntry>&
|
||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||
|
||||
while(allowedWeekdaysInt > 0) {
|
||||
while(allowedWeekdaysInt > 0)
|
||||
{
|
||||
if(allowedWeekdaysInt >= 64)
|
||||
{
|
||||
weekdays.add("mon");
|
||||
@@ -1466,24 +1532,26 @@ void NukiNetworkLock::publishAuth(const std::list<NukiLock::AuthorizationEntry>&
|
||||
std::string displayName = std::string("Authorization - ") + std::to_string(entry.authId);
|
||||
|
||||
_network->publishHassTopic("switch",
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_auth_action,
|
||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }});
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_auth_action,
|
||||
{
|
||||
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }
|
||||
});
|
||||
}
|
||||
|
||||
++index;
|
||||
@@ -1510,7 +1578,10 @@ void NukiNetworkLock::publishConfigCommandResult(const char* result)
|
||||
|
||||
void NukiNetworkLock::publishKeypadCommandResult(const char* result)
|
||||
{
|
||||
if(_disableNonJSON) return;
|
||||
if(_disableNonJSON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
publishString(mqtt_topic_keypad_command_result, result, true);
|
||||
}
|
||||
|
||||
@@ -1551,7 +1622,10 @@ void NukiNetworkLock::setConfigUpdateReceivedCallback(void (*configUpdateReceive
|
||||
|
||||
void NukiNetworkLock::setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled))
|
||||
{
|
||||
if(_disableNonJSON) return;
|
||||
if(_disableNonJSON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_keypadCommandReceivedReceivedCallback = keypadCommandReceivedReceivedCallback;
|
||||
}
|
||||
|
||||
@@ -1604,7 +1678,7 @@ bool NukiNetworkLock::comparePrefixedPath(const char *fullPath, const char *subP
|
||||
}
|
||||
|
||||
void NukiNetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic, char *name, char *uidString, const char *softwareVersion, const char *hardwareVersion, const bool& hasDoorSensor, const bool& hasKeypad, const bool& publishAuthData, char *lockAction,
|
||||
char *unlockAction, char *openAction)
|
||||
char *unlockAction, char *openAction)
|
||||
{
|
||||
_network->publishHASSConfig(deviceType, baseTopic, name, uidString, softwareVersion, hardwareVersion, "~/maintenance/mqttConnectionState", hasKeypad, lockAction, unlockAction, openAction);
|
||||
_network->publishHASSConfigAdditionalLockEntities(deviceType, baseTopic, name, uidString);
|
||||
@@ -1618,9 +1692,9 @@ void NukiNetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic,
|
||||
_network->removeHASSConfigTopic((char*)"binary_sensor", (char*)"door_sensor", uidString);
|
||||
}
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
_network->publishHASSWifiRssiConfig(deviceType, baseTopic, name, uidString);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(publishAuthData)
|
||||
{
|
||||
@@ -1719,76 +1793,82 @@ uint8_t NukiNetworkLock::queryCommands()
|
||||
return qc;
|
||||
}
|
||||
|
||||
void NukiNetworkLock::buttonPressActionToString(const NukiLock::ButtonPressAction btnPressAction, char* str) {
|
||||
switch (btnPressAction) {
|
||||
void NukiNetworkLock::buttonPressActionToString(const NukiLock::ButtonPressAction btnPressAction, char* str)
|
||||
{
|
||||
switch (btnPressAction)
|
||||
{
|
||||
case NukiLock::ButtonPressAction::NoAction:
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::Intelligent:
|
||||
strcpy(str, "Intelligent");
|
||||
break;
|
||||
strcpy(str, "Intelligent");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::Unlock:
|
||||
strcpy(str, "Unlock");
|
||||
break;
|
||||
strcpy(str, "Unlock");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::Lock:
|
||||
strcpy(str, "Lock");
|
||||
break;
|
||||
strcpy(str, "Lock");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::Unlatch:
|
||||
strcpy(str, "Unlatch");
|
||||
break;
|
||||
strcpy(str, "Unlatch");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::LockNgo:
|
||||
strcpy(str, "Lock n Go");
|
||||
break;
|
||||
strcpy(str, "Lock n Go");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::ShowStatus:
|
||||
strcpy(str, "Show Status");
|
||||
break;
|
||||
strcpy(str, "Show Status");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NukiNetworkLock::homeKitStatusToString(const int hkstatus, char* str) {
|
||||
switch (hkstatus) {
|
||||
void NukiNetworkLock::homeKitStatusToString(const int hkstatus, char* str)
|
||||
{
|
||||
switch (hkstatus)
|
||||
{
|
||||
case 0:
|
||||
strcpy(str, "Not Available");
|
||||
break;
|
||||
strcpy(str, "Not Available");
|
||||
break;
|
||||
case 1:
|
||||
strcpy(str, "Disabled");
|
||||
break;
|
||||
strcpy(str, "Disabled");
|
||||
break;
|
||||
case 2:
|
||||
strcpy(str, "Enabled");
|
||||
break;
|
||||
strcpy(str, "Enabled");
|
||||
break;
|
||||
case 3:
|
||||
strcpy(str, "Enabled & Paired");
|
||||
break;
|
||||
strcpy(str, "Enabled & Paired");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NukiNetworkLock::fobActionToString(const int fobact, char* str) {
|
||||
switch (fobact) {
|
||||
void NukiNetworkLock::fobActionToString(const int fobact, char* str)
|
||||
{
|
||||
switch (fobact)
|
||||
{
|
||||
case 0:
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
case 1:
|
||||
strcpy(str, "Unlock");
|
||||
break;
|
||||
strcpy(str, "Unlock");
|
||||
break;
|
||||
case 2:
|
||||
strcpy(str, "Lock");
|
||||
break;
|
||||
strcpy(str, "Lock");
|
||||
break;
|
||||
case 3:
|
||||
strcpy(str, "Lock n Go");
|
||||
break;
|
||||
strcpy(str, "Lock n Go");
|
||||
break;
|
||||
case 4:
|
||||
strcpy(str, "Intelligent");
|
||||
break;
|
||||
strcpy(str, "Intelligent");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const uint32_t NukiNetworkLock::getAuthId() const
|
||||
|
||||
Reference in New Issue
Block a user