MQTT JSON Keypad
This commit is contained in:
@@ -52,6 +52,7 @@
|
|||||||
#define mqtt_topic_keypad_command_code "/keypad/command/code"
|
#define mqtt_topic_keypad_command_code "/keypad/command/code"
|
||||||
#define mqtt_topic_keypad_command_enabled "/keypad/command/enabled"
|
#define mqtt_topic_keypad_command_enabled "/keypad/command/enabled"
|
||||||
#define mqtt_topic_keypad_command_result "/keypad/command/commandResult"
|
#define mqtt_topic_keypad_command_result "/keypad/command/commandResult"
|
||||||
|
#define mqtt_topic_keypad_json "/keypad/json"
|
||||||
|
|
||||||
#define mqtt_topic_presence "/presence/devices"
|
#define mqtt_topic_presence "/presence/devices"
|
||||||
|
|
||||||
|
|||||||
@@ -268,40 +268,35 @@ void NetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurne
|
|||||||
|
|
||||||
json["door_sensor_state"] = str;
|
json["door_sensor_state"] = str;
|
||||||
|
|
||||||
bool critical = (keyTurnerState.criticalBatteryState & 0b00000001) > 0;
|
|
||||||
bool charging = (keyTurnerState.criticalBatteryState & 0b00000010) > 0;
|
|
||||||
uint8_t level = (keyTurnerState.criticalBatteryState & 0b11111100) >> 1;
|
|
||||||
|
|
||||||
if(_firstTunerStatePublish || keyTurnerState.criticalBatteryState != lastKeyTurnerState.criticalBatteryState)
|
if(_firstTunerStatePublish || keyTurnerState.criticalBatteryState != lastKeyTurnerState.criticalBatteryState)
|
||||||
{
|
{
|
||||||
|
bool critical = (keyTurnerState.criticalBatteryState & 0b00000001) > 0;
|
||||||
publishBool(mqtt_topic_battery_critical, critical);
|
publishBool(mqtt_topic_battery_critical, critical);
|
||||||
|
|
||||||
|
bool charging = (keyTurnerState.criticalBatteryState & 0b00000010) > 0;
|
||||||
publishBool(mqtt_topic_battery_charging, charging);
|
publishBool(mqtt_topic_battery_charging, charging);
|
||||||
|
|
||||||
|
uint8_t level = (keyTurnerState.criticalBatteryState & 0b11111100) >> 1;
|
||||||
publishInt(mqtt_topic_battery_level, level);
|
publishInt(mqtt_topic_battery_level, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
json["battery_critical"] = critical;
|
|
||||||
json["battery_charging"] = charging;
|
|
||||||
json["battery_level"] = level;
|
|
||||||
|
|
||||||
bool keypadBatteryCritical;
|
|
||||||
|
|
||||||
if ((keyTurnerState.accessoryBatteryState & (1 << 7)) != 0) {
|
|
||||||
keypadBatteryCritical = ((keyTurnerState.accessoryBatteryState & (1 << 6)) != 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
keypadBatteryCritical = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_firstTunerStatePublish || keyTurnerState.accessoryBatteryState != lastKeyTurnerState.accessoryBatteryState)
|
if(_firstTunerStatePublish || keyTurnerState.accessoryBatteryState != lastKeyTurnerState.accessoryBatteryState)
|
||||||
{
|
{
|
||||||
publishBool(mqtt_topic_battery_keypad_critical, keypadBatteryCritical);
|
if ((keyTurnerState.accessoryBatteryState & (1 << 7)) != 0) {
|
||||||
|
publishBool(mqtt_topic_battery_keypad_critical, (keyTurnerState.accessoryBatteryState & (1 << 6)) != 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
publishBool(mqtt_topic_battery_keypad_critical, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json["keypad_battery_critical"] = keypadBatteryCritical;
|
|
||||||
json["auth_id"] = authId;
|
json["auth_id"] = authId;
|
||||||
json["auth_name"] = authName;
|
json["auth_name"] = authName;
|
||||||
|
|
||||||
|
serializeJson(json, _buffer, _bufferSize);
|
||||||
|
publishString(mqtt_topic_lock_json, _buffer);
|
||||||
|
|
||||||
_firstTunerStatePublish = false;
|
_firstTunerStatePublish = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,6 +479,9 @@ void NetworkLock::publishBleAddress(const std::string &address)
|
|||||||
void NetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount)
|
void NetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount)
|
||||||
{
|
{
|
||||||
uint index = 0;
|
uint index = 0;
|
||||||
|
|
||||||
|
DynamicJsonDocument json(_bufferSize);
|
||||||
|
|
||||||
for(const auto& entry : entries)
|
for(const auto& entry : entries)
|
||||||
{
|
{
|
||||||
String basePath = mqtt_topic_keypad;
|
String basePath = mqtt_topic_keypad;
|
||||||
@@ -491,8 +489,25 @@ void NetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries,
|
|||||||
basePath.concat(std::to_string(index).c_str());
|
basePath.concat(std::to_string(index).c_str());
|
||||||
publishKeypadEntry(basePath, entry);
|
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;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serializeJson(json, _buffer, _bufferSize);
|
||||||
|
publishString(mqtt_topic_keypad_json, _buffer);
|
||||||
|
|
||||||
while(index < maxKeypadCodeCount)
|
while(index < maxKeypadCodeCount)
|
||||||
{
|
{
|
||||||
NukiLock::KeypadEntry entry;
|
NukiLock::KeypadEntry entry;
|
||||||
|
|||||||
@@ -229,9 +229,9 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
|
|||||||
|
|
||||||
if(keyTurnerState.nukiState == NukiOpener::State::ContinuousMode)
|
if(keyTurnerState.nukiState == NukiOpener::State::ContinuousMode)
|
||||||
{
|
{
|
||||||
json["continuous_mode"] = true;
|
json["continuous_mode"] = 1;
|
||||||
} else {
|
} else {
|
||||||
json["continuous_mode"] = false;
|
json["continuous_mode"] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&str, 0, sizeof(str));
|
memset(&str, 0, sizeof(str));
|
||||||
@@ -264,14 +264,12 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
|
|||||||
|
|
||||||
json["door_sensor_state"] = str;
|
json["door_sensor_state"] = str;
|
||||||
|
|
||||||
bool critical = (keyTurnerState.criticalBatteryState & 0b00000001) > 0;
|
|
||||||
|
|
||||||
if(_firstTunerStatePublish || keyTurnerState.criticalBatteryState != lastKeyTurnerState.criticalBatteryState)
|
if(_firstTunerStatePublish || keyTurnerState.criticalBatteryState != lastKeyTurnerState.criticalBatteryState)
|
||||||
{
|
{
|
||||||
|
bool critical = (keyTurnerState.criticalBatteryState & 0b00000001) > 0;
|
||||||
publishBool(mqtt_topic_battery_critical, critical);
|
publishBool(mqtt_topic_battery_critical, critical);
|
||||||
}
|
}
|
||||||
|
|
||||||
json["battery_critical"] = critical;
|
|
||||||
json["auth_id"] = authId;
|
json["auth_id"] = authId;
|
||||||
json["auth_name"] = authName;
|
json["auth_name"] = authName;
|
||||||
|
|
||||||
@@ -538,6 +536,9 @@ void NetworkOpener::removeHASSConfig(char* uidString)
|
|||||||
void NetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount)
|
void NetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount)
|
||||||
{
|
{
|
||||||
uint index = 0;
|
uint index = 0;
|
||||||
|
|
||||||
|
DynamicJsonDocument json(_bufferSize);
|
||||||
|
|
||||||
for(const auto& entry : entries)
|
for(const auto& entry : entries)
|
||||||
{
|
{
|
||||||
String basePath = mqtt_topic_keypad;
|
String basePath = mqtt_topic_keypad;
|
||||||
@@ -545,8 +546,25 @@ void NetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& entrie
|
|||||||
basePath.concat(std::to_string(index).c_str());
|
basePath.concat(std::to_string(index).c_str());
|
||||||
publishKeypadEntry(basePath, entry);
|
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;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serializeJson(json, _buffer, _bufferSize);
|
||||||
|
publishString(mqtt_topic_keypad_json, _buffer);
|
||||||
|
|
||||||
while(index < maxKeypadCodeCount)
|
while(index < maxKeypadCodeCount)
|
||||||
{
|
{
|
||||||
NukiLock::KeypadEntry entry;
|
NukiLock::KeypadEntry entry;
|
||||||
|
|||||||
Reference in New Issue
Block a user