- cleaning, optimization\- added lowbat detection

This commit is contained in:
2026-05-14 18:56:25 +02:00
parent 5e4712503b
commit 798407fbf5
2 changed files with 43 additions and 29 deletions
+42 -24
View File
@@ -38,9 +38,7 @@ QStringList previsionList
"Temps stable"
};
QMap <QByteArray, QString> propertyList;
QMap <QByteArray, QString> precPropertyList;
QMap <QByteArray, double> propertiesValue;
QMap <QByteArray, QPair<QString, QByteArray>> propertyName
{
{"tempf", {"Température extérieure", "°C"}},
@@ -146,11 +144,11 @@ void Pws2mqtt::init()
//return QHttpServerResponse("text/plain", "Success\n");
});
for (auto [name, pair]: propertyName.asKeyValueRange())
/* for (auto [name, pair]: propertyName.asKeyValueRange())
{
propertyList[name].append(formatNotifString(pair, "0"));
debug (DEBUGMACRO, "Init " + name + " => " + propertyList[name], DEBUG);
}
}*/
}
void notify(QString notif, QString priority, QString inputPath, QString tag)
@@ -228,6 +226,8 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
#endif
QString notif = "";
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
QMap <QByteArray, QString> propertyList;
QMap <QByteArray, double> propertiesValue;
QString attachment = "";
QString tag = "";
double propertyValue = 0;
@@ -351,7 +351,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
QString msg = "";
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
propertiesValue[name] = round(mphTokmh(value.toFloat()) );
propertiesValue[name] = round(mphTokmh(value.toFloat()));
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue[name]) + " km/h", DEBUG);
@@ -365,7 +365,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
}else if (name == "rainin")
{
static double ecart;
quint8 raininPriority = 1;
quint8 raininPriority;
propertyValue = round(pair.second.toFloat()*100)/100.0;
if (propertyValue <= 0.01)
{
@@ -373,7 +373,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
ecart = 0.0001;
}else
{
raininPriority = 3;
raininPriority = 5;
ecart = 0.01;
}
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
@@ -442,16 +442,25 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
priority[name] = setPriority (priority[name], 5);
timeUV = timeUV.currentDateTime().addSecs(300);
propertiesValue[name] = propertyValue;
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
propertyList[name] = "- UV - " + QByteArray::number(propertyValue) + "\n";
}
debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
}else if (name == "solarradiation")
{
propertyValue = pair.second.toFloat()*100/100;
propertyValue = round(pair.second.toFloat()*100)/100.0;
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
propertiesValue[name] = round(pair.second.toFloat()*100/100);
debug (DEBUGMACRO, "solarradiations : " + QByteArray::number(propertyValue), DEBUG);
propertiesValue[name] = propertyValue;
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
}else if (name == "lowbat")
{
if (pair.second.toUInt() != 0)
{
priority[name] = 5;
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue;
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
}
}
}
debug(DEBUGMACRO, "propertyList[name] = " + propertyList[name], DEBUG);
@@ -491,7 +500,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
{
timer = QDateTime::currentDateTime();
start = true;
notif = listProperties2notify (propertyList, priority, 0);
notif = listProperties2notify (precPropertyList, propertyList, priority, 0);
notify (notif, priorityList[aPriority], attachment, tag);
precPropertyList = propertyList;
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", INFO);
@@ -502,24 +511,24 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
}
if (aPriority >= 3)
{
notif = "**ALERTES**\n" + listProperties2notify (propertyList, priority, 3);
notif = "**ALERTES**\n" + listProperties2notify (precPropertyList, propertyList, priority, 3);
precPropertyList = propertyList;
notify (notif, priorityList[aPriority], attachment, tag);
}
debug(DEBUGMACRO, "parseData: Returning", DEBUG);
}
QString listProperties2notify (const QMap <QByteArray, QString> &propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert)
QString listProperties2notify (const QMap <QByteArray, QString> &precPropertyList, const QMap <QByteArray, QString> &propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert)
{
static QHash <QByteArray, quint8> announced = {};
QString notif = "";
for (auto [name, value]: propertyList.asKeyValueRange())
for (auto [name, value]: propertyName.asKeyValueRange())
{
debug(DEBUGMACRO, "property : " + name + " value : " + value, DEBUG);
if (name != "prevision")
{
//if (precPropertyList.contains(name))
//{
debug(DEBUGMACRO, "property : " + name, DEBUG);
//if (name != "prevision")
//{
if (propertyList.contains(name))
{
//if (precPropertyList[name] != propertyList[name])
//{
if (minAlert == 0)
@@ -542,11 +551,20 @@ QString listProperties2notify (const QMap <QByteArray, QString> &propertyList,
}
}
//}
//}
debug(DEBUGMACRO, "Name = " + name + ", value = " + value, DEBUG);
}
}else if (precPropertyList.contains(name))
{
notif += precPropertyList[name];
debug(DEBUGMACRO, "notif : " + notif, DEBUG);
}
//}
}
/* if (propertyList.contains("prevision"))
{
notif += propertyList["prevision"];
}else if (precPropertyList.contains("prevision"))
{
notif += precPropertyList["prevision"];
}*/
return notif;
}
+1 -5
View File
@@ -45,10 +45,6 @@ class Pws2mqtt : public QObject
int newsockfd = 0;
QString inputPath = "/usr/local/share/pws2mqtt/fleche.png";
QString outputPath = "/tmp/pws2mqttFleche.png";
QList <QString> deviceProperties =
{
"ieeeAddress", "type", "dateutc", "softwaretype", "action", "realtime", "freq", "wh65batt", "wh25batt", "runtime"
};
void init();
void listeningHttp();
@@ -68,5 +64,5 @@ void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qre
double windChill(double airT, double vent);
double calculerHumidex(double temperature, double humiditeRelative);
void notify (QString notif, QString priority = "low", QString inputPath = "", QString tag = "");
QString listProperties2notify (const QMap<QByteArray, QString> &propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert = 0);
QString listProperties2notify (const QMap<QByteArray, QString> &precPropertyList, const QMap<QByteArray, QString> &propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert = 0);