detect a multi value sensor based on common id
This commit is contained in:
parent
dbedf0d2f1
commit
7327533b24
6
src/ha.h
6
src/ha.h
@ -93,6 +93,7 @@ namespace Ha {
|
||||
JsonPairs<const char*> jsonStrings;
|
||||
DeviceConfig* mainDevice = nullptr;
|
||||
static List<Component> components;
|
||||
bool multiValueComponent = false;
|
||||
|
||||
Component(const char* name, const char* id, const char* type) : name(name), id((char*)id), type(type) {
|
||||
components.add(this);
|
||||
@ -213,6 +214,7 @@ namespace Ha {
|
||||
|
||||
Builder& addSecondary(Component* c) {
|
||||
if (cmp->mainDevice) c->mainDevice = &DeviceConfig::create(cmp->mainDevice->id).withName(cmp->mainDevice->name);
|
||||
if (!strcmp(cmp->id, c->id)) c->multiValueComponent = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -354,7 +356,7 @@ namespace Ha {
|
||||
}
|
||||
|
||||
void buildUniqueId(char* uniqueId) override {
|
||||
if (deviceClass) {
|
||||
if (multiValueComponent && deviceClass) {
|
||||
sprintf(uniqueId, "%s_%s_%s", MAIN_DEVICE_ID, deviceClass, id);
|
||||
} else {
|
||||
Component::buildUniqueId(uniqueId);
|
||||
@ -362,7 +364,7 @@ namespace Ha {
|
||||
}
|
||||
|
||||
void buildConfigTopic() override {
|
||||
if (deviceClass) {
|
||||
if (multiValueComponent && deviceClass) {
|
||||
sprintf(configTopic, "homeassistant/%s/%s/%s_%s/config", type, MAIN_DEVICE_ID, deviceClass, id);
|
||||
} else {
|
||||
Component::buildConfigTopic();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user