From 5927f7501c24527c7c73ecc6e60ebf31c9ca2862 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 11 Mar 2019 15:41:06 +0100 Subject: [PATCH] Update xdrv_12_home_assistant.ino Quick fix for #5356 --- sonoff/xdrv_12_home_assistant.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sonoff/xdrv_12_home_assistant.ino b/sonoff/xdrv_12_home_assistant.ino index adc93ae09..0304d1411 100644 --- a/sonoff/xdrv_12_home_assistant.ino +++ b/sonoff/xdrv_12_home_assistant.ino @@ -170,7 +170,8 @@ int try_snprintf_P(char *s, size_t n, const char *format, ... ) { va_list args; va_start(args, format); - int len = vsnprintf_P(NULL, 0, format, args); + char dummy[2]; + int len = vsnprintf_P(dummy, 1, format, args); if (len >= n) { AddLog_P2(LOG_LEVEL_ERROR, PSTR("ERROR: MQTT discovery failed due to too long topic or friendly name. " "Please shorten topic and friendly name. Failed to format(%u/%u):"), len, n); @@ -232,6 +233,7 @@ void HAssAnnounceRelayLight(void) Shorten(&command_topic, prefix); Shorten(&state_topic, prefix); Shorten(&availability_topic, prefix); + try_snprintf_P(mqtt_data, sizeof(mqtt_data)-1, HASS_DISCOVER_RELAY, name, command_topic, state_topic, value_template, Settings.state_text[0], Settings.state_text[1], availability_topic); try_snprintf_P(mqtt_data, sizeof(mqtt_data)-1, HASS_DISCOVER_DEVICE_INFO_SHORT, mqtt_data,