From 4037ede0116f52b0a700b19db02dafabe2eb75f9 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 26 Mar 2025 10:19:35 +0100 Subject: [PATCH] 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;