Browse Source

thermostat: settings: use an accessor to get the room vector

This prepares for using also an accessor to set the target temperature
in the edit dialog
master
Richard Genoud 4 years ago
parent
commit
331e88e1ea
4 changed files with 18 additions and 19 deletions
  1. +2
    -1
      soft/thermostat/inc/settings.h
  2. +3
    -5
      soft/thermostat/src/edit_dlg.cpp
  3. +8
    -8
      soft/thermostat/src/mainwindow.cpp
  4. +5
    -5
      soft/thermostat/src/mqttclient.cpp

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

@ -60,8 +60,8 @@ public:
void setPowerState(enum power_states state);
const QDateTime &getEndHoliday(void) { return m_end_holiday; }
void setEndHoliday(const QDateTime &endDate);
const struct Room &getRoom(int idx) { return m_rooms.at(idx); }
QVector<struct Room> m_rooms;
struct Brocker m_broker;
private:
@ -74,6 +74,7 @@ private:
enum power_states m_state;
QDateTime m_end_holiday;
QVector<struct Room> m_rooms;
};
#endif // SETTINGS_H


+ 3
- 5
soft/thermostat/src/edit_dlg.cpp View File

@ -27,12 +27,10 @@
EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
Settings *s = Settings::getInstance();
const struct Room *r = NULL;
const struct Room r = s->getRoom(idx);
QString sheet;
r = &(s->m_rooms.at(idx));
QLabel *room_name = new QLabel(QString(tr("%1 default target:").arg(r->name)));
QLabel *room_name = new QLabel(QString(tr("%1 default target:").arg(r.name)));
QFont font = room_name->font();
font.setPointSize(12);
@ -46,7 +44,7 @@ EditDlg::EditDlg(int idx, QWidget *parent, Qt::WindowFlags f) : QWidget(parent,
m_idx = idx;
m_default_temperature.setDecimals(1);
m_default_temperature.setValue(r->default_temperature);
m_default_temperature.setValue(r.default_temperature);
m_default_temperature.setSingleStep(0.1);
m_default_temperature.setSuffix(" °C");


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

@ -36,7 +36,7 @@ MainWindow::MainWindow(QWidget *parent) :
Settings *s = Settings::getInstance();
for (int i = 0; i < s->nbZones(); i++) {
zone = new ZoneItem(s->m_rooms.at(i).name, this);
zone = new ZoneItem(s->getRoom(i).name, this);
zone->setProperty("idx", i);
zone->m_target_temperature = get_target_temperature(i);
connect(zone, SIGNAL(clicked()), this, SLOT(show_boost()));
@ -290,7 +290,7 @@ double MainWindow::get_target_temperature(int room_idx)
goto out;
}
r = &(s->m_rooms.at(room_idx));
r = &(s->getRoom(room_idx));
target = r->default_temperature;
if (!dow) {
goto out;
@ -387,14 +387,14 @@ void MainWindow::apply_automatic_state(void)
int i;
qDebug() << "apply auto state";
for (i = 0; i < s->m_rooms.count(); i++) {
const struct Room *r = &(s->m_rooms.at(i));
for (i = 0; i < s->nbZones(); i++) {
const struct Room r = s->getRoom(i);
m_zones.at(i)->m_heating_on = get_heater_order(i);
m_zones.at(i)->m_target_temperature = get_target_temperature(i);
m_zones.at(i)->refresh();
qDebug() << "room " << r->name;
for (int j = 0; j < r->heaters.count(); j++) {
const struct Heater *h = &(r->heaters.at(j));
qDebug() << "room " << r.name;
for (int j = 0; j < r.heaters.count(); j++) {
const struct Heater *h = &(r.heaters.at(j));
qDebug() << "heater " << h->ctrl_topic;
m_mqtt->publish_msg(h->ctrl_topic,
m_zones.at(i)->m_heating_on ? "1" : "0");
@ -450,7 +450,7 @@ void MainWindow::apply_order_to_heaters(void)
}
}
for (int i = 0; i < s->m_rooms.count(); i++) {
for (int i = 0; i < s->nbZones(); i++) {
m_zones.at(i)->refresh();
}
}


+ 5
- 5
soft/thermostat/src/mqttclient.cpp View File

@ -113,7 +113,7 @@ void MQTTClient::onReceived(const QByteArray &message, const QMqttTopicName &top
<< "\"" << " from: " << topic.name();
for (int i = 0; i < s->nbZones(); ++i) {
if (s->m_rooms.at(i).sensor_topic == topic.name()) {
if (s->getRoom(i).sensor_topic == topic.name()) {
qDebug() << "this is for us !";
sensorData = QJsonDocument::fromJson(message);
if (!sensorData.isObject()) {
@ -142,7 +142,7 @@ void MQTTClient::onReceived(const QByteArray &message, const QMqttTopicName &top
break;
}
if (s->m_rooms.at(i).availability_topic == topic.name()) {
if (s->getRoom(i).availability_topic == topic.name()) {
emit new_availability(i, message == QString("online").toUtf8());
}
@ -178,9 +178,9 @@ void MQTTClient::allHeatersOn(bool on) {
QString payload = on ? QString("1") : QString("0");
for (int i = 0; i < s->nbZones(); i++) {
const struct Room *r = &(s->m_rooms.at(i));
for (int j = 0; j < r->heaters.count(); j++) {
const struct Heater *h = &(r->heaters.at(j));
const struct Room r = s->getRoom(i);
for (int j = 0; j < r.heaters.count(); j++) {
const struct Heater *h = &(r.heaters.at(j));
publish_msg(h->ctrl_topic, payload);
}


Loading…
Cancel
Save