Configure shades via MQTT messages
This commit is contained in:
23
src/main.cpp
23
src/main.cpp
@@ -6,6 +6,7 @@
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
#include "Shade.h"
|
||||
#include "Configurator.h"
|
||||
#include "ShadeRepository.h"
|
||||
#include "HADiscovery.h"
|
||||
#include "secrets.h"
|
||||
@@ -48,6 +49,8 @@ EspMQTTClient client(
|
||||
1883
|
||||
);
|
||||
|
||||
Configurator configurator = Configurator();
|
||||
|
||||
ShadeRepository shadeRepository = ShadeRepository();
|
||||
|
||||
HADiscovery haDiscovery(topic_prefix.c_str(), [] (const char* topic, const char* message) {
|
||||
@@ -94,6 +97,10 @@ void setup() {
|
||||
Serial.println("Failed to set max packet size");
|
||||
}
|
||||
|
||||
configurator.addShadeConfiguredCallback([] (Shade shade) {
|
||||
shadeRepository.upsert(shade);
|
||||
});
|
||||
|
||||
shadeRepository.addShadeAddedCallback([] (Shade& shade) {
|
||||
// Only add shade if client is already connected
|
||||
if (client.isConnected()) {
|
||||
@@ -109,22 +116,6 @@ void setup() {
|
||||
|
||||
delay(100);
|
||||
|
||||
shadeRepository.upsert(Shade{0x4EF1, "study_blind", "Study Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0xA51F, "studio_blockout_left_blind", "Studio Blockout Left Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0xDAEF, "studio_blockout_right_blind", "Studio Blockout Right Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0x7687, "studio_left_blind", "Studio Left Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0xB0DE, "studio_right_blind", "Studio Right Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0xB451, "bedroom_door_blockout_blind", "Bedroom Door Blockout Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0x48A6, "bedroom_window_blockout_blind", "Bedroom Window Blockout Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0x9E14, "bedroom_door_blind", "Bedroom Door Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0x061C, "bedroom_window_blind", "Bedroom Window Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0x2959, "bathroom_blind", "Bathroom Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0x6FAD, "kitchen_door_blind", "Kitchen Door Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0xFB21, "kitchen_window_blind", "Kitchen Window Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0x8B10, "living_room_big_window_blind", "Living Room Big Window Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0x3EB8, "living_room_door_blind", "Living Room Door Blind", -1, -1, 0, 0, nullptr});
|
||||
shadeRepository.upsert(Shade{0x5463, "living_room_window_blind", "Living Room Window Blind", -1, -1, 0, 0, nullptr});
|
||||
|
||||
Serial.println("Ready");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user