FemaLocalSoftware/getsensors_r.h

86 lines
2.5 KiB
C
Raw Normal View History

2024-12-16 08:38:04 +00:00
#ifndef GETSENSORS_R_H
#define GETSENSORS_R_H
2025-01-07 22:13:48 +00:00
#include <QJsonArray>
2024-12-16 08:38:04 +00:00
#include <QJsonDocument>
#include <QJsonObject>
#include <QList>
2025-01-07 22:13:48 +00:00
#include <QString>
2024-12-16 08:38:04 +00:00
2025-01-07 22:13:48 +00:00
class Sensor
{
2024-12-16 08:38:04 +00:00
public:
int alarmCooldown;
double alarmLowerBound;
double alarmUpperBound;
bool isBooled; // Поле из EXTRA
2025-01-07 22:13:48 +00:00
bool isHide; // Поле из EXTRA
2024-12-16 08:38:04 +00:00
QString group;
QString id;
bool isAlarmEnabled;
bool isEnabled;
double lastValue;
QString name;
QString unitName;
2025-01-07 22:13:48 +00:00
void parseSensor(const QJsonObject &sensorObj)
{
2024-12-16 08:38:04 +00:00
alarmCooldown = sensorObj["ALARM_COOLDOWN"].toInt();
alarmLowerBound = sensorObj["ALARM_LOWERBOUND"].toDouble();
alarmUpperBound = sensorObj["ALARM_UPPERBOUND"].toDouble();
// Обработка полей из EXTRA
QString extraString = sensorObj["EXTRA"].toString();
if (!extraString.isEmpty()) {
QJsonParseError parseError;
QJsonDocument extraDoc = QJsonDocument::fromJson(extraString.toUtf8(), &parseError);
if (parseError.error == QJsonParseError::NoError && extraDoc.isObject()) {
QJsonObject extraObj = extraDoc.object();
isBooled = extraObj.value("isBool").toBool(false);
isHide = extraObj.value("isHide").toBool(true); // Обратное значение "isHide"
} else {
isBooled = false;
isHide = false;
}
} else {
isBooled = false;
isHide = false;
}
group = sensorObj["GROUP"].toString();
id = sensorObj["ID"].toString();
isAlarmEnabled = sensorObj["IS_ALARM_ENABLED"].toBool();
isEnabled = sensorObj["IS_ENABLED"].toBool();
lastValue = sensorObj["LAST_VALUE"].toDouble();
name = sensorObj["NAME"].toString();
unitName = sensorObj["UNIT_NAME"].toString();
}
};
2025-01-07 22:13:48 +00:00
class GetSensorsR
{
2024-12-16 08:38:04 +00:00
public:
GetSensorsR() = default;
2025-01-07 22:13:48 +00:00
void parseResponse(const QJsonObject &responseObj)
{
2024-12-16 08:38:04 +00:00
if (responseObj.contains("sensors") && responseObj["sensors"].isArray()) {
QJsonArray sensorsArray = responseObj["sensors"].toArray();
2025-01-07 22:13:48 +00:00
for (const QJsonValue &value : sensorsArray) {
2024-12-16 08:38:04 +00:00
if (value.isObject()) {
Sensor sensor;
sensor.parseSensor(value.toObject());
sensors.append(sensor);
}
}
}
}
2025-01-07 22:13:48 +00:00
const QList<Sensor> &getSensors() const { return sensors; }
2024-12-16 08:38:04 +00:00
private:
QList<Sensor> sensors;
};
#endif // GETSENSORS_R_H