From 82500bb0cb8938b07d9a5e5a33f9f9c732d2d571 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Sun, 30 Aug 2020 11:41:01 +0200 Subject: [PATCH] thermostat: save automatically holiday end date --- soft/thermostat/inc/settings.h | 5 +++-- soft/thermostat/src/mainwindow.cpp | 4 ++-- soft/thermostat/src/settings.cpp | 9 +++++++++ soft/thermostat/src/zoneitem.cpp | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/soft/thermostat/inc/settings.h b/soft/thermostat/inc/settings.h index d6b3832..1a52438 100644 --- a/soft/thermostat/inc/settings.h +++ b/soft/thermostat/inc/settings.h @@ -57,12 +57,12 @@ public: static Settings *getInstance(void); int nbZones(void); enum power_states getPowerState(void) { return m_state; } - void setPowerState(enum power_states state); + const QDateTime &getEndHoliday(void) { return m_end_holiday; } + void setEndHoliday(const QDateTime &endDate); QVector m_rooms; struct Brocker m_broker; - QDateTime m_end_holiday; private: explicit Settings(QObject *parent = Q_NULLPTR); @@ -73,6 +73,7 @@ private: int read_config(void); enum power_states m_state; + QDateTime m_end_holiday; }; #endif // SETTINGS_H diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp index 8402dc5..120aaac 100644 --- a/soft/thermostat/src/mainwindow.cpp +++ b/soft/thermostat/src/mainwindow.cpp @@ -207,7 +207,7 @@ void MainWindow::set_holiday_mode(QDateTime end_date) { Settings *s = Settings::getInstance(); - s->m_end_holiday = end_date; + s->setEndHoliday(end_date); apply_order_to_heaters(); } @@ -430,7 +430,7 @@ void MainWindow::apply_order_to_heaters(void) Settings *s = Settings::getInstance(); bool heating_order = false; - if (s->m_end_holiday > QDateTime::currentDateTime()) { + if (s->getEndHoliday() > QDateTime::currentDateTime()) { qDebug() << "Holiday mode => emit ALL_OFF order"; emit setAllHeatersOn(false); } else { diff --git a/soft/thermostat/src/settings.cpp b/soft/thermostat/src/settings.cpp index 40d5c21..23280ac 100644 --- a/soft/thermostat/src/settings.cpp +++ b/soft/thermostat/src/settings.cpp @@ -138,6 +138,15 @@ void Settings::setPowerState(enum power_states state) } } +void Settings::setEndHoliday(const QDateTime &endDate) +{ + if (endDate.isValid()) { + m_end_holiday = endDate; + this->setValue("end_holiday", m_end_holiday.toString(Qt::ISODate)); + } + /* else TODO: error */ +} + void Settings::set_rooms_default_config(void) { this->setValue("state", "auto"); diff --git a/soft/thermostat/src/zoneitem.cpp b/soft/thermostat/src/zoneitem.cpp index 4af79c9..d4a07b6 100644 --- a/soft/thermostat/src/zoneitem.cpp +++ b/soft/thermostat/src/zoneitem.cpp @@ -81,7 +81,7 @@ void ZoneItem::refresh(void) break; } - if (s->m_end_holiday > QDateTime::currentDateTime()) { + if (s->getEndHoliday() > QDateTime::currentDateTime()) { m_target_temperature = FORCE_OFF; }