Browse Source

thermostat: save automatically the wanted heater state

The general power state wasn't saved, it is now.
master
Richard Genoud 4 years ago
parent
commit
aedcdacd47
4 changed files with 35 additions and 10 deletions
  1. +5
    -1
      soft/thermostat/inc/settings.h
  2. +7
    -7
      soft/thermostat/src/mainwindow.cpp
  3. +21
    -0
      soft/thermostat/src/settings.cpp
  4. +2
    -2
      soft/thermostat/src/zoneitem.cpp

+ 5
- 1
soft/thermostat/inc/settings.h View File

@ -56,10 +56,12 @@ class Settings : public QSettings
public:
static Settings *getInstance(void);
int nbZones(void);
enum power_states getPowerState(void) { return m_state; }
void setPowerState(enum power_states state);
QVector<struct Room> m_rooms;
struct Brocker m_broker;
enum power_states m_state;
QDateTime m_end_holiday;
private:
@ -69,6 +71,8 @@ private:
void set_rooms_default_config(void);
int read_config(void);
enum power_states m_state;
};
#endif // SETTINGS_H


+ 7
- 7
soft/thermostat/src/mainwindow.cpp View File

@ -63,7 +63,7 @@ MainWindow::MainWindow(QWidget *parent) :
mainLayout->addWidget(m_zones.at(3), 1, 1);
mainLayout->addWidget(m_state_btn, 1, 2);
}
update_state_btn(s->m_state);
update_state_btn(s->getPowerState());
QSizePolicy *szPolicy = new QSizePolicy(QSizePolicy::Minimum,
QSizePolicy::MinimumExpanding,
@ -406,21 +406,21 @@ void MainWindow::change_state(void)
{
Settings *s = Settings::getInstance();
switch (s->m_state) {
switch (s->getPowerState()) {
case OFF:
s->m_state = ON;
s->setPowerState(ON);
break;
case ON:
s->m_state = AUTO;
s->setPowerState(AUTO);
break;
case AUTO:
/* fall through */
default:
s->m_state = OFF;
s->setPowerState(OFF);
break;
}
update_state_btn(s->m_state);
update_state_btn(s->getPowerState());
apply_order_to_heaters();
}
@ -434,7 +434,7 @@ void MainWindow::apply_order_to_heaters(void)
qDebug() << "Holiday mode => emit ALL_OFF order";
emit setAllHeatersOn(false);
} else {
switch (s->m_state) {
switch (s->getPowerState()) {
case AUTO:
qDebug() << "apply AUTO state";
apply_automatic_state();


+ 21
- 0
soft/thermostat/src/settings.cpp View File

@ -117,6 +117,27 @@ Settings::Settings(QObject *parent) : QSettings(parent)
m_broker.port = this->value("broker/port", 1883).toInt();
}
void Settings::setPowerState(enum power_states state)
{
switch (state) {
case OFF:
m_state = OFF;
this->setValue("state", "off");
break;
case ON:
m_state = ON;
this->setValue("state", "on");
break;
case AUTO:
m_state = AUTO;
this->setValue("state", "auto");
break;
default:
/* TODO: error */
break;
}
}
void Settings::set_rooms_default_config(void)
{
this->setValue("state", "auto");


+ 2
- 2
soft/thermostat/src/zoneitem.cpp View File

@ -68,7 +68,7 @@ void ZoneItem::refresh(void)
QString text;
Settings *s = Settings::getInstance();
switch (s->m_state) {
switch (s->getPowerState()) {
case OFF:
m_target_temperature = FORCE_OFF;
break;
@ -89,7 +89,7 @@ void ZoneItem::refresh(void)
/* Temperature */
text += QString("<center><b>");
if (((s->m_state == AUTO) && m_heating_on) || (s->m_state == FORCE_ON)) {
if (((s->getPowerState() == AUTO) && m_heating_on) || (s->getPowerState() == FORCE_ON)) {
text += QString("<font color='red'>");
} else {
text += QString("<font color='black'>");


Loading…
Cancel
Save