Kstars

indiweather.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include <basedevice.h>
8 #include "indiweather.h"
9 #include "clientmanager.h"
10 
11 namespace ISD
12 {
13 
14 Weather::Weather(GenericDevice *parent) : ConcreteDevice(parent)
15 {
16 }
17 
18 void Weather::processLight(ILightVectorProperty *lvp)
19 {
20  if (!strcmp(lvp->name, "WEATHER_STATUS"))
21  {
22  Status currentStatus = static_cast<Status>(lvp->s);
23  if (currentStatus != m_WeatherStatus)
24  {
25  m_WeatherStatus = currentStatus;
26  emit newStatus(m_WeatherStatus);
27  }
28  }
29 }
30 
31 void Weather::processNumber(INumberVectorProperty *nvp)
32 {
33  if (nvp == nullptr)
34  return;
35 
36  if (!strcmp(nvp->name, "WEATHER_PARAMETERS"))
37  {
38  m_WeatherData.clear();
39 
40  // read all sensor values received
41  for (int i = 0; i < nvp->nnp; i++)
42  {
43  INumber number = nvp->np[i];
44  m_WeatherData.push_back({QString(number.name), QString(number.label), number.value});
45  }
46  emit newWeatherData(m_WeatherData);
47  }
48 }
49 
50 Weather::Status Weather::getWeatherStatus()
51 {
52  auto weatherLP = getLight("WEATHER_STATUS");
53 
54  if (!weatherLP)
55  return WEATHER_IDLE;
56 
57  m_WeatherStatus = static_cast<Status>(weatherLP->getState());
58 
59  return static_cast<Status>(weatherLP->getState());
60 }
61 
62 quint16 Weather::getUpdatePeriod()
63 {
64  auto updateNP = getNumber("WEATHER_UPDATE");
65 
66  if (!updateNP)
67  return 0;
68 
69  return static_cast<quint16>(updateNP->at(0)->getValue());
70 }
71 
72 bool Weather::refresh()
73 {
74  auto refreshSP = getSwitch("WEATHER_REFRESH");
75 
76  if (refreshSP == nullptr)
77  return false;
78 
79  auto refreshSW = refreshSP->findWidgetByName("REFRESH");
80 
81  if (refreshSW == nullptr)
82  return false;
83 
84  refreshSP->reset();
85  refreshSW->setState(ISS_ON);
86  sendNewSwitch(refreshSP);
87 
88  return true;
89 
90 }
91 }
92 
93 #ifndef KSTARS_LITE
94 QDBusArgument &operator<<(QDBusArgument &argument, const ISD::Weather::Status &source)
95 {
96  argument.beginStructure();
97  argument << static_cast<int>(source);
98  argument.endStructure();
99  return argument;
100 }
101 
102 const QDBusArgument &operator>>(const QDBusArgument &argument, ISD::Weather::Status &dest)
103 {
104  int a;
105  argument.beginStructure();
106  argument >> a;
107  argument.endStructure();
108  dest = static_cast<ISD::Weather::Status>(a);
109  return argument;
110 }
111 #endif
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
void push_back(QChar ch)
QDebug operator<<(QDebug d, const QCPVector2D &vec)
Definition: qcustomplot.h:450
void beginStructure()
void endStructure()
KIOCORE_EXPORT QString number(KIO::filesize_t size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:54 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.