move all devices creattion in devices.h

This commit is contained in:
Nicu Hodos 2024-05-17 18:01:12 +02:00
parent 4b3ed383d8
commit 22add7aea8
3 changed files with 24 additions and 24 deletions

View File

@ -94,3 +94,22 @@ struct EasyHomeSwitch : Switch {
publisher(stateTopic, msg);
}
};
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")
};

View File

@ -7,7 +7,7 @@
#define TOPIC_SIZE 255
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);
struct DeviceConfig {
@ -128,10 +128,10 @@ namespace Ha {
struct Builder : AbstractBuilder {
T* cmp;
Builder(T* cmp) : AbstractBuilder(), cmp(cmp) {}
Builder(T* cmp) : AbstractBuilder(), cmp(cmp) {}
Builder(const char* id) : AbstractBuilder() {
cmp = new T{id};
cmp = new T{ id };
}
static Builder& instance(T* c) {
@ -285,7 +285,7 @@ namespace Ha {
};
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;
deviceClass = "battery";
unitMeasure = "%";

View File

@ -12,7 +12,7 @@ namespace Mqtt {
AsyncMqttClient client;
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, []() {
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, []{
Serial.println("Connecting to MQTT...");
client.connect();
}, &ts);
@ -30,25 +30,6 @@ namespace Mqtt {
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() {
Ha::publisher = publish;
Component::components.forEach([](Component* c) { c->publishConfig(); });