diff --git a/library.json b/library.json index 3a1aa10..c170cb0 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", "name": "ha-mqtt", - "version": "1.11.0", + "version": "1.12.0", "description": "Home Assistant classes for integration with MQTT auto discovery", "repository": { "type": "git", diff --git a/src/ha.h b/src/ha.h index 0aff058..c07fa31 100644 --- a/src/ha.h +++ b/src/ha.h @@ -6,9 +6,10 @@ using namespace std; -#define JSON_SIZE 512 -#define TOPIC_SIZE 255 -#define BASE_TOPIC "homeassistant/%s/%s/%s" +#define JSON_SIZE 512 +#define TOPIC_SIZE 255 +#define CONFIG_TOPIC "homeassistant/%s/" MAIN_DEVICE_ID "/%s" +#define BASE_TOPIC MAIN_DEVICE_ID "/%s" namespace Ha { uint16(*publisher)(const char*, const char*); @@ -133,9 +134,9 @@ namespace Ha { void buildConfigTopic() { if (multiValueComponent && deviceClass) { - snprintf(configTopic, sizeof(configTopic), BASE_TOPIC"_%s""/config", type, MAIN_DEVICE_ID, deviceClass, id); + snprintf(configTopic, sizeof(configTopic), CONFIG_TOPIC"_%s""/config", type, deviceClass, id); } else { - snprintf(configTopic, sizeof(configTopic), BASE_TOPIC"/config", type, MAIN_DEVICE_ID, id); + snprintf(configTopic, sizeof(configTopic), CONFIG_TOPIC"/config", type, id); } } }; @@ -146,7 +147,7 @@ namespace Ha { inline static unordered_map mapCommandIds; Command(Component* cmp, onMessage f) : f(f), cmp(cmp) { - snprintf(commandTopic, sizeof(commandTopic), BASE_TOPIC"/set", cmp->type, MAIN_DEVICE_ID, cmp->id); + snprintf(commandTopic, sizeof(commandTopic), BASE_TOPIC"/set", cmp->id); mapCommandTopics.insert({ string(commandTopic), this }); mapCommandIds.insert({ string(cmp->id), this }); } @@ -179,7 +180,7 @@ namespace Ha { State(Component* cmp) : cmp(cmp) {} void withStateTopic() { - snprintf(stateTopic, sizeof(stateTopic), BASE_TOPIC"/state", cmp->type, MAIN_DEVICE_ID, cmp->id); + snprintf(stateTopic, sizeof(stateTopic), BASE_TOPIC"/state", cmp->id); } void updateState(const char* message) { diff --git a/src/mqtt.h b/src/mqtt.h index f4424c7..c8131d9 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -5,7 +5,7 @@ #include #include "esp.h" -#define MAIN_TOPIC "homeassistant/+/" MAIN_DEVICE_ID "/#" +#define MAIN_TOPIC MAIN_DEVICE_ID "/#" using namespace Ha;