re-organize state and command topics by removing component type from path
This commit is contained in:
parent
21b96b481c
commit
01c7eb8479
@ -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",
|
||||
|
||||
15
src/ha.h
15
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<string, Command*> 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) {
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#include <TaskScheduler.h>
|
||||
#include "esp.h"
|
||||
|
||||
#define MAIN_TOPIC "homeassistant/+/" MAIN_DEVICE_ID "/#"
|
||||
#define MAIN_TOPIC MAIN_DEVICE_ID "/#"
|
||||
|
||||
using namespace Ha;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user