Merge branch 'master' into separate-config

This commit is contained in:
iranl
2024-04-25 16:58:32 +02:00
committed by GitHub
23 changed files with 935 additions and 1676 deletions

View File

@@ -75,6 +75,12 @@ void NetworkLock::initialize()
_network->initTopic(_mqttPath, mqtt_topic_keypad_json_action, "--");
}
if(_preferences->getBool(preference_timecontrol_control_enabled))
{
_network->subscribe(_mqttPath, mqtt_topic_timecontrol_action);
_network->initTopic(_mqttPath, mqtt_topic_timecontrol_action, "--");
}
_network->addReconnectedCallback([&]()
{
_reconnected = true;
@@ -210,6 +216,18 @@ void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const uns
publishString(mqtt_topic_keypad_json_action, "--");
}
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
{
if(strcmp(value, "") == 0 || strcmp(value, "--") == 0) return;
if(_timeControlCommandReceivedReceivedCallback != NULL)
{
_timeControlCommandReceivedReceivedCallback(value);
}
publishString(mqtt_topic_timecontrol_action, "--");
}
}
void NetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurnerState, const NukiLock::KeyTurnerState& lastKeyTurnerState)
@@ -692,6 +710,78 @@ void NetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries,
}
}
void NetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEntry>& timeControlEntries)
{
char str[50];
JsonDocument json;
for(const auto& entry : timeControlEntries)
{
auto jsonEntry = json.add();
jsonEntry["entryId"] = entry.entryId;
jsonEntry["enabled"] = entry.enabled;
uint8_t weekdaysInt = entry.weekdays;
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
while(weekdaysInt > 0) {
if(weekdaysInt >= 64)
{
weekdays.add("mon");
weekdaysInt -= 64;
continue;
}
if(weekdaysInt >= 32)
{
weekdays.add("tue");
weekdaysInt -= 32;
continue;
}
if(weekdaysInt >= 16)
{
weekdays.add("wed");
weekdaysInt -= 16;
continue;
}
if(weekdaysInt >= 8)
{
weekdays.add("thu");
weekdaysInt -= 8;
continue;
}
if(weekdaysInt >= 4)
{
weekdays.add("fri");
weekdaysInt -= 4;
continue;
}
if(weekdaysInt >= 2)
{
weekdays.add("sat");
weekdaysInt -= 2;
continue;
}
if(weekdaysInt >= 1)
{
weekdays.add("sun");
weekdaysInt -= 1;
continue;
}
}
char timeT[5];
sprintf(timeT, "%02d:%02d", entry.timeHour, entry.timeMin);
jsonEntry["time"] = timeT;
memset(str, 0, sizeof(str));
NukiLock::lockactionToString(entry.lockAction, str);
jsonEntry["lockAction"] = str;
}
serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_timecontrol_json, _buffer);
}
void NetworkLock::publishConfigCommandResult(const char* result)
{
publishString(mqtt_topic_config_action_command_result, result);
@@ -707,6 +797,11 @@ void NetworkLock::publishKeypadJsonCommandResult(const char* result)
publishString(mqtt_topic_keypad_json_command_result, result);
}
void NetworkLock::publishTimeControlCommandResult(const char* result)
{
publishString(mqtt_topic_timecontrol_command_result, result);
}
void NetworkLock::setLockActionReceivedCallback(LockActionResult (*lockActionReceivedCallback)(const char *))
{
_lockActionReceivedCallback = lockActionReceivedCallback;
@@ -727,6 +822,11 @@ void NetworkLock::setKeypadJsonCommandReceivedCallback(void (*keypadJsonCommandR
_keypadJsonCommandReceivedReceivedCallback = keypadJsonCommandReceivedReceivedCallback;
}
void NetworkLock::setTimeControlCommandReceivedCallback(void (*timeControlCommandReceivedReceivedCallback)(const char *))
{
_timeControlCommandReceivedReceivedCallback = timeControlCommandReceivedReceivedCallback;
}
void NetworkLock::buildMqttPath(const char* path, char* outPath)
{
int offset = 0;