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* parent = nullptr;
|
||||||
|
|
||||||
DeviceConfig(const char* id) : id(id) {}
|
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) {
|
void buildConfig(JsonDocument& jsonDoc) {
|
||||||
JsonObject device = jsonDoc.createNestedObject("device");
|
JsonObject device = jsonDoc.createNestedObject("device");
|
||||||
|
|||||||
@ -12,12 +12,11 @@ namespace Mqtt {
|
|||||||
|
|
||||||
AsyncMqttClient client;
|
AsyncMqttClient client;
|
||||||
|
|
||||||
void publishInit();
|
|
||||||
void disconnect();
|
|
||||||
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);
|
||||||
|
void publishInit();
|
||||||
Task tPublishInit(TASK_IMMEDIATE, TASK_ONCE, publishInit, &ts);
|
Task tPublishInit(TASK_IMMEDIATE, TASK_ONCE, publishInit, &ts);
|
||||||
|
|
||||||
const char* mainTopic = "homeassistant/+/rc-gateway/#";
|
const char* mainTopic = "homeassistant/+/rc-gateway/#";
|
||||||
@ -34,7 +33,7 @@ namespace Mqtt {
|
|||||||
Command* commands[] = {
|
Command* commands[] = {
|
||||||
Builder<Button>::instance(new Button{"Restart", "restart",
|
Builder<Button>::instance(new Button{"Restart", "restart",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
if (String { "PRESS" }.equals(msg)) ESP.restart();
|
if (strcmp("PRESS", msg) == 0) ESP.restart();
|
||||||
}
|
}
|
||||||
}).asDevice(gatewayDevice).build(),
|
}).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{"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[] = {
|
Sensor* sensors[] = {
|
||||||
OilTankRoomSensorBuilder::build("4"),
|
OilTank::buildRoomSensor("4"),
|
||||||
OilSensorBuilder::build("7")
|
OilTank::buildTankSensor("7")
|
||||||
};
|
};
|
||||||
|
|
||||||
void publishInit() {
|
void publishInit() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user