Browse Source

thermostat: setting: set a default configuration

master
Richard Genoud 4 years ago
parent
commit
78582706fc
3 changed files with 98 additions and 3 deletions
  1. +5
    -0
      soft/thermostat/Thermostat.conf
  2. +11
    -0
      soft/thermostat/inc/settings.h
  3. +82
    -3
      soft/thermostat/src/settings.cpp

+ 5
- 0
soft/thermostat/Thermostat.conf View File

@ -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


+ 11
- 0
soft/thermostat/inc/settings.h View File

@ -11,6 +11,7 @@
#include <QSettings>
#include <QVector>
#include <QTime>
#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<struct Heater> heaters;
QVector<struct Program> 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


+ 82
- 3
soft/thermostat/src/settings.cpp View File

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


Loading…
Cancel
Save