From 6924775e02d87d24585e3bc343598412142d6d16 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 8 Sep 2025 12:22:38 +0200 Subject: [PATCH] implement toJson for Component and Command to be used in webserver responses --- library.json | 2 +- src/ha.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index f451edd..e32a3aa 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.8.0", + "version": "1.9.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 4732bee..3559738 100644 --- a/src/ha.h +++ b/src/ha.h @@ -101,6 +101,12 @@ namespace Ha { publisher(configTopic, ""); } + void toJson(JsonDocument& jsonDoc) { + jsonDoc["id"] = id; + jsonDoc["name"] = name; + jsonDoc["type"] = type; + } + protected: void buildConfig(JsonDocument& jsonDoc) override { if (mainDevice) mainDevice->buildConfig(jsonDoc); @@ -149,6 +155,10 @@ namespace Ha { if (f) f(msg); } + void toJson(JsonDocument& jsonDoc) { + cmp->toJson(jsonDoc); + } + protected: char commandTopic[TOPIC_SIZE] = {}; onMessage f;