11 #if SUPPORT_HA_DISCOVERY
39 size_t HATrigger::getDiscoveryJson (
char* buffer,
size_t buflen,
const char* nodeName,
const char* networkName, DynamicJsonDocument* inputJSON) {
41 DynamicJsonDocument outputJSON (1024);
47 if (!nodeName || !networkName || !inputJSON || !buffer) {
48 DEBUG_WARN (
"Whrong parameters");
52 outputJSON[
"automation_type"] =
"trigger";
53 outputJSON[
"topic"] = String (networkName) +
"/" + String (nodeName) +
"/data";
56 outputJSON[
"payload"] = (*inputJSON)[
ha_payload].as<String> ();
58 if (inputJSON->containsKey (
ha_type)) {
59 if ((*inputJSON)[
ha_type].is<
int> ()) {
61 outputJSON[
"type"] = type;
63 type = (*inputJSON)[
ha_type].as<String>();
64 outputJSON[
"type"] = type;
70 outputJSON[
"subtype"] = subtype;
72 subtype = (*inputJSON)[
ha_subtype].as<String> ();
73 outputJSON[
"subtype"] = subtype;
77 JsonObject device = outputJSON.createNestedObject (
"device");
78 device[
"name"] = String (nodeName) + (type !=
"" ? (
"_" + type) :
"") + (subtype !=
"" ? (
"_" + subtype) :
"");
79 device[
"identifiers"] = device[
"name"];
81 size_t jsonLen = measureJson (outputJSON);
83 if (jsonLen > buflen) {
84 DEBUG_WARN (
"Too small buffer. Required %u Has %u", jsonLen, buflen);
89 serializeJson (outputJSON, buffer, buflen);
94 #endif // SUPPORT_HA_DISCOVERY