Auth Name and Context

This commit is contained in:
iranl
2025-01-04 22:01:23 +01:00
parent 9d7cd00d2d
commit 4c8f9c65b1
9 changed files with 89 additions and 29 deletions

View File

@@ -6,7 +6,6 @@
#include <stdlib.h>
#include <ctype.h>
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;