From 9511f08d2b58d3a0d29bb3cce658545289ea5292 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 8 Oct 2025 09:43:59 +0200 Subject: [PATCH 01/14] don't create Builders on heap, use temporary objects instead --- library.json | 2 +- src/esp.h | 18 +++++++++--------- src/ha.h | 28 +++------------------------- src/mqtt.h | 1 - 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/library.json b/library.json index 0a4a586..be1d133 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.13.0", + "version": "2.0.0", "description": "Home Assistant classes for integration with MQTT auto discovery", "repository": { "type": "git", diff --git a/src/esp.h b/src/esp.h index 4753eca..9b78bdb 100644 --- a/src/esp.h +++ b/src/esp.h @@ -22,7 +22,7 @@ namespace HaESP { ESP.getHeapStats(&hfree, &hmax, &hfrag); char value[128]; - snprintf_P(value, sizeof(value), PSTR("{\"fragmentation\":%d,\"heap\":{\"Heap free\":\"%d B\",\"Heap max free block\":\"%d B\"}}"), hfrag, hfree, hmax); + snprintf_P(value, sizeof(value), PSTR("{\"fragmentation\":%d,\"heap\":{\"Heap free\":\"%d B\",\"Heap max free block\":\"%d B\"}}"), hfrag, hfree, hmax); GenericSensor::mapSensors["heap_fragmentation"]->updateState(value); GenericSensor::mapSensors["heap_free"]->updateState(to_string(hfree).c_str()); GenericSensor::mapSensors["heap_max_free_block"]->updateState(to_string(hmax).c_str()); @@ -42,19 +42,19 @@ namespace HaESP { template Builder& heapStats(Builder& builder) { - builder.addDiagnostic(Builder::instance(new Sensor{ "Heap fragmentation", "heap_fragmentation" }) + builder.addDiagnostic(Builder(new Sensor{ "Heap fragmentation", "heap_fragmentation" }) .withUnitMeasure("%") .withPrecision(0) .withValueTemplate("{{ value_json.fragmentation }}") .withJsonAttributes("{{ value_json.heap | tojson }}") .build()); - builder.addDiagnostic(Builder::instance(new Sensor{ "Heap free", "heap_free" }) + builder.addDiagnostic(Builder(new Sensor{ "Heap free", "heap_free" }) .withDeviceClass("data_size") .withUnitMeasure("B") .withPrecision(0) .build() ); - builder.addDiagnostic(Builder::instance(new Sensor{ "Heap max free block", "heap_max_free_block" }) + builder.addDiagnostic(Builder(new Sensor{ "Heap max free block", "heap_max_free_block" }) .withDeviceClass("data_size") .withUnitMeasure("B") .withPrecision(0) @@ -66,14 +66,14 @@ namespace HaESP { template Builder& restartInfo(Builder& builder) { - builder.addDiagnostic(Builder::instance((new Sensor{ "Restart reason", "restart_reason" })).build()); + builder.addDiagnostic((new Sensor{ "Restart reason", "restart_reason" })); activeSensors.restartInfo = true; return builder; } template Builder& wifiInfo(Builder& builder) { - builder.addDiagnostic(Builder::instance(( + builder.addDiagnostic(Builder(( new Sensor{ "WiFi Signal (RSSI)", "wifi_signal_strength" })) .withDeviceClass("signal_strength") .withUnitMeasure("dBm") @@ -85,12 +85,12 @@ namespace HaESP { } Builder