add restart reason sensor

This commit is contained in:
Nicu Hodos 2024-10-08 21:03:55 +02:00
parent f1901a1b53
commit 6468db5565

View File

@ -12,6 +12,10 @@ namespace HaESP {
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 <class T>
Builder<T>& heapStats(Builder<T>& builder) {
builder.addDiagnostic(Builder<Sensor>::instance(new Sensor{ "Heap fragmentation", "heap_fragmentation" })
@ -33,4 +37,11 @@ namespace HaESP {
tHeap.enable();
return builder;
}
template <class T>
Builder<T>& restartInfo(Builder<T>& builder) {
builder.addDiagnostic(Builder<Sensor>::instance((new Sensor{"Restart reason", "restart_reason"})).build());
tRestartInfo.enable();
return builder;
}
}