fine tunning:
- use namespace for oil tank builders - use factory method for creating DeviceConfig - use C's strcmp for comparing strings - split parsing of incoming RCSwitch states
This commit is contained in:
parent
0d574b8da1
commit
0cdf58d99b
@ -19,7 +19,10 @@ namespace Ha {
|
||||
DeviceConfig* parent = nullptr;
|
||||
|
||||
DeviceConfig(const char* id) : id(id) {}
|
||||
DeviceConfig(DeviceConfig& d) : id(d.id), name(d.name), model(d.model), manufacturer(d.manufacturer), area(d.area), parent(d.parent) {}
|
||||
|
||||
static DeviceConfig* create(const char* id) {
|
||||
return new DeviceConfig{ id };
|
||||
}
|
||||
|
||||
void buildConfig(JsonDocument& jsonDoc) {
|
||||
JsonObject device = jsonDoc.createNestedObject("device");
|
||||
|
||||
@ -12,12 +12,11 @@ namespace Mqtt {
|
||||
|
||||
AsyncMqttClient client;
|
||||
|
||||
void publishInit();
|
||||
void disconnect();
|
||||
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, []() {
|
||||
Serial.println("Connecting to MQTT...");
|
||||
client.connect();
|
||||
}, &ts);
|
||||
void publishInit();
|
||||
Task tPublishInit(TASK_IMMEDIATE, TASK_ONCE, publishInit, &ts);
|
||||
|
||||
const char* mainTopic = "homeassistant/+/rc-gateway/#";
|
||||
@ -34,7 +33,7 @@ namespace Mqtt {
|
||||
Command* commands[] = {
|
||||
Builder<Button>::instance(new Button{"Restart", "restart",
|
||||
[](const char* msg) {
|
||||
if (String { "PRESS" }.equals(msg)) ESP.restart();
|
||||
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(),
|
||||
@ -46,8 +45,8 @@ namespace Mqtt {
|
||||
};
|
||||
|
||||
Sensor* sensors[] = {
|
||||
OilTankRoomSensorBuilder::build("4"),
|
||||
OilSensorBuilder::build("7")
|
||||
OilTank::buildRoomSensor("4"),
|
||||
OilTank::buildTankSensor("7")
|
||||
};
|
||||
|
||||
void publishInit() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user