File indexing completed on 2024-07-21 06:28:24

0001 /*
0002     SPDX-FileCopyrightText: 2015 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <QTimer>
0011 #include <QJsonDocument>
0012 
0013 #include "indiconcretedevice.h"
0014 
0015 namespace ISD
0016 {
0017 /**
0018  * @class Weather
0019  * Focuser class handles control of INDI Weather devices. It reports overall state and the value of each parameter
0020  *
0021  * @author Jasem Mutlaq
0022  */
0023 class Weather : public ConcreteDevice
0024 {
0025         Q_OBJECT
0026         Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.INDI.Weather")
0027         Q_PROPERTY(ISD::Weather::Status status READ status NOTIFY newStatus)
0028         Q_PROPERTY(int refreshPeriod READ refreshPeriod WRITE setRefreshPeriod)
0029         Q_PROPERTY(QByteArray data READ jsonData NOTIFY newJSONData)
0030 
0031     public:
0032         explicit Weather(GenericDevice *parent);
0033 
0034         typedef enum
0035         {
0036             WEATHER_IDLE,
0037             WEATHER_OK,
0038             WEATHER_WARNING,
0039             WEATHER_ALERT,
0040         } Status;
0041 
0042         void processNumber(INDI::Property prop) override;
0043         void processLight(INDI::Property prop) override;
0044 
0045         Status status();
0046 
0047         int refreshPeriod();
0048         void setRefreshPeriod(int value);
0049 
0050         bool refresh();
0051         const QJsonArray &data() const
0052         {
0053             return m_Data;
0054         }
0055         /**
0056          * @brief jsondata Used for DBus
0057          * @return Weahter data in JSON Format
0058          */
0059         QByteArray jsonData() const
0060         {
0061             return QJsonDocument(m_Data).toJson();
0062         }
0063 
0064     signals:
0065         void newStatus(ISD::Weather::Status status);
0066         void newData(const QJsonArray &data);
0067         void newJSONData(QByteArray data);
0068 
0069     private:
0070         Status m_WeatherStatus { WEATHER_IDLE };
0071         QJsonArray m_Data;
0072 };
0073 }
0074 
0075 #ifndef KSTARS_LITE
0076 Q_DECLARE_METATYPE(ISD::Weather::Status)
0077 QDBusArgument &operator<<(QDBusArgument &argument, const ISD::Weather::Status &source);
0078 const QDBusArgument &operator>>(const QDBusArgument &argument, ISD::Weather::Status &dest);
0079 #endif