Thermostat pour piloter jusqu'à 4 radiateurs avec fil pilote
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

104 lines
2.4 KiB

// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Qt mutizone MQTT thermostat
*
* Copyright (C) 2019 Richard Genoud
*
*/
#include <QtWidgets>
#include <QPushButton>
#include <QTime>
#include <QLocale>
#include <QVector>
#include "mqttclient.h"
#include "zoneitem.h"
#include "settings.h"
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
ZoneItem *zone;
Settings *s = Settings::getInstance();
mqttclient = new MQTTSubcriber(QHostAddress(s->m_broker.address), s->m_broker.port);
for (int i = 0; i < s->nbZones(); i++) {
zone = new ZoneItem(s->m_rooms.at(i).name, this);
m_zones << zone;
}
connect(mqttclient, SIGNAL(new_temperature(int, double)),
this, SLOT(temperature_slot(int, double)));
connect(mqttclient, SIGNAL(new_hygro(int, double)),
this, SLOT(hygro_slot(int, double)));
connect(mqttclient, SIGNAL(new_availability(int, bool)),
this, SLOT(availability_slot(int, bool)));
/*
* Sensors-related layout
*/
QGridLayout *mainLayout = new QGridLayout;
if (s->nbZones() < 4) {
// TODO
qDebug() << "bad configuration" ;
} else {
mainLayout->addWidget(m_zones.at(0), 0, 0);
mainLayout->addWidget(m_zones.at(1), 0, 1);
mainLayout->addWidget(new QPushButton(tr("Menu")), 0, 2);
mainLayout->addWidget(m_zones.at(2), 1, 0);
mainLayout->addWidget(m_zones.at(3), 1, 1);
mainLayout->addWidget(new QPushButton(tr("Auto")), 1, 2);
}
QWidget *mainWidget = new QWidget;
mainWidget->setLayout(mainLayout);
/*
* Top widget
*/
setCentralWidget(mainWidget);
setWindowTitle(tr("Sorico's thermostat"));
m_backLoop.start();
mqttclient->connectToHost();
}
MainWindow::~MainWindow()
{
}
void MainWindow::temperature_slot(int idx, double val)
{
Settings *s = Settings::getInstance();
qDebug() << "temperature idx:" << idx << " val: " << val << endl;
if (idx < s->nbZones()) {
m_zones.at(idx)->set_temperature_value(val);
}
}
void MainWindow::hygro_slot(int idx, double val)
{
Settings *s = Settings::getInstance();
qDebug() << "hygro idx:" << idx << " val: " << val << endl;
if (idx < s->nbZones()) {
m_zones.at(idx)->set_hygro_value(val);
}
}
void MainWindow::availability_slot(int idx, bool ok)
{
Settings *s = Settings::getInstance();
if ((idx < s->nbZones()) && !ok) {
m_zones.at(idx)->set_hygro_value(0);
m_zones.at(idx)->set_temperature_value(0);
}
}
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */