MQTT JSON Keypad
This commit is contained in:
@@ -202,14 +202,14 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
|
||||
_currentLockState = keyTurnerState.lockState;
|
||||
|
||||
char str[50];
|
||||
memset(&str, 0, sizeof(str));
|
||||
memset(&str, 0, sizeof(str));
|
||||
|
||||
DynamicJsonDocument json(_bufferSize);
|
||||
|
||||
lockstateToString(keyTurnerState.lockState, str);
|
||||
|
||||
if((_firstTunerStatePublish || keyTurnerState.lockState != lastKeyTurnerState.lockState || keyTurnerState.nukiState != lastKeyTurnerState.nukiState) && keyTurnerState.lockState != NukiOpener::LockState::Undefined)
|
||||
{
|
||||
{
|
||||
if(keyTurnerState.nukiState == NukiOpener::State::ContinuousMode)
|
||||
{
|
||||
publishString(mqtt_topic_lock_state, "ContinuousMode");
|
||||
@@ -224,14 +224,14 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
|
||||
publishBinaryState(keyTurnerState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
json["lock_state"] = str;
|
||||
|
||||
|
||||
if(keyTurnerState.nukiState == NukiOpener::State::ContinuousMode)
|
||||
{
|
||||
json["continuous_mode"] = true;
|
||||
json["continuous_mode"] = 1;
|
||||
} else {
|
||||
json["continuous_mode"] = false;
|
||||
json["continuous_mode"] = 0;
|
||||
}
|
||||
|
||||
memset(&str, 0, sizeof(str));
|
||||
@@ -241,7 +241,7 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
|
||||
{
|
||||
publishString(mqtt_topic_lock_trigger, str);
|
||||
}
|
||||
|
||||
|
||||
json["trigger"] = str;
|
||||
|
||||
memset(&str, 0, sizeof(str));
|
||||
@@ -251,7 +251,7 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
|
||||
{
|
||||
publishString(mqtt_topic_lock_completionStatus, str);
|
||||
}
|
||||
|
||||
|
||||
json["lock_completion_status"] = str;
|
||||
|
||||
memset(&str, 0, sizeof(str));
|
||||
@@ -261,19 +261,17 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
|
||||
{
|
||||
publishString(mqtt_topic_lock_door_sensor_state, str);
|
||||
}
|
||||
|
||||
json["door_sensor_state"] = str;
|
||||
|
||||
bool critical = (keyTurnerState.criticalBatteryState & 0b00000001) > 0;
|
||||
json["door_sensor_state"] = str;
|
||||
|
||||
if(_firstTunerStatePublish || keyTurnerState.criticalBatteryState != lastKeyTurnerState.criticalBatteryState)
|
||||
{
|
||||
bool critical = (keyTurnerState.criticalBatteryState & 0b00000001) > 0;
|
||||
publishBool(mqtt_topic_battery_critical, critical);
|
||||
}
|
||||
|
||||
json["battery_critical"] = critical;
|
||||
json["auth_id"] = authId;
|
||||
json["auth_name"] = authName;
|
||||
json["auth_name"] = authName;
|
||||
|
||||
serializeJson(json, _buffer, _bufferSize);
|
||||
publishString(mqtt_topic_lock_json, _buffer);
|
||||
@@ -538,15 +536,35 @@ void NetworkOpener::removeHASSConfig(char* uidString)
|
||||
void NetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount)
|
||||
{
|
||||
uint index = 0;
|
||||
|
||||
DynamicJsonDocument json(_bufferSize);
|
||||
|
||||
for(const auto& entry : entries)
|
||||
{
|
||||
String basePath = mqtt_topic_keypad;
|
||||
basePath.concat("/code_");
|
||||
basePath.concat(std::to_string(index).c_str());
|
||||
publishKeypadEntry(basePath, entry);
|
||||
|
||||
auto jsonEntry = json.add();
|
||||
|
||||
jsonEntry["id"] = entry.codeId;
|
||||
jsonEntry["enabled"] = entry.enabled;
|
||||
jsonEntry["name"] = entry.name;
|
||||
jsonEntry["createdYear"] = entry.dateCreatedYear;
|
||||
jsonEntry["createdMonth"] = entry.dateCreatedMonth;
|
||||
jsonEntry["createdDay"] = entry.dateCreatedDay;
|
||||
jsonEntry["createdHour"] = entry.dateCreatedHour;
|
||||
jsonEntry["createdMin"] = entry.dateCreatedMin;
|
||||
jsonEntry["createdSec"] = entry.dateCreatedSec;
|
||||
jsonEntry["lockCount"] = entry.lockCount;
|
||||
|
||||
++index;
|
||||
}
|
||||
|
||||
serializeJson(json, _buffer, _bufferSize);
|
||||
publishString(mqtt_topic_keypad_json, _buffer);
|
||||
|
||||
while(index < maxKeypadCodeCount)
|
||||
{
|
||||
NukiLock::KeypadEntry entry;
|
||||
|
||||
Reference in New Issue
Block a user