move all devices creattion in devices.h
This commit is contained in:
parent
26b11129a8
commit
96b420b258
@ -7,7 +7,7 @@
|
|||||||
#define TOPIC_SIZE 255
|
#define TOPIC_SIZE 255
|
||||||
|
|
||||||
namespace Ha {
|
namespace Ha {
|
||||||
uint16_t (*publisher)(const char* topic, const char* message);
|
uint16_t(*publisher)(const char* topic, const char* message);
|
||||||
typedef void (*onMessage)(const char* msg);
|
typedef void (*onMessage)(const char* msg);
|
||||||
|
|
||||||
struct DeviceConfig {
|
struct DeviceConfig {
|
||||||
@ -128,10 +128,10 @@ namespace Ha {
|
|||||||
struct Builder : AbstractBuilder {
|
struct Builder : AbstractBuilder {
|
||||||
T* cmp;
|
T* cmp;
|
||||||
|
|
||||||
Builder(T* cmp) : AbstractBuilder(), cmp(cmp) {}
|
Builder(T* cmp) : AbstractBuilder(), cmp(cmp) {}
|
||||||
|
|
||||||
Builder(const char* id) : AbstractBuilder() {
|
Builder(const char* id) : AbstractBuilder() {
|
||||||
cmp = new T{id};
|
cmp = new T{ id };
|
||||||
}
|
}
|
||||||
|
|
||||||
static Builder& instance(T* c) {
|
static Builder& instance(T* c) {
|
||||||
@ -285,7 +285,7 @@ namespace Ha {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct BatterySensor : Sensor {
|
struct BatterySensor : Sensor {
|
||||||
BatterySensor(const char* id, const char* name, const char* valueTemplate) : Sensor(name, id) {
|
BatterySensor(const char* id, const char* name, const char* valueTemplate) : Sensor(name, id) {
|
||||||
this->valueTemplate = valueTemplate;
|
this->valueTemplate = valueTemplate;
|
||||||
deviceClass = "battery";
|
deviceClass = "battery";
|
||||||
unitMeasure = "%";
|
unitMeasure = "%";
|
||||||
|
|||||||
@ -12,7 +12,7 @@ namespace Mqtt {
|
|||||||
|
|
||||||
AsyncMqttClient client;
|
AsyncMqttClient client;
|
||||||
|
|
||||||
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, []() {
|
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, []{
|
||||||
Serial.println("Connecting to MQTT...");
|
Serial.println("Connecting to MQTT...");
|
||||||
client.connect();
|
client.connect();
|
||||||
}, &ts);
|
}, &ts);
|
||||||
@ -30,25 +30,6 @@ namespace Mqtt {
|
|||||||
return client.publish(topic, 0, true, message);
|
return client.publish(topic, 0, true, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command* commands[] = {
|
|
||||||
Builder<Button>::instance(new Button{"Restart", "restart",
|
|
||||||
[](const char* msg) {
|
|
||||||
if (strcmp("PRESS", msg) == 0) ESP.restart();
|
|
||||||
}
|
|
||||||
}).asDevice(gatewayDevice).build(),
|
|
||||||
(new EasyHomeSwitch{"FritzBox", "easy_home_a", (unsigned long[4]) { 4483136, 4626800, 4661552, 4819632 }, (unsigned long[4]) { 4326544, 4537104, 4767520, 4972704 }, "Basement"})->withStateTopic(),
|
|
||||||
(new EasyHomeSwitch{"Outside", "easy_home_b", (unsigned long[4]) { 4483140, 4626804, 4661556, 4819636 }, (unsigned long[4]) { 4326548, 4537108, 4767524, 4972708 }, "Basement"})->withStateTopic(),
|
|
||||||
(new PollinSwitch{"Meeting sensor", "00001", 1, "Dining room"})->withStateTopic(),
|
|
||||||
(new PollinSwitch{"Fire Tv", "00001", 2, "Living room"})->withStateTopic(),
|
|
||||||
(new PollinSwitch{"Diningroom player", "00001", 3, "Dining room"})->withStateTopic(),
|
|
||||||
(new PollinSwitch{"Train", "11111", 4, "Playroom"})->withStateTopic()
|
|
||||||
};
|
|
||||||
|
|
||||||
Sensor* sensors[] = {
|
|
||||||
OilTank::buildRoomSensor("4"),
|
|
||||||
OilTank::buildTankSensor("7")
|
|
||||||
};
|
|
||||||
|
|
||||||
void publishInit() {
|
void publishInit() {
|
||||||
Ha::publisher = publish;
|
Ha::publisher = publish;
|
||||||
Component::components.forEach([](Component* c) { c->publishConfig(); });
|
Component::components.forEach([](Component* c) { c->publishConfig(); });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user