From 6258021d5585fb7d1a370494ec5ba94b5b348967 Mon Sep 17 00:00:00 2001 From: aaronk6 Date: Sun, 17 Mar 2024 22:33:54 +0000 Subject: [PATCH] Fixed multiple devices getting merged in Home Assistant --- mqtt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mqtt.c b/mqtt.c index cc85e0398..addf04f60 100644 --- a/mqtt.c +++ b/mqtt.c @@ -101,6 +101,7 @@ void on_connect(struct mosquitto *mosq, __attribute__((unused)) void *userdata, void send_autodiscovery_messages(struct mosquitto *mosq) { const char *device_name = config.service_name; const char *device_id = config.airplay_device_id ? config.airplay_device_id : config.service_name; + const char *device_id_no_colons = str_replace(device_id, ":", ""); const char *sw_version = get_version_string(); const char *model = "shairport-sync"; const char *model_friendly = "Shairport Sync"; @@ -189,9 +190,9 @@ void send_autodiscovery_messages(struct mosquitto *mosq) { bool is_binary_sensor = (strcmp(sensors[i], "active") == 0 || strcmp(sensors[i], "playing") == 0); bool is_volume_sensor = strcmp(sensors[i], "volume") == 0; - snprintf(topic, sizeof(topic), "%s/%ssensor/%s/%s_%s/config", + snprintf(topic, sizeof(topic), "%s/%ssensor/%s_%s/%s/config", autodiscovery_prefix, is_binary_sensor ? "binary_" : "", - model, device_name, sensors[i]); + model, device_id_no_colons, sensors[i]); snprintf(id_string, sizeof(id_string), "%s_%s_%s", model, device_name, sensors[i]);