mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 20:46:52 +03:00
add maintopic to entity name to get a better entity ID. For some undocumented reason, HA removes the maintopic again in the name, so it looks ok :)
This commit is contained in:
@@ -26,7 +26,7 @@ extern const char* libfive_git_branch(void);
|
|||||||
std::vector<NumberPost*>* NUMBERS;
|
std::vector<NumberPost*>* NUMBERS;
|
||||||
|
|
||||||
void sendHomeAssistantDiscoveryTopic(std::string maintopic, std::string group, std::string field,
|
void sendHomeAssistantDiscoveryTopic(std::string maintopic, std::string group, std::string field,
|
||||||
std::string userFriendlyName, std::string icon, std::string unit, std::string deviceClass, std::string stateClass) {
|
std::string name, std::string icon, std::string unit, std::string deviceClass, std::string stateClass) {
|
||||||
std::string version = std::string(libfive_git_version());
|
std::string version = std::string(libfive_git_version());
|
||||||
|
|
||||||
if (version == "") {
|
if (version == "") {
|
||||||
@@ -38,30 +38,29 @@ void sendHomeAssistantDiscoveryTopic(std::string maintopic, std::string group, s
|
|||||||
std::string topicT;
|
std::string topicT;
|
||||||
std::string payload;
|
std::string payload;
|
||||||
std::string nl = "\n";
|
std::string nl = "\n";
|
||||||
std::string name;
|
|
||||||
|
|
||||||
if (group != "") {
|
if (group == "") {
|
||||||
topic = group + "/" + field;
|
|
||||||
topicT = group + "_" + field;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
topic = field;
|
topic = field;
|
||||||
topicT = field;
|
topicT = field;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
name = field;
|
topic = group + "/" + field;
|
||||||
if (group != "") {
|
topicT = group + "_" + field;
|
||||||
name = group + " " + name;
|
|
||||||
userFriendlyName = group + " " + userFriendlyName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The name is used as Friendly Name but also to generate the Entity ID! */
|
||||||
|
if (group != "") { // Prepend the group to the name
|
||||||
|
name = group + " " + name;
|
||||||
|
}
|
||||||
|
name = maintopic + " " + name; // Prepend device name to make the entities unique
|
||||||
|
|
||||||
topicFull = "homeassistant/sensor/" + maintopic + "/" + topicT + "/config";
|
topicFull = "homeassistant/sensor/" + maintopic + "/" + topicT + "/config";
|
||||||
|
|
||||||
/* See https://www.home-assistant.io/docs/mqtt/discovery/ */
|
/* See https://www.home-assistant.io/docs/mqtt/discovery/ */
|
||||||
payload = "{" + nl +
|
payload = "{" + nl +
|
||||||
"\"~\": \"" + maintopic + "\"," + nl +
|
"\"~\": \"" + maintopic + "\"," + nl +
|
||||||
"\"unique_id\": \"" + maintopic + "-" +topicT + "\"," + nl +
|
"\"unique_id\": \"" + maintopic + "-" + topicT + "\"," + nl +
|
||||||
"\"name\": \"" + userFriendlyName + "\"," + nl +
|
"\"name\": \"" + name + "\"," + nl +
|
||||||
"\"icon\": \"mdi:" + icon + "\"," + nl;
|
"\"icon\": \"mdi:" + icon + "\"," + nl;
|
||||||
|
|
||||||
if (group != "") {
|
if (group != "") {
|
||||||
|
|||||||
Reference in New Issue
Block a user