From 98fbf2a55e6884a69742b4c0ac6b97aeb5e2b9e4 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 8 Oct 2025 14:32:49 +0200 Subject: [PATCH] add pre-configured button for updating the heap statistics --- src/esp.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/esp.h b/src/esp.h index 9b78bdb..a438d5c 100644 --- a/src/esp.h +++ b/src/esp.h @@ -47,19 +47,24 @@ namespace HaESP { .withPrecision(0) .withValueTemplate("{{ value_json.fragmentation }}") .withJsonAttributes("{{ value_json.heap | tojson }}") - .build()); - builder.addDiagnostic(Builder(new Sensor{ "Heap free", "heap_free" }) + .build()) + .addDiagnostic(Builder(new Sensor{ "Heap free", "heap_free" }) .withDeviceClass("data_size") .withUnitMeasure("B") .withPrecision(0) - .build() - ); - builder.addDiagnostic(Builder(new Sensor{ "Heap max free block", "heap_max_free_block" }) + .build()) + .addDiagnostic(Builder(new Sensor{ "Heap max free block", "heap_max_free_block" }) .withDeviceClass("data_size") .withUnitMeasure("B") .withPrecision(0) - .build() - ); + .build()) + .addSecondary(new Button{"Update heap stats", "update_heap_stats", + [](const char* msg) { + if ((strcmp("PRESS", msg) == 0) && tHeap.isEnabled()) { + tHeap.cancel(); + tHeap.restart(); + }}}); + activeSensors.heapStats = true; return builder; }