add support for icon

This commit is contained in:
Nicu Hodos 2025-03-26 10:19:35 +01:00
parent 4b600a4686
commit 4037ede011
2 changed files with 8 additions and 1 deletions

View File

@ -1,7 +1,7 @@
{ {
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
"name": "ha-mqtt", "name": "ha-mqtt",
"version": "1.5.1", "version": "1.6.0",
"description": "Home Assistant classes for integration with MQTT auto discovery", "description": "Home Assistant classes for integration with MQTT auto discovery",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -77,6 +77,7 @@ namespace Ha {
const char* name = nullptr; const char* name = nullptr;
const char* entityCategory = nullptr; const char* entityCategory = nullptr;
const char* deviceClass = nullptr; const char* deviceClass = nullptr;
const char* icon = nullptr;
DeviceConfig* mainDevice = nullptr; DeviceConfig* mainDevice = nullptr;
inline static List<Component> components; inline static List<Component> components;
bool multiValueComponent = false; bool multiValueComponent = false;
@ -104,6 +105,7 @@ namespace Ha {
if (mainDevice) mainDevice->buildConfig(jsonDoc); if (mainDevice) mainDevice->buildConfig(jsonDoc);
if (entityCategory) jsonDoc["entity_category"] = entityCategory; if (entityCategory) jsonDoc["entity_category"] = entityCategory;
if (deviceClass) jsonDoc["device_class"] = deviceClass; if (deviceClass) jsonDoc["device_class"] = deviceClass;
if (icon) jsonDoc["icon"] = icon;
jsonDoc["name"] = name; jsonDoc["name"] = name;
buildUniqueId(jsonDoc); buildUniqueId(jsonDoc);
@ -388,6 +390,11 @@ namespace Ha {
return *this; return *this;
} }
Builder& withIcon(const char* value) {
cmp->icon = value;
return *this;
}
Builder& withValueTemplate(const char* value) { Builder& withValueTemplate(const char* value) {
cmp->valueTemplate = value; cmp->valueTemplate = value;
return *this; return *this;