Merge branch 'v1.12.0'
This commit is contained in:
commit
49a86fb559
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
|
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
|
||||||
"name": "ha-mqtt",
|
"name": "ha-mqtt",
|
||||||
"version": "1.11.0",
|
"version": "1.12.0",
|
||||||
"description": "Home Assistant classes for integration with MQTT auto discovery",
|
"description": "Home Assistant classes for integration with MQTT auto discovery",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
11
src/ha.h
11
src/ha.h
@ -8,7 +8,8 @@ using namespace std;
|
|||||||
|
|
||||||
#define JSON_SIZE 512
|
#define JSON_SIZE 512
|
||||||
#define TOPIC_SIZE 255
|
#define TOPIC_SIZE 255
|
||||||
#define BASE_TOPIC "homeassistant/%s/%s/%s"
|
#define CONFIG_TOPIC "homeassistant/%s/" MAIN_DEVICE_ID "/%s"
|
||||||
|
#define BASE_TOPIC MAIN_DEVICE_ID "/%s"
|
||||||
|
|
||||||
namespace Ha {
|
namespace Ha {
|
||||||
uint16(*publisher)(const char*, const char*);
|
uint16(*publisher)(const char*, const char*);
|
||||||
@ -133,9 +134,9 @@ namespace Ha {
|
|||||||
|
|
||||||
void buildConfigTopic() {
|
void buildConfigTopic() {
|
||||||
if (multiValueComponent && deviceClass) {
|
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 {
|
} 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;
|
inline static unordered_map<string, Command*> mapCommandIds;
|
||||||
|
|
||||||
Command(Component* cmp, onMessage f) : f(f), cmp(cmp) {
|
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 });
|
mapCommandTopics.insert({ string(commandTopic), this });
|
||||||
mapCommandIds.insert({ string(cmp->id), this });
|
mapCommandIds.insert({ string(cmp->id), this });
|
||||||
}
|
}
|
||||||
@ -179,7 +180,7 @@ namespace Ha {
|
|||||||
State(Component* cmp) : cmp(cmp) {}
|
State(Component* cmp) : cmp(cmp) {}
|
||||||
|
|
||||||
void withStateTopic() {
|
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) {
|
void updateState(const char* message) {
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include <TaskScheduler.h>
|
#include <TaskScheduler.h>
|
||||||
#include "esp.h"
|
#include "esp.h"
|
||||||
|
|
||||||
#define MAIN_TOPIC "homeassistant/+/" MAIN_DEVICE_ID "/#"
|
#define MAIN_TOPIC MAIN_DEVICE_ID "/#"
|
||||||
|
|
||||||
using namespace Ha;
|
using namespace Ha;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user