add support for using lambdas with captures as factory_builder functions
This commit is contained in:
parent
49a86fb559
commit
07eeac8beb
@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
|
||||
"name": "ha-mqtt",
|
||||
"version": "1.12.0",
|
||||
"version": "1.13.0",
|
||||
"description": "Home Assistant classes for integration with MQTT auto discovery",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@ -42,8 +42,7 @@ namespace HaESP {
|
||||
|
||||
template <class T>
|
||||
Builder<T>& heapStats(Builder<T>& builder) {
|
||||
auto heap = new Sensor{ "Heap fragmentation", "heap_fragmentation" };
|
||||
builder.addDiagnostic(Builder<Sensor>::instance(heap)
|
||||
builder.addDiagnostic(Builder<Sensor>::instance(new Sensor{ "Heap fragmentation", "heap_fragmentation" })
|
||||
.withUnitMeasure("%")
|
||||
.withPrecision(0)
|
||||
.withValueTemplate("{{ value_json.fragmentation }}")
|
||||
|
||||
5
src/ha.h
5
src/ha.h
@ -401,6 +401,7 @@ namespace Ha {
|
||||
|
||||
template <class T>
|
||||
struct Builder : AbstractBuilder {
|
||||
using factory_builder = std::function<Builder&(Builder&)>;
|
||||
T* cmp;
|
||||
|
||||
Builder(T* cmp) : AbstractBuilder(), cmp(cmp) {}
|
||||
@ -496,6 +497,10 @@ namespace Ha {
|
||||
return factoryBuilder(*this);
|
||||
}
|
||||
|
||||
Builder& addPreconfigured(factory_builder factoryBuilder) {
|
||||
return factoryBuilder(*this);
|
||||
}
|
||||
|
||||
Builder& addConfiguration(Component* c) {
|
||||
c->entityCategory = "config";
|
||||
return addSecondary(c);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user