12 #if SUPPORT_HA_DISCOVERY
85 size_t HASwitch::getDiscoveryJson (
char* buffer,
size_t buflen,
const char* nodeName,
const char* networkName, DynamicJsonDocument* inputJSON) {
87 DynamicJsonDocument outputJSON (1024);
91 if (!nodeName || !networkName || !inputJSON ) {
92 DEBUG_WARN (
"Whrong parameters");
97 outputJSON[
"name"] = String (nodeName) +
"_" + (*inputJSON)[
ha_name_sufix].as<String> ();
99 outputJSON[
"name"] = nodeName;
102 outputJSON[
"unique_id"] = String (nodeName) +
"_" + (*inputJSON)[
ha_name_sufix].as<String> ();
104 outputJSON[
"unique_id"] = nodeName;
106 outputJSON[
"command_topic"] = String (networkName) +
"/" + String (nodeName) +
"/set/data";
113 outputJSON[
"state_topic"] = String (networkName) +
"/" + String (nodeName) +
"/data";
115 outputJSON[
"state_on"] = (*inputJSON)[
ha_state_on];
121 outputJSON[
"value_template"] = String (
"{{value_json.") + (*inputJSON)[
ha_value_key].as<String> () + String (
"}}");
124 outputJSON[
"json_attributes_topic"] = String (networkName) +
"/" + String (nodeName) +
"/data";
125 outputJSON[
"json_attributes_template"] =
"{{value_json | tojson}}";
128 size_t jsonLen = measureJson (outputJSON);
130 if (jsonLen > buflen) {
131 DEBUG_WARN (
"Too small buffer. Required %u Has %u", jsonLen, buflen);
136 serializeJson (outputJSON, buffer, 1024);
141 #endif // SUPPORT_HA_DISCOVERY