add support for precondfigured components - heap stats
This commit is contained in:
parent
7327533b24
commit
f1901a1b53
36
src/esp.h
Normal file
36
src/esp.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#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);
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
Builder<T>& heapStats(Builder<T>& builder) {
|
||||||
|
builder.addDiagnostic(Builder<Sensor>::instance(new Sensor{ "Heap fragmentation", "heap_fragmentation" })
|
||||||
|
.withUnitMeasure("%")
|
||||||
|
.withPrecision(0)
|
||||||
|
.build());
|
||||||
|
builder.addDiagnostic(Builder<Sensor>::instance(new Sensor{ "Heap free", "heap_free" })
|
||||||
|
.withDeviceClass("data_size")
|
||||||
|
.withUnitMeasure("B")
|
||||||
|
.withPrecision(0)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
builder.addDiagnostic(Builder<Sensor>::instance(new Sensor{ "Heap max free block", "heap_max_free_block" })
|
||||||
|
.withDeviceClass("data_size")
|
||||||
|
.withUnitMeasure("B")
|
||||||
|
.withPrecision(0)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
tHeap.enable();
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
4
src/ha.h
4
src/ha.h
@ -223,6 +223,10 @@ namespace Ha {
|
|||||||
return addSecondary(c);
|
return addSecondary(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Builder& addPreconfigured(Builder& (*factoryBuilder)(Builder& builder)) {
|
||||||
|
return factoryBuilder(*this);
|
||||||
|
}
|
||||||
|
|
||||||
Builder& addConfiguration(Component* c) {
|
Builder& addConfiguration(Component* c) {
|
||||||
c->entityCategory = "config";
|
c->entityCategory = "config";
|
||||||
return addSecondary(c);
|
return addSecondary(c);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user