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..f7cfbce 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\":%lu,\"heap\":{\"Heap free\":\"%lu B\",\"Heap max free block\":\"%u 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,38 +42,43 @@ 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" }) + .build()) + .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" }) + .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; } 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 +90,12 @@ namespace HaESP { } Builder