// SPDX-License-Identifier: GPL-3.0-or-later
|
|
/*
|
|
* Qt mutizone MQTT thermostat
|
|
*
|
|
* Copyright (C) 2019 Richard Genoud
|
|
*
|
|
*/
|
|
|
|
#include <QTranslator>
|
|
#include <QSettings>
|
|
#include <QString>
|
|
|
|
#include "settings.h"
|
|
|
|
Settings *Settings::_singleton = NULL;
|
|
|
|
Settings::Settings(QObject *parent) : QSettings(parent)
|
|
{
|
|
struct Room room;
|
|
struct Heater heater;
|
|
int nb_rooms;
|
|
|
|
nb_rooms = this->beginReadArray("rooms");
|
|
if (nb_rooms > MAX_NB_ZONES) {
|
|
// TODO;
|
|
nb_rooms = MAX_NB_ZONES;
|
|
}
|
|
|
|
for (int i = 0; i < nb_rooms; ++i) {
|
|
this->setArrayIndex(i);
|
|
room.name = this->value("name", "").toString();
|
|
room.sensor_topic = this->value("sensor_topic", "").toString();
|
|
room.availability_topic = this->value("availability_topic", "").toString();
|
|
int size = this->beginReadArray("heaters");
|
|
for (int j = 0; j < size; ++j) {
|
|
this->setArrayIndex(j);
|
|
heater.ctrl_topic = this->value("control_topic", "").toString();
|
|
room.heaters << heater;
|
|
}
|
|
this->endArray();
|
|
m_rooms << room;
|
|
}
|
|
this->endArray();
|
|
m_broker.address = this->value("broker/address", "localhost").toString();
|
|
m_broker.port = this->value("broker/port", 1883).toInt();
|
|
}
|
|
|
|
int Settings::nbZones(void)
|
|
{
|
|
return m_rooms.size();
|
|
}
|
|
|
|
Settings::~Settings(void)
|
|
{
|
|
}
|
|
|
|
Settings *Settings::getInstance(void)
|
|
{
|
|
if (!_singleton) {
|
|
_singleton = new Settings();
|
|
}
|
|
|
|
return _singleton;
|
|
}
|
|
|
|
/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */
|
|
|
|
|