From 4037ede0116f52b0a700b19db02dafabe2eb75f9 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 26 Mar 2025 10:19:35 +0100 Subject: [PATCH 1/4] add support for icon --- library.json | 2 +- src/ha.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index b6f29eb..e79e522 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.5.1", + "version": "1.6.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 3d627ea..c7e5bfb 100644 --- a/src/ha.h +++ b/src/ha.h @@ -77,6 +77,7 @@ namespace Ha { const char* name = nullptr; const char* entityCategory = nullptr; const char* deviceClass = nullptr; + const char* icon = nullptr; DeviceConfig* mainDevice = nullptr; inline static List components; bool multiValueComponent = false; @@ -104,6 +105,7 @@ namespace Ha { if (mainDevice) mainDevice->buildConfig(jsonDoc); if (entityCategory) jsonDoc["entity_category"] = entityCategory; if (deviceClass) jsonDoc["device_class"] = deviceClass; + if (icon) jsonDoc["icon"] = icon; jsonDoc["name"] = name; buildUniqueId(jsonDoc); @@ -388,6 +390,11 @@ namespace Ha { return *this; } + Builder& withIcon(const char* value) { + cmp->icon = value; + return *this; + } + Builder& withValueTemplate(const char* value) { cmp->valueTemplate = value; return *this; From 94ff72aefc7ee1a019ab0778e141caebfdacfd81 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 26 Mar 2025 13:37:38 +0100 Subject: [PATCH 2/4] add support of unitMeasure for Numbers --- src/ha.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ha.h b/src/ha.h index c7e5bfb..ce7af34 100644 --- a/src/ha.h +++ b/src/ha.h @@ -245,6 +245,7 @@ namespace Ha { unsigned int min = 1; unsigned int max = 100; unsigned int step = 1; + const char* unitMeasure = nullptr; Number(const char* name, const char* id, onMessage f) : Component(id, name, "number"), StatefulCommand(this, f) {} @@ -258,6 +259,7 @@ namespace Ha { jsonDoc["min"] = min; jsonDoc["max"] = max; jsonDoc["step"] = step; + if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure; } }; From 5d9b0862bf75432a6874e3d70fe582795385960d Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 26 Mar 2025 13:38:16 +0100 Subject: [PATCH 3/4] valueTemplate is specific to all state components --- src/ha.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ha.h b/src/ha.h index ce7af34..56d182e 100644 --- a/src/ha.h +++ b/src/ha.h @@ -161,6 +161,7 @@ namespace Ha { struct State : Config { char stateTopic[TOPIC_SIZE] = {}; const char* jsonAttributesTemplate = nullptr; + const char* valueTemplate = nullptr; State(Component* cmp) : cmp(cmp) {} @@ -180,6 +181,7 @@ namespace Ha { jsonDoc["json_attributes_template"] = jsonAttributesTemplate; jsonDoc["json_attributes_topic"] = (const char*)stateTopic; } + if (valueTemplate) jsonDoc["value_template"] = valueTemplate; } } private: @@ -286,7 +288,6 @@ namespace Ha { struct Sensor : Component, State { const char* unitMeasure = nullptr; - const char* valueTemplate = nullptr; unsigned int precision = 2; inline static unordered_map mapSensors; @@ -299,7 +300,6 @@ namespace Ha { Component::buildConfig(jsonDoc); State::buildConfig(jsonDoc); if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure; - if (valueTemplate) jsonDoc["value_template"] = valueTemplate; if (isNumericSensor()) jsonDoc["suggested_display_precision"] = precision; } From f33ed5cd7574dedb5e1a636a28f5f7955c448897 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Thu, 27 Mar 2025 12:28:00 +0100 Subject: [PATCH 4/4] add restart button for ESP devices --- src/esp.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/esp.h b/src/esp.h index 5cfb8a7..4dd511b 100644 --- a/src/esp.h +++ b/src/esp.h @@ -60,6 +60,15 @@ namespace HaESP { return builder; } + Builder