|
|
@ -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(); |
|
|
|