From 7327533b2420f1457547341c92881c756cfacf47 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 7 Oct 2024 22:06:26 +0200 Subject: [PATCH] detect a multi value sensor based on common id --- src/ha.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ha.h b/src/ha.h index c9a99c4..37ec441 100644 --- a/src/ha.h +++ b/src/ha.h @@ -93,6 +93,7 @@ namespace Ha { JsonPairs jsonStrings; DeviceConfig* mainDevice = nullptr; static List 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();