implement add and delete keypad code

This commit is contained in:
technyon
2022-08-12 18:29:30 +02:00
parent da1a2ebcfe
commit 9fed6c0ce8
5 changed files with 81 additions and 3 deletions

View File

@@ -53,6 +53,15 @@ void NetworkLock::initialize()
_network->subscribe(_mqttPath, mqtt_topic_reset);
_network->initTopic(_mqttPath, mqtt_topic_reset, "0");
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_action);
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_id);
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_name);
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_code);
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_action, "--");
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_id, "0");
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_name, "--");
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_code, "000000");
}
void NetworkLock::update()
@@ -98,6 +107,30 @@ void NetworkLock::onMqttDataReceived(char *&topic, byte *&payload, unsigned int
publishString(mqtt_topic_lock_action, success ? "ack" : "unknown_action");
}
if(comparePrefixedPath(topic, mqtt_topic_keypad_command_action))
{
if(_keypadCommandReceivedReceivedCallback != nullptr)
{
_keypadCommandReceivedReceivedCallback(value, _keypadCommandId, _keypadCommandName, _keypadCommandCode);
publishString(mqtt_topic_keypad_command_action, "--");
publishInt(mqtt_topic_keypad_command_id, 0);
publishString(mqtt_topic_keypad_command_name, "--");
publishString(mqtt_topic_keypad_command_code, "000000");
}
}
else if(comparePrefixedPath(topic, mqtt_topic_keypad_command_id))
{
_keypadCommandId = atoi(value);
}
else if(comparePrefixedPath(topic, mqtt_topic_keypad_command_name))
{
_keypadCommandName = value;
}
else if(comparePrefixedPath(topic, mqtt_topic_keypad_command_code))
{
_keypadCommandCode = value;
}
for(auto configTopic : _configTopics)
{
if(comparePrefixedPath(topic, configTopic))
@@ -251,6 +284,11 @@ void NetworkLock::setConfigUpdateReceivedCallback(void (*configUpdateReceivedCal
_configUpdateReceivedCallback = configUpdateReceivedCallback;
}
void NetworkLock::setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code))
{
_keypadCommandReceivedReceivedCallback = keypadCommandReceivedReceivedCallback;
}
void NetworkLock::buildMqttPath(const char* path, char* outPath)
{
int offset = 0;
@@ -349,4 +387,3 @@ String NetworkLock::concat(String a, String b)
c.concat(b);
return c;
}