// SPDX-License-Identifier: GPL-3.0-or-later /* * Qt mutizone MQTT thermostat * * Copyright (C) 2019 Richard Genoud * */ #include #include #define LOOP_SLEEP_TIME_S 5 #include "mqttclient.h" #include "settings.h" #include "backgroundloop.h" BackgroundLoop::BackgroundLoop() { } BackgroundLoop::~BackgroundLoop() { } void BackgroundLoop::onNewPowerState(enum power_states state) { m_pwr_state = state; } void BackgroundLoop::allHeatersOn(bool on) { MQTTClient *mc = MQTTClient::getInstance(); Settings *s = Settings::getInstance(); QString payload = on ? QString("on") : QString("off"); 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)); mc->publish_msg(h->ctrl_topic, payload); } } } void BackgroundLoop::run() { while (!isInterruptionRequested()) { switch (m_pwr_state) { case ON: allHeatersOn(true); break; case AUTO: /* TODO */ break; case OFF: /* fall */ default: allHeatersOn(false); break; } this->sleep(LOOP_SLEEP_TIME_S); } } /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */