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",
|
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
|
||||||
"name": "ha-mqtt",
|
"name": "ha-mqtt",
|
||||||
"version": "1.12.0",
|
"version": "1.13.0",
|
||||||
"description": "Home Assistant classes for integration with MQTT auto discovery",
|
"description": "Home Assistant classes for integration with MQTT auto discovery",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@ -42,8 +42,7 @@ namespace HaESP {
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Builder<T>& heapStats(Builder<T>& builder) {
|
Builder<T>& heapStats(Builder<T>& builder) {
|
||||||
auto heap = new Sensor{ "Heap fragmentation", "heap_fragmentation" };
|
builder.addDiagnostic(Builder<Sensor>::instance(new Sensor{ "Heap fragmentation", "heap_fragmentation" })
|
||||||
builder.addDiagnostic(Builder<Sensor>::instance(heap)
|
|
||||||
.withUnitMeasure("%")
|
.withUnitMeasure("%")
|
||||||
.withPrecision(0)
|
.withPrecision(0)
|
||||||
.withValueTemplate("{{ value_json.fragmentation }}")
|
.withValueTemplate("{{ value_json.fragmentation }}")
|
||||||
|
|||||||
5
src/ha.h
5
src/ha.h
@ -401,6 +401,7 @@ namespace Ha {
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct Builder : AbstractBuilder {
|
struct Builder : AbstractBuilder {
|
||||||
|
using factory_builder = std::function<Builder&(Builder&)>;
|
||||||
T* cmp;
|
T* cmp;
|
||||||
|
|
||||||
Builder(T* cmp) : AbstractBuilder(), cmp(cmp) {}
|
Builder(T* cmp) : AbstractBuilder(), cmp(cmp) {}
|
||||||
@ -496,6 +497,10 @@ namespace Ha {
|
|||||||
return factoryBuilder(*this);
|
return factoryBuilder(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Builder& addPreconfigured(factory_builder factoryBuilder) {
|
||||||
|
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