|
@ -8,12 +8,14 @@ |
|
|
|
|
|
|
|
|
#include <QtWidgets>
|
|
|
#include <QtWidgets>
|
|
|
#include <QPushButton>
|
|
|
#include <QPushButton>
|
|
|
|
|
|
#include <QDateTime>
|
|
|
#include <QTime>
|
|
|
#include <QTime>
|
|
|
#include <QDate>
|
|
|
#include <QDate>
|
|
|
#include <QtMath>
|
|
|
#include <QtMath>
|
|
|
#include <QLocale>
|
|
|
#include <QLocale>
|
|
|
#include <QVector>
|
|
|
#include <QVector>
|
|
|
|
|
|
|
|
|
|
|
|
#include "boost_dlg.h"
|
|
|
#include "mqttclient.h"
|
|
|
#include "mqttclient.h"
|
|
|
#include "zoneitem.h"
|
|
|
#include "zoneitem.h"
|
|
|
#include "settings.h"
|
|
|
#include "settings.h"
|
|
@ -28,7 +30,9 @@ MainWindow::MainWindow(QWidget *parent) : |
|
|
|
|
|
|
|
|
for (int i = 0; i < s->nbZones(); i++) { |
|
|
for (int i = 0; i < s->nbZones(); i++) { |
|
|
zone = new ZoneItem(s->m_rooms.at(i).name, this); |
|
|
zone = new ZoneItem(s->m_rooms.at(i).name, this); |
|
|
|
|
|
zone->m_zoneNameBtn.setProperty("idx", i); |
|
|
zone->m_target_temperature = get_target_temperature(i); |
|
|
zone->m_target_temperature = get_target_temperature(i); |
|
|
|
|
|
connect(&(zone->m_zoneNameBtn), SIGNAL(clicked()), this, SLOT(show_boost())); |
|
|
m_zones << zone; |
|
|
m_zones << zone; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -93,6 +97,36 @@ MainWindow::~MainWindow() |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::boost_slot(int idx, struct boost_data &data) |
|
|
|
|
|
{ |
|
|
|
|
|
qDebug() << "room " << m_zones.at(idx)->m_name << " new BOOST " << data.temperature << " end: " << data.end_date; |
|
|
|
|
|
|
|
|
|
|
|
m_zones.at(idx)->m_boost = data; |
|
|
|
|
|
|
|
|
|
|
|
apply_order_to_heaters(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::show_boost(void) |
|
|
|
|
|
{ |
|
|
|
|
|
QObject* obj = sender(); |
|
|
|
|
|
QVariant v; |
|
|
|
|
|
|
|
|
|
|
|
v = obj->property("idx"); |
|
|
|
|
|
if (!v.isValid()) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
int idx = v.toInt(); |
|
|
|
|
|
|
|
|
|
|
|
if ((idx < 0) || (idx >= MAX_NB_ZONES)) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
BoostDlg boost(idx, m_zones.at(idx)->m_name, m_zones.at(idx)->m_target_temperature, this); |
|
|
|
|
|
|
|
|
|
|
|
connect(&boost, SIGNAL(boost_changed(int, struct boost_data &)), this, SLOT(boost_slot(int, struct boost_data &))); |
|
|
|
|
|
boost.showFullScreen(); |
|
|
|
|
|
boost.exec(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void MainWindow::update_state_btn(enum power_states st) |
|
|
void MainWindow::update_state_btn(enum power_states st) |
|
|
{ |
|
|
{ |
|
|
switch (st) { |
|
|
switch (st) { |
|
@ -116,8 +150,9 @@ double MainWindow::get_target_temperature(int room_idx) |
|
|
Settings *s = Settings::getInstance(); |
|
|
Settings *s = Settings::getInstance(); |
|
|
const struct Room *r = NULL; |
|
|
const struct Room *r = NULL; |
|
|
const struct Program *p = NULL; |
|
|
const struct Program *p = NULL; |
|
|
|
|
|
const struct boost_data *b = NULL; |
|
|
double target = FORCE_OFF; |
|
|
double target = FORCE_OFF; |
|
|
QTime now = QTime::currentTime(); |
|
|
|
|
|
|
|
|
QDateTime now = QDateTime::currentDateTime(); |
|
|
uint8_t dow = QDate::currentDate().dayOfWeek(); |
|
|
uint8_t dow = QDate::currentDate().dayOfWeek(); |
|
|
|
|
|
|
|
|
if ((room_idx < 0) || (room_idx >= MAX_NB_ZONES)) { |
|
|
if ((room_idx < 0) || (room_idx >= MAX_NB_ZONES)) { |
|
@ -131,6 +166,18 @@ double MainWindow::get_target_temperature(int room_idx) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
|
|
|
* Check if there's a boost programmation |
|
|
|
|
|
*/ |
|
|
|
|
|
if (room_idx < m_zones.count()) { |
|
|
|
|
|
b = &(m_zones.at(room_idx)->m_boost); |
|
|
|
|
|
if (b->end_date.isValid() && (b->end_date > now)) { |
|
|
|
|
|
/* BOOST is active */ |
|
|
|
|
|
target = b->temperature; |
|
|
|
|
|
goto out; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
* dayOfWeek() returns 1 for monday, 7 for sunday. |
|
|
* dayOfWeek() returns 1 for monday, 7 for sunday. |
|
|
* so dow -= 1 gives 0 for monday, 6 for sunday. |
|
|
* so dow -= 1 gives 0 for monday, 6 for sunday. |
|
|
* And (1 << dow) gives the day of week as a bit field |
|
|
* And (1 << dow) gives the day of week as a bit field |
|
@ -147,17 +194,17 @@ double MainWindow::get_target_temperature(int room_idx) |
|
|
* Ex: from 10h to 18h |
|
|
* Ex: from 10h to 18h |
|
|
*/ |
|
|
*/ |
|
|
if (p->start_time < p->end_time) { |
|
|
if (p->start_time < p->end_time) { |
|
|
if ((now >= p->start_time) && (now < p->end_time)) { |
|
|
|
|
|
|
|
|
if ((now.time() >= p->start_time) && (now.time() < p->end_time)) { |
|
|
target = p->temperature; |
|
|
target = p->temperature; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
/*
|
|
|
/*
|
|
|
* Ex: from 22h to 6h |
|
|
* Ex: from 22h to 6h |
|
|
*/ |
|
|
*/ |
|
|
if (now >= p->start_time) { |
|
|
|
|
|
|
|
|
if (now.time() >= p->start_time) { |
|
|
target = p->temperature; |
|
|
target = p->temperature; |
|
|
} else { |
|
|
} else { |
|
|
if (now < p->end_time) { |
|
|
|
|
|
|
|
|
if (now.time() < p->end_time) { |
|
|
target = p->temperature; |
|
|
target = p->temperature; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|