upgrade to ha-mqtt v2.0.0

This commit is contained in:
Nicu Hodos 2025-10-08 15:32:38 +02:00
parent 04b2d1c306
commit bfd8b02f2a
4 changed files with 10 additions and 12 deletions

View File

@ -4,7 +4,7 @@
using namespace Ha;
auto roomSensor = Builder<TemperatureSensor>::instance(TEMP_SENSOR)
auto roomSensor = Builder<TemperatureSensor>(TEMP_SENSOR)
.asDevice(&DeviceConfig::create(TEMP_SENSOR)
.withName("Servers room")
.withManufacturer("Atmel")
@ -15,7 +15,7 @@ auto roomSensor = Builder<TemperatureSensor>::instance(TEMP_SENSOR)
.addPreconfigured(batterySensors<TemperatureSensor>(TEMP_SENSOR, BATTERY_PERCENTAGE_TEMPLATE(2.5, 2)))
.build();
auto tankSensor = Builder<Sensor>::instance(new Sensor{ "Level", OIL_SENSOR })
auto tankSensor = Builder<Sensor>(new Sensor{ "Level", OIL_SENSOR })
.asDevice(&DeviceConfig::create(OIL_SENSOR)
.withName("Oil tank")
.withManufacturer("Arduino")
@ -27,7 +27,7 @@ auto tankSensor = Builder<Sensor>::instance(new Sensor{ "Level", OIL_SENSOR })
.withIcon("mdi:hydraulic-oil-level")
.withValueTemplate("{{ 100 - ((value_json.sensor.value-12)|float*100/120)|round(2) }}")
.addSecondary(
Builder<Sensor>::instance(new Sensor{ "Depth", OIL_SENSOR })
Builder<Sensor>(new Sensor{ "Depth", OIL_SENSOR })
.withDeviceClass("distance")
.withUnitMeasure("cm")
.withSensorStateClass(MEASUREMENT)
@ -37,7 +37,7 @@ auto tankSensor = Builder<Sensor>::instance(new Sensor{ "Level", OIL_SENSOR })
.addPreconfigured(batterySensors<Sensor>(OIL_SENSOR, BATTERY_PERCENTAGE_TEMPLATE(4, 2.4)))
.build();
auto presenceTracker = Builder<BinarySensor>::instance(PRESENCE_SENSOR)
auto presenceTracker = Builder<BinarySensor>(PRESENCE_SENSOR)
.asDevice(&DeviceConfig::create(PRESENCE_SENSOR)
.withName("Kid presence")
.withManufacturer("Atmel")
@ -57,7 +57,7 @@ Command* commands[] = {
.addPreconfigured(HaESP::wifiInfo)
.build(),
#if ENABLE_DOORBELL
Builder<Button>::instance(new Button{"Front door", "doorbell_front",
Builder<Button>(new Button{"Front door", "doorbell_front",
[](const char* msg) {
if (strcmp("PRESS", msg) == 0) doorbell.ring("00000000110100101000100");
}

View File

@ -41,6 +41,7 @@ namespace Board {
turnLed(RED_LED, false);
turnLed(BLUE_LED);
WebServer::setup();
Mqtt::setup(&ts,
[] {turnLed(BLUE_LED, false);},
[] {turnLed(BLUE_LED);}
@ -49,7 +50,7 @@ namespace Board {
[] {
Ota::tLoop.enable();
Mqtt::tReConnect.enable();
WebServer::setup();
WebServer::start();
},
[] {
Ota::tLoop.disable();

View File

@ -35,7 +35,7 @@ struct PollinSwitch : Switch {
void onCommand(const char* msg) override {
strcmp("ON", msg) == 0 ? mySwitch.switchOn(group, channel) : mySwitch.switchOff(group, channel);
publisher(stateTopic, msg);
publisher(State::topic, msg);
}
};
@ -69,7 +69,7 @@ struct EasyHomeSwitch : Switch {
void onCommand(const char* msg) override {
mySwitch.setProtocol(4);
strcmp("ON", msg) == 0 ? mySwitch.send(on[4], 24) : mySwitch.send(off[4], 24);
publisher(stateTopic, msg);
publisher(State::topic, msg);
}
};

View File

@ -14,7 +14,6 @@ default_envs = huzzah
[env]
lib_deps =
sui77/rc-switch@^2.6.4
bblanchon/ArduinoJson@6.21.5
adafruit/Adafruit Unified Sensor@^1.1.4
https://github.com/adafruit/Adafruit-GFX-Library#1.2.2
https://github.com/adafruit/Adafruit_LED_Backpack#1.1.6
@ -32,10 +31,8 @@ board = huzzah
framework = arduino
lib_deps =
${env.lib_deps}
arkhipenko/TaskScheduler@^3.8.5
https://git.hodos.ro/libraries/ha-mqtt.git@^1.13.0
https://git.hodos.ro/libraries/ha-mqtt.git#2.0.0
https://git.hodos.ro/libraries/wifi.git@^2.0.0
esphome/ESPAsyncWebServer-esphome@^3.4.0
upload_port = 192.168.6.161
upload_protocol = espota
upload_flags =