From e1b83ac242133a20107f9c6c891b2d54b98ec211 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Sat, 5 Sep 2020 11:31:28 +0200 Subject: [PATCH] thermostat: Settings: add functions to save room temperature and programs --- soft/thermostat/inc/settings.h | 2 ++ soft/thermostat/src/settings.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/soft/thermostat/inc/settings.h b/soft/thermostat/inc/settings.h index df4fdb9..e8098b6 100644 --- a/soft/thermostat/inc/settings.h +++ b/soft/thermostat/inc/settings.h @@ -61,6 +61,8 @@ public: const QDateTime &getEndHoliday(void) { return m_end_holiday; } void setEndHoliday(const QDateTime &endDate); const struct Room &getRoom(int idx) { return m_rooms.at(idx); } + void setRoomDefaultTemperature(int idx, double temperature); + void setRoomPrograms(int idx, QVector &progs); struct Brocker m_broker; diff --git a/soft/thermostat/src/settings.cpp b/soft/thermostat/src/settings.cpp index 23280ac..72a59c8 100644 --- a/soft/thermostat/src/settings.cpp +++ b/soft/thermostat/src/settings.cpp @@ -117,6 +117,44 @@ Settings::Settings(QObject *parent) : QSettings(parent) m_broker.port = this->value("broker/port", 1883).toInt(); } +void Settings::setRoomDefaultTemperature(int idx, double temperature) +{ + if ((idx < 0) || (idx >= MAX_NB_ZONES)) { + // ERROR + return; + } + + this->beginWriteArray("rooms"); + this->setArrayIndex(idx); + this->setValue("default_temperature", temperature); + this->endArray(); + this->sync(); +} + +void Settings::setRoomPrograms(int idx, QVector &progs) +{ + if ((idx < 0) || (idx >= MAX_NB_ZONES)) { + // ERROR + return; + } + + this->beginWriteArray("rooms"); + + this->setArrayIndex(idx); + this->remove("temperature_schedule"); + this->beginWriteArray("temperature_schedule"); + for (int i = 0; i < progs.count(); i++) { + this->setArrayIndex(i); + this->setValue("temperature", progs.at(i).temperature); + this->setValue("days_of_week", progs.at(i).DoW); + this->setValue("start_time", progs.at(i).start_time.toString("H:m")); + this->setValue("end_time", progs.at(i).end_time.toString("H:m")); + } + this->endArray(); + this->endArray(); + this->sync(); +} + void Settings::setPowerState(enum power_states state) { switch (state) {