From 69c42225532f83117b6f7c4460557086b07e8a23 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 7 Oct 2024 15:15:22 +0200 Subject: [PATCH 1/2] secondary components: always put the device name in MQTT configuration, even it is just referenced - new requirement from HA --- library.json | 2 +- src/ha.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index d4a8930..e9134ae 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", "name": "ha-mqtt", - "version": "1.1.0", + "version": "1.2.0", "description": "Home Assistant classes for integration with MQTT auto discovery", "repository": { "type": "git", diff --git a/src/ha.h b/src/ha.h index 76e1f94..c57e442 100644 --- a/src/ha.h +++ b/src/ha.h @@ -212,7 +212,7 @@ namespace Ha { } Builder& addSecondary(Component* c) { - if (cmp->mainDevice) c->mainDevice = &DeviceConfig::create(cmp->mainDevice->id); + if (cmp->mainDevice) c->mainDevice = &DeviceConfig::create(cmp->mainDevice->id).withName(cmp->mainDevice->name); return *this; } From 2bdbba11132ae12eb8f74d792f30d9f9072cb45c Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 7 Oct 2024 15:27:24 +0200 Subject: [PATCH 2/2] sensor: specifying a precision implies the sensor is number, but it needs to be generic (e.g. text) set a default precision only if there is a unit_of_measurement --- src/ha.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ha.h b/src/ha.h index c57e442..c526e6d 100644 --- a/src/ha.h +++ b/src/ha.h @@ -373,7 +373,12 @@ namespace Ha { StateConfig::buildConfig(jsonDoc); if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure; if (valueTemplate) jsonDoc["value_template"] = valueTemplate; - jsonDoc["suggested_display_precision"] = precision; + if (isNumericSensor()) jsonDoc["suggested_display_precision"] = precision; + } + + private: + bool isNumericSensor() { + return deviceClass || unitMeasure; } };