implement toJson for Component and Command to be used in webserver

responses
This commit is contained in:
Nicu Hodos 2025-09-08 12:22:38 +02:00
parent 9d026b4aef
commit 6924775e02
2 changed files with 11 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.8.0", "version": "1.9.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

@ -101,6 +101,12 @@ namespace Ha {
publisher(configTopic, ""); publisher(configTopic, "");
} }
void toJson(JsonDocument& jsonDoc) {
jsonDoc["id"] = id;
jsonDoc["name"] = name;
jsonDoc["type"] = type;
}
protected: protected:
void buildConfig(JsonDocument& jsonDoc) override { void buildConfig(JsonDocument& jsonDoc) override {
if (mainDevice) mainDevice->buildConfig(jsonDoc); if (mainDevice) mainDevice->buildConfig(jsonDoc);
@ -149,6 +155,10 @@ namespace Ha {
if (f) f(msg); if (f) f(msg);
} }
void toJson(JsonDocument& jsonDoc) {
cmp->toJson(jsonDoc);
}
protected: protected:
char commandTopic[TOPIC_SIZE] = {}; char commandTopic[TOPIC_SIZE] = {};
onMessage f; onMessage f;