From bc650bd3e322adbd441e28ecd7cf71d52f75a00b Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Tue, 14 Jan 2020 15:44:18 +0100 Subject: [PATCH] thermostat: add holiday mode --- soft/thermostat/inc/holiday_dlg.h | 13 ++++++++++++- soft/thermostat/inc/mainwindow.h | 7 ++++++- soft/thermostat/src/holiday_dlg.cpp | 23 ++++++++++++++++------- soft/thermostat/src/mainwindow.cpp | 30 ++++++++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/soft/thermostat/inc/holiday_dlg.h b/soft/thermostat/inc/holiday_dlg.h index e181fcc..060ce59 100644 --- a/soft/thermostat/inc/holiday_dlg.h +++ b/soft/thermostat/inc/holiday_dlg.h @@ -11,7 +11,8 @@ #include #include -#include +#include +#include class HolidayDlg : public QWidget { @@ -22,6 +23,16 @@ public: Qt::WindowFlags f = Qt::WindowFlags()); ~HolidayDlg(); +private: + QCalendarWidget m_cal; + +signals: + void close_holiday_dlg(void); + void holiday_mode(QDate end_date); + +private slots: + void validate_holiday_mode(void); + }; #endif // HOLIDAYDLG_H diff --git a/soft/thermostat/inc/mainwindow.h b/soft/thermostat/inc/mainwindow.h index fb5d65b..9895011 100644 --- a/soft/thermostat/inc/mainwindow.h +++ b/soft/thermostat/inc/mainwindow.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include "mqttclient.h" #include "zoneitem.h" @@ -36,6 +38,7 @@ private: QTimer *m_timer; BoostDlg *m_boost; MenuDlg *m_menu; + QDate m_end_holiday; QStackedWidget m_central_widget; void update_state_btn(enum power_states st); double get_target_temperature(int room_idx); @@ -52,7 +55,9 @@ private slots: void show_main(void); void show_menu(void); void boost_slot(int idx, struct boost_data &data); - void show_holiday_dlg(void); + void do_show_holiday_dlg(void); + void do_close_holiday_dlg(void); + void set_holiday_mode(QDate end_date); signals: void setAllHeatersOn(bool on); diff --git a/soft/thermostat/src/holiday_dlg.cpp b/soft/thermostat/src/holiday_dlg.cpp index 08ed152..57084ba 100644 --- a/soft/thermostat/src/holiday_dlg.cpp +++ b/soft/thermostat/src/holiday_dlg.cpp @@ -22,7 +22,11 @@ HolidayDlg::HolidayDlg(QWidget *parent, Qt::WindowFlags f) : { QVBoxLayout *middleLayout = new QVBoxLayout; QHBoxLayout *mainLayout = new QHBoxLayout; - QCalendarWidget *cal = new QCalendarWidget(this); + + m_cal.setGridVisible(true); + m_cal.setMinimumDate(QDate::currentDate()); + m_cal.setDateEditEnabled(false); + QSizePolicy *szPolicy = new QSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding, QSizePolicy::PushButton); @@ -42,14 +46,13 @@ HolidayDlg::HolidayDlg(QWidget *parent, Qt::WindowFlags f) : middleLayout->addWidget(ok_btn); middleLayout->addWidget(cancel_btn); - mainLayout->addWidget(cal); + mainLayout->addWidget(&m_cal); mainLayout->addLayout(middleLayout); - connect(cal, SIGNAL(clicked(void)), this, SIGNAL(show_holiday_dlg(void))); - connect(next_btn, SIGNAL(clicked(void)), cal, SLOT(showNextMonth(void))); - connect(prev_btn, SIGNAL(clicked(void)), cal, SLOT(showPreviousMonth(void))); -// connect(ok_btn, SIGNAL(clicked(void)), this, SIGNAL(closed(void))); -// connect(cancel_btn, SIGNAL(clicked(void)), this, SLOT(show_confirm_exit_dlg(void))); + connect(next_btn, SIGNAL(clicked(void)), &m_cal, SLOT(showNextMonth(void))); + connect(prev_btn, SIGNAL(clicked(void)), &m_cal, SLOT(showPreviousMonth(void))); + connect(ok_btn, SIGNAL(clicked(void)), this, SLOT(validate_holiday_mode(void))); + connect(cancel_btn, SIGNAL(clicked(void)), this, SIGNAL(close_holiday_dlg(void))); this->setLayout(mainLayout); @@ -59,5 +62,11 @@ HolidayDlg::~HolidayDlg() { } +void HolidayDlg::validate_holiday_mode(void) +{ + emit holiday_mode(m_cal.selectedDate()); + emit close_holiday_dlg(); +} + /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */ diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp index 59d0505..d9fa103 100644 --- a/soft/thermostat/src/mainwindow.cpp +++ b/soft/thermostat/src/mainwindow.cpp @@ -31,6 +31,8 @@ MainWindow::MainWindow(QWidget *parent) : m_boost = NULL; m_menu = NULL; + m_end_holiday = QDate::currentDate();; + Settings *s = Settings::getInstance(); for (int i = 0; i < s->nbZones(); i++) { @@ -150,12 +152,31 @@ void MainWindow::show_boost(void) m_central_widget.setCurrentWidget(m_boost); } -void MainWindow::show_holiday_dlg(void) +void MainWindow::do_show_holiday_dlg(void) { HolidayDlg *holiday_dlg = new HolidayDlg(this); m_central_widget.addWidget(holiday_dlg); m_central_widget.setCurrentWidget(holiday_dlg); + connect(holiday_dlg, SIGNAL(close_holiday_dlg(void)), this, SLOT(do_close_holiday_dlg(void))); + connect(holiday_dlg, SIGNAL(holiday_mode(QDate)), this, SLOT(set_holiday_mode(QDate))); +} + +void MainWindow::do_close_holiday_dlg(void) +{ + QWidget *current = m_central_widget.currentWidget(); + + if (current == NULL) + return; + + m_central_widget.removeWidget(current); + delete current; +} + +void MainWindow::set_holiday_mode(QDate end_date) +{ + m_end_holiday = end_date; + apply_order_to_heaters(); } void MainWindow::show_menu(void) @@ -163,7 +184,7 @@ void MainWindow::show_menu(void) m_menu = new MenuDlg(NULL); connect(m_menu, SIGNAL(closed(void)), this, SLOT(show_main(void))); - connect(m_menu, SIGNAL(show_holiday_dlg(void)), this, SLOT(show_holiday_dlg(void))); + connect(m_menu, SIGNAL(show_holiday_dlg(void)), this, SLOT(do_show_holiday_dlg(void))); m_central_widget.addWidget(m_menu); m_central_widget.setCurrentWidget(m_menu); @@ -373,6 +394,11 @@ void MainWindow::apply_order_to_heaters(void) { Settings *s = Settings::getInstance(); + if (m_end_holiday > QDate::currentDate()) { + qDebug() << "Holiday mode => emit ALL_OFF order"; + emit setAllHeatersOn(false); + } + switch (s->m_state) { case ON: qDebug() << "emit ALL_ON order";