diff --git a/soft/thermostat/Thermostat.conf b/soft/thermostat/Thermostat.conf index 1fbf6f3..2ebe722 100644 --- a/soft/thermostat/Thermostat.conf +++ b/soft/thermostat/Thermostat.conf @@ -11,6 +11,11 @@ port=1883 1\availability_topic=sensors/chambre_so/availability 1\name=Bedroom 1\sensor_topic=sensors/chambre_so/xiaomi +1\default_temperature=21 +1\temperature_schedule\1\temperature=21 +1\temperature_schedule\1\days_of_week=127 +1\temperature_schedule\1\start_time=10:00 +1\temperature_schedule\1\end_time=18:30 2\heaters\1\control_topic=chauffage/chambre_rico 2\heaters\size=1 2\availability_topic=sensors/chambre_rico/availability diff --git a/soft/thermostat/inc/settings.h b/soft/thermostat/inc/settings.h index f0fdbef..549371e 100644 --- a/soft/thermostat/inc/settings.h +++ b/soft/thermostat/inc/settings.h @@ -11,6 +11,7 @@ #include #include +#include #define MAX_NB_ZONES 4 @@ -18,11 +19,19 @@ struct Heater { QString ctrl_topic; }; +struct Program { + double temperature; + uint8_t DoW; + QTime start_time; + QTime end_time; +}; + struct Room { QString name; QString sensor_topic; QString availability_topic; QVector heaters; + QVector progs; }; struct Brocker { @@ -45,6 +54,8 @@ private: ~Settings(void); static Settings *_singleton; + void set_rooms_default_config(void); + int read_config(void); }; #endif // SETTINGS_H diff --git a/soft/thermostat/src/settings.cpp b/soft/thermostat/src/settings.cpp index 939f8ef..9db770c 100644 --- a/soft/thermostat/src/settings.cpp +++ b/soft/thermostat/src/settings.cpp @@ -12,6 +12,34 @@ #include "settings.h" +const char default_room_names[MAX_NB_ZONES][42] = { + "Bedroom", + "Living Room", + "Workspace", + "Bathroom" +}; + +const char default_sensors_topics[MAX_NB_ZONES][64] = { + "sensors/bedroom/xiaomi", + "sensors/living_room/xiaomi", + "sensors/workspace/xiaomi", + "sensors/bathroom/xiaomi" +}; + +const char default_availability_topics[MAX_NB_ZONES][64] = { + "sensors/bedroom/availability", + "sensors/living_room/availability", + "sensors/workspace/availability", + "sensors/bathroom/availability" +}; + +const char default_control_topics[MAX_NB_ZONES][64] = { + "heaters/bedroom", + "heaters/living_room", + "heaters/workspace", + "heaters/bathroom" +}; + Settings *Settings::_singleton = NULL; Settings::Settings(QObject *parent) : QSettings(parent) @@ -21,6 +49,12 @@ Settings::Settings(QObject *parent) : QSettings(parent) int nb_rooms; nb_rooms = this->beginReadArray("rooms"); + if (nb_rooms == 0) { + this->endArray(); + set_rooms_default_config(); + nb_rooms = this->beginReadArray("rooms"); + } + if (nb_rooms > MAX_NB_ZONES) { // TODO; nb_rooms = MAX_NB_ZONES; @@ -28,9 +62,10 @@ Settings::Settings(QObject *parent) : QSettings(parent) for (int i = 0; i < nb_rooms; ++i) { this->setArrayIndex(i); - room.name = this->value("name", "").toString(); - room.sensor_topic = this->value("sensor_topic", "").toString(); - room.availability_topic = this->value("availability_topic", "").toString(); + room.name = this->value("name", default_room_names[i]).toString(); + room.sensor_topic = this->value("sensor_topic", default_sensors_topics[i]).toString(); + room.availability_topic = this->value("availability_topic", + default_availability_topics[i]).toString(); int size = this->beginReadArray("heaters"); for (int j = 0; j < size; ++j) { this->setArrayIndex(j); @@ -45,6 +80,50 @@ Settings::Settings(QObject *parent) : QSettings(parent) m_broker.port = this->value("broker/port", 1883).toInt(); } +void Settings::set_rooms_default_config(void) +{ + this->beginWriteArray("rooms"); + + for (int i = 0; i < MAX_NB_ZONES; i++) { + this->setArrayIndex(i); + this->setValue("name", tr(default_room_names[i])); + this->setValue("sensor_topic", default_sensors_topics[i]); + this->setValue("availability_topic", default_availability_topics[i]); + this->setValue("default_temperature", 20); + this->beginWriteArray("heaters"); + this->setArrayIndex(0); + this->setValue("control_topic", default_control_topics[i]); + this->endArray(); + } + + this->setArrayIndex(0); + this->beginWriteArray("temperature_schedule"); + this->setArrayIndex(0); + this->setValue("temperature", 18); + this->setValue("days_of_week", 127); + this->setValue("start_time", QTime(22,0).toString("H:m")); + this->setValue("end_time", QTime(7,0).toString("H:m")); + this->endArray(); + + + this->setArrayIndex(3); + this->beginWriteArray("temperature_schedule"); + this->setArrayIndex(0); + this->setValue("temperature", 99); // Force On + this->setValue("days_of_week", 31); + this->setValue("start_time", QTime(6,30).toString("H:m")); + this->setValue("end_time", QTime(7,0).toString("H:m")); + this->setArrayIndex(1); + this->setValue("temperature", 99); // Force On + this->setValue("days_of_week", 96); + this->setValue("start_time", QTime(7,30).toString("H:m")); + this->setValue("end_time", QTime(8,0).toString("H:m")); + this->endArray(); + + this->endArray(); + this->sync(); +} + int Settings::nbZones(void) { return m_rooms.size();