From 6ca19d2990bf267c9821404651ceefb1c5b5cfa0 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Sun, 8 Dec 2019 20:15:20 +0100 Subject: [PATCH] prepare zoneitem to show real values --- soft/thermostat/inc/mqttclient.h | 6 ++++++ soft/thermostat/inc/zoneitem.h | 11 +++++++++++ soft/thermostat/src/mqttclient.cpp | 24 +++++++++++++++++++++-- soft/thermostat/src/zoneitem.cpp | 40 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 77 insertions(+), 4 deletions(-) diff --git a/soft/thermostat/inc/mqttclient.h b/soft/thermostat/inc/mqttclient.h index 3704361..cce76f3 100644 --- a/soft/thermostat/inc/mqttclient.h +++ b/soft/thermostat/inc/mqttclient.h @@ -26,6 +26,12 @@ public slots: void onConnected(); void onSubscribed(const QString& topic); void onReceived(const QMQTT::Message& message); + +signals: + void new_temperature(unsigned idx, double val); + void new_hygro(unsigned idx, double val); + void new_battery(unsigned idx, double val); + void new_availability(unsigned idx, bool ok); }; #endif diff --git a/soft/thermostat/inc/zoneitem.h b/soft/thermostat/inc/zoneitem.h index bc05a1c..1338941 100644 --- a/soft/thermostat/inc/zoneitem.h +++ b/soft/thermostat/inc/zoneitem.h @@ -21,10 +21,21 @@ class ZoneItem : public QWidget public: explicit ZoneItem(const QString &zoneName, QWidget *parent = Q_NULLPTR); ~ZoneItem(); + + void set_temperature_value(double val); + void set_target_temperature(double val); + void set_hygro_value(double val); + private: QPushButton m_zoneNameBtn; QPushButton m_temperatureBtn; QPushButton m_hygroBtn; + + void refresh(void); + + double m_temperature_value; + double m_hygro_value; + double m_target_temperature; }; #endif // ZONEITEM_H diff --git a/soft/thermostat/src/mqttclient.cpp b/soft/thermostat/src/mqttclient.cpp index 759b4a0..dc5186a 100644 --- a/soft/thermostat/src/mqttclient.cpp +++ b/soft/thermostat/src/mqttclient.cpp @@ -43,6 +43,7 @@ void MQTTSubcriber::onSubscribed(const QString& topic) void MQTTSubcriber::onReceived(const QMQTT::Message& message) { QJsonDocument sensorData; + QJsonValue val; qDebug() << "publish received: \"" << QString::fromUtf8(message.payload()) << "\"" << " from: " << message.topic() << endl; @@ -56,12 +57,31 @@ void MQTTSubcriber::onReceived(const QMQTT::Message& message) goto out; } QJsonObject obj(sensorData.object()); - QJsonValue val = obj["temperature"]; + val = obj["temperature"]; + if (val.isDouble()) { + emit new_temperature(i, val.toDouble()); + qDebug() << val.toDouble() << endl; + } + + val = obj["humidity"]; + if (val.isDouble()) { + emit new_hygro(i, val.toDouble()); + qDebug() << val.toDouble() << endl; + } - qDebug() << val.toDouble() << endl; + val = obj["battery"]; + if (val.isDouble()) { + emit new_battery(i, val.toDouble()); + qDebug() << val.toDouble() << endl; + } break; } + + if (Settings::getInstance()->m_availability_topics.at(i) == message.topic()) { + + emit new_availability(i, message.payload() == QString("online").toUtf8()); + } } out: return; diff --git a/soft/thermostat/src/zoneitem.cpp b/soft/thermostat/src/zoneitem.cpp index 677a8cd..f162d01 100644 --- a/soft/thermostat/src/zoneitem.cpp +++ b/soft/thermostat/src/zoneitem.cpp @@ -19,11 +19,13 @@ ZoneItem::ZoneItem(const QString &zoneName, QWidget *parent) : { m_zoneNameBtn.setText(zoneName); m_zoneNameBtn.setFlat(true); - m_temperatureBtn.setText("20.3°C / 20°C"); m_temperatureBtn.setFlat(true); - m_hygroBtn.setText("45%h"); m_hygroBtn.setFlat(true); + m_temperature_value = 0; + m_hygro_value = 0; + m_target_temperature = 0; + /* * Layout for the left part of the window */ @@ -39,4 +41,38 @@ ZoneItem::~ZoneItem() { } +void ZoneItem::refresh(void) +{ + QString text; + + text += QString::number(m_temperature_value); + text += QString("°C / "); + text += QString::number(m_target_temperature); + text += QString("°C"); + + m_temperatureBtn.setText(text); + + text = QString::number(m_hygro_value); + text += QString("%h"); + m_hygroBtn.setText(text); +} + +void ZoneItem::set_temperature_value(double val) +{ + m_temperature_value = val; + refresh(); +} + +void ZoneItem::set_target_temperature(double val) +{ + m_target_temperature = val; + refresh(); +} + +void ZoneItem::set_hygro_value(double val) +{ + m_hygro_value = val; + refresh(); +} + /* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */