diff --git a/lib/nuki_ble b/lib/nuki_ble index 84865a9..ebcd364 160000 --- a/lib/nuki_ble +++ b/lib/nuki_ble @@ -1 +1 @@ -Subproject commit 84865a9eedcdb9971a1414ea9338ad6ded13a028 +Subproject commit ebcd364046b0a0bc44dc6ef9e96c2a352f086167 diff --git a/src/Config.h b/src/Config.h index 4eb4a51..37f5d96 100644 --- a/src/Config.h +++ b/src/Config.h @@ -5,7 +5,7 @@ #define NUKI_HUB_VERSION "9.07" #define NUKI_HUB_VERSION_INT (uint32_t)907 #define NUKI_HUB_BUILD "unknownbuildnr" -#define NUKI_HUB_DATE "2025-01-04" +#define NUKI_HUB_DATE "2025-01-05" #define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest" #define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json" diff --git a/src/MqttTopics.h b/src/MqttTopics.h index 040d65a..ef8f5de 100644 --- a/src/MqttTopics.h +++ b/src/MqttTopics.h @@ -12,6 +12,7 @@ #define mqtt_topic_lock_binary_ring (char*)"/binaryRing" #define mqtt_topic_lock_trigger (char*)"/trigger" #define mqtt_topic_lock_last_lock_action (char*)"/lastLockAction" +#define mqtt_topic_lock_lock_action_context (char*)"/lockActionContext" #define mqtt_topic_lock_log (char*)"/log" #define mqtt_topic_lock_log_latest (char*)"/shortLog" #define mqtt_topic_lock_log_rolling (char*)"/rollingLog" diff --git a/src/NukiNetworkLock.cpp b/src/NukiNetworkLock.cpp index 1e091e2..5347f40 100644 --- a/src/NukiNetworkLock.cpp +++ b/src/NukiNetworkLock.cpp @@ -142,12 +142,6 @@ void NukiNetworkLock::initialize() { _network->subscribe(_mqttPath, mqtt_topic_lock_log_rolling_last); } -/* - _network->addReconnectedCallback([&]() - { - _reconnected = true; - }); -*/ } void NukiNetworkLock::update() @@ -496,7 +490,7 @@ void NukiNetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyT } json["auth_id"] = getAuthId(); - json["auth_name"] = _authName; + json["auth_name"] = getAuthName(); serializeJson(json, _buffer, _bufferSize); _nukiPublisher->publishString(mqtt_topic_lock_json, _buffer, true); @@ -697,10 +691,10 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::listpublishString(mqtt_topic_lock_log, _buffer, true); } - if(authIndex > 0) + if(authIndex > 0 || (_nukiOfficial->getOffConnected() && _nukiOfficial->hasAuthId())) { _nukiPublisher->publishUInt(mqtt_topic_lock_auth_id, getAuthId(), true); - _nukiPublisher->publishString(mqtt_topic_lock_auth_name, _authName, true); + _nukiPublisher->publishString(mqtt_topic_lock_auth_name, getAuthName(), true); } } @@ -911,6 +905,7 @@ void NukiNetworkLock::publishKeypad(const std::list& entr } jsonEntry["enabled"] = entry.enabled; jsonEntry["name"] = entry.name; + _authEntries[jsonEntry["codeId"]] = jsonEntry["name"].as(); char createdDT[20]; sprintf(createdDT, "%04d-%02d-%02d %02d:%02d:%02d", entry.dateCreatedYear, entry.dateCreatedMonth, entry.dateCreatedDay, entry.dateCreatedHour, entry.dateCreatedMin, entry.dateCreatedSec); jsonEntry["dateCreated"] = createdDT; @@ -1276,7 +1271,7 @@ void NukiNetworkLock::publishAuth(const std::list& auto jsonEntry = json.add(); jsonEntry["authId"] = entry.authId; - jsonEntry["idType"] = entry.idType; //CONSIDER INT TO STRING + jsonEntry["idType"] = entry.idType; jsonEntry["enabled"] = entry.enabled; jsonEntry["name"] = entry.name; _authEntries[jsonEntry["authId"]] = jsonEntry["name"].as(); @@ -1627,9 +1622,18 @@ void NukiNetworkLock::fobActionToString(const int fobact, char* str) const uint32_t NukiNetworkLock::getAuthId() const { - if(_nukiOfficial->hasAuthId()) + if(_nukiOfficial->getOffConnected() && _nukiOfficial->hasAuthId()) { return _nukiOfficial->getAuthId(); } return _authId; } + +const char* NukiNetworkLock::getAuthName() +{ + if(_nukiOfficial->getOffConnected() && _nukiOfficial->hasAuthId()) + { + return _authEntries[getAuthId()].c_str(); + } + return _authName; +} \ No newline at end of file diff --git a/src/NukiNetworkLock.h b/src/NukiNetworkLock.h index 2c84b42..96a136a 100644 --- a/src/NukiNetworkLock.h +++ b/src/NukiNetworkLock.h @@ -59,6 +59,7 @@ public: void setupHASS(int type, uint32_t nukiId, char* nukiName, const char* firmwareVersion, const char* hardwareVersion, bool hasDoorSensor, bool hasKeypad); const uint32_t getAuthId() const; + const char* getAuthName(); int mqttConnectionState(); uint8_t queryCommands(); diff --git a/src/NukiNetworkOpener.cpp b/src/NukiNetworkOpener.cpp index c44f492..b13a39d 100644 --- a/src/NukiNetworkOpener.cpp +++ b/src/NukiNetworkOpener.cpp @@ -116,12 +116,6 @@ void NukiNetworkOpener::initialize() { _network->subscribe(_mqttPath, mqtt_topic_lock_log_rolling_last); } -/* - _network->addReconnectedCallback([&]() - { - _reconnected = true; - }); -*/ } void NukiNetworkOpener::update() @@ -886,6 +880,7 @@ void NukiNetworkOpener::publishKeypad(const std::list& en } jsonEntry["enabled"] = entry.enabled; jsonEntry["name"] = entry.name; + _authEntries[jsonEntry["codeId"]] = jsonEntry["name"].as(); char createdDT[20]; sprintf(createdDT, "%04d-%02d-%02d %02d:%02d:%02d", entry.dateCreatedYear, entry.dateCreatedMonth, entry.dateCreatedDay, entry.dateCreatedHour, entry.dateCreatedMin, entry.dateCreatedSec); jsonEntry["dateCreated"] = createdDT; @@ -1218,7 +1213,7 @@ void NukiNetworkOpener::publishAuth(const std::list(); jsonEntry["authId"] = entry.authId; - jsonEntry["idType"] = entry.idType; //CONSIDER INT TO STRING + jsonEntry["idType"] = entry.idType; jsonEntry["enabled"] = entry.enabled; jsonEntry["name"] = entry.name; _authEntries[jsonEntry["authId"]] = jsonEntry["name"].as(); diff --git a/src/NukiOfficial.cpp b/src/NukiOfficial.cpp index d1bd966..469aded 100644 --- a/src/NukiOfficial.cpp +++ b/src/NukiOfficial.cpp @@ -6,7 +6,6 @@ #include #include - NukiOfficial::NukiOfficial(Preferences *preferences) { offEnabled = preferences->getBool(preference_official_hybrid_enabled, false); @@ -197,6 +196,7 @@ void NukiOfficial::onOfficialUpdateReceived(const char *topic, const char *value } else if(strcmp(topic, mqtt_topic_official_lockActionEvent) == 0) { + clearAuthId(); clearOffCommandExecutedTs(); offLockActionEvent = (char*)value; String LockActionEvent = offLockActionEvent; @@ -210,7 +210,7 @@ void NukiOfficial::onOfficialUpdateReceived(const char *topic, const char *value offTrigger = atoi(LockActionEvent.substring(ind1 + 1, ind2 + 1).c_str()); offAuthId = atoi(LockActionEvent.substring(ind2 + 1, ind3 + 1).c_str()); offCodeId = atoi(LockActionEvent.substring(ind3 + 1, ind4 + 1).c_str()); -// offContext = atoi(LockActionEvent.substring(ind4 + 1, ind5 + 1).c_str()); + offContext = atoi(LockActionEvent.substring(ind4 + 1, ind5 + 1).c_str()); memset(&str, 0, sizeof(str)); lockactionToString((NukiLock::LockAction)offLockAction, str); @@ -225,17 +225,69 @@ void NukiOfficial::onOfficialUpdateReceived(const char *topic, const char *value if(offCodeId > 0) { _authId = offCodeId; + + switch(offContext) + { + case 0: + _publisher->publishString(mqtt_topic_lock_lock_action_context, "keypadBackKey", true); + break; + case 1: + _publisher->publishString(mqtt_topic_lock_lock_action_context, "keypadCode", true); + break; + case 2: + _publisher->publishString(mqtt_topic_lock_lock_action_context, "keypadFingerprint", true); + break; + default: + _publisher->publishString(mqtt_topic_lock_lock_action_context, "", true); + break; + } } else { _authId = offAuthId; + + switch(offTrigger) + { + case 0: + if (offContext == 1) + { + _publisher->publishString(mqtt_topic_lock_lock_action_context, "autoUnlock", true); + } + else + { + _publisher->publishString(mqtt_topic_lock_lock_action_context, "", true); + } + break; + case 2: + if (offContext > 0) + { + _publisher->publishString(mqtt_topic_lock_lock_action_context, String("button") + String(offContext) + "press", true); + } + else + { + _publisher->publishString(mqtt_topic_lock_lock_action_context, "", true); + } + break; + case 3: + if (offContext > 0) + { + _publisher->publishString(mqtt_topic_lock_lock_action_context, String("fob") + String(offContext) + "press", true); + } + else + { + _publisher->publishString(mqtt_topic_lock_lock_action_context, "", true); + } + break; + default: + _publisher->publishString(mqtt_topic_lock_lock_action_context, "", true); + break; + } } _hasAuthId = true; - - /* - _network->_authName = RETRIEVE FROM VECTOR AFTER AUTHORIZATION ENTRIES ARE IMPLEMENTED; - _offContext = BASE ON CONTEXT OF TRIGGER AND PUBLISH TO MQTT; - */ + } + else + { + _publisher->publishString(mqtt_topic_lock_lock_action_context, "", true); } } @@ -285,6 +337,7 @@ const bool NukiOfficial::hasAuthId() const void NukiOfficial::clearAuthId() { _hasAuthId = false; + _authId = 0; } const bool NukiOfficial::getOffConnected() const @@ -317,6 +370,11 @@ const uint8_t NukiOfficial::getOffTrigger() const return offTrigger; } +const uint8_t NukiOfficial::getOffContext() const +{ + return offContext; +} + const int64_t NukiOfficial::getOffCommandExecutedTs() const { return offCommandExecutedTs; diff --git a/src/NukiOfficial.h b/src/NukiOfficial.h index 17383c3..1d8c048 100644 --- a/src/NukiOfficial.h +++ b/src/NukiOfficial.h @@ -34,6 +34,7 @@ public: const uint8_t getOffState() const; const uint8_t getOffLockAction() const; const uint8_t getOffTrigger() const; + const uint8_t getOffContext() const; const std::vector getOffTopics() const; const int64_t getOffCommandExecutedTs() const; @@ -69,7 +70,7 @@ private: uint8_t offTrigger = 0; uint32_t offAuthId = 0; uint32_t offCodeId = 0; - //uint8_t offContext = 0; + uint8_t offContext = 0; bool offEnabled = false; }; diff --git a/src/PreferencesKeys.h b/src/PreferencesKeys.h index 2996690..cfb50d6 100644 --- a/src/PreferencesKeys.h +++ b/src/PreferencesKeys.h @@ -83,7 +83,7 @@ #define preference_authlog_max_entries (char*)"authmaxentry" #define preference_keypad_max_entries (char*)"kpmaxentry" #define preference_timecontrol_max_entries (char*)"tcmaxentry" -#define preference_register_as_app (char*)"regAsApp" // true = register as hub; false = register as app +#define preference_register_as_app (char*)"regAsApp" #define preference_register_opener_as_app (char*)"regOpnAsApp" #define preference_acl (char*)"aclLckOpn" #define preference_conf_lock_basic_acl (char*)"confLckBasAcl"