#pragma once #include "TaskScheduler.h" #include "ha.h" using namespace Ha; namespace HaESP { Task tHeap(1 * TASK_MINUTE, TASK_FOREVER, []() { Sensor::mapSensors["heap_fragmentation"]->updateState(to_string(ESP.getHeapFragmentation()).c_str()); Sensor::mapSensors["heap_free"]->updateState(to_string(ESP.getFreeHeap()).c_str()); Sensor::mapSensors["heap_max_free_block"]->updateState(to_string(ESP.getMaxFreeBlockSize()).c_str()); }, &ts); Task tRestartInfo(TASK_IMMEDIATE, TASK_ONCE, [](){ Sensor::mapSensors["restart_reason"]->updateState(ESP.getResetReason().c_str()); }, &ts); template Builder& heapStats(Builder& builder) { builder.addDiagnostic(Builder::instance(new Sensor{ "Heap fragmentation", "heap_fragmentation" }) .withUnitMeasure("%") .withPrecision(0) .build()); builder.addDiagnostic(Builder::instance(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" }) .withDeviceClass("data_size") .withUnitMeasure("B") .withPrecision(0) .build() ); tHeap.enable(); return builder; } template Builder& restartInfo(Builder& builder) { builder.addDiagnostic(Builder::instance((new Sensor{"Restart reason", "restart_reason"})).build()); tRestartInfo.enable(); return builder; } }