added urgencies notifications

This commit is contained in:
2026-05-15 00:58:37 +02:00
parent 282745899e
commit 06b7fe187c
+75 -14
View File
@@ -38,6 +38,7 @@ QStringList previsionList
"Temps stable" "Temps stable"
}; };
QHash <QByteArray, quint8> announced = {};
QMap <QByteArray, QString> precPropertyList; QMap <QByteArray, QString> precPropertyList;
QMap <QByteArray, QPair<QString, QByteArray>> propertyName QMap <QByteArray, QPair<QString, QByteArray>> propertyName
{ {
@@ -96,7 +97,8 @@ void Pws2mqtt::init()
httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder) httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder)
{ {
debug(DEBUGMACRO, "body " + request.url().toString(), WARNING); debug(DEBUGMACRO, "body " + request.url().toString(), WARNING);
responder.sendResponse(QHttpServerResponse("text/plain; charset=utf-8", "404 - Page non trouvée. Route par défaut.", QHttpServerResponder::StatusCode::NotFound)); responder.sendResponse(QHttpServerResponse static QHash <QByteArray, quint8> announced = {};
("text/plain; charset=utf-8", "404 - Page non trouvée. Route par défaut.", QHttpServerResponder::StatusCode::NotFound));
}); });
#else #else
httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder) httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder)
@@ -285,12 +287,17 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
//timeTemp = timeTemp.currentDateTime().addSecs(300); //timeTemp = timeTemp.currentDateTime().addSecs(300);
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue)); propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue; propertiesValue[name] = propertyValue;
if (propertyValue > 35) if (propertyValue > 35 and announced[name] != 5)
{ {
priority[name] = 4; notify (notif, priorityList[5]);
}else if (propertyValue > 27) announced[name] = 5;
}else if (propertyValue > 27 and announced[name] != 4)
{ {
priority[name] = 3; notify (notif, priorityList[4]);
announced[name] = 4;
}else
{
announced[name] = 0;
} }
} }
}else if (name == "humidity") }else if (name == "humidity")
@@ -315,7 +322,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
{ {
QString msg = ""; QString msg = "";
quint8 i; quint8 i;
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600); //static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
quint8 windPriority = 1; quint8 windPriority = 1;
propertiesValue[name] = round(mphTokmh(value.toFloat())); propertiesValue[name] = round(mphTokmh(value.toFloat()));
@@ -328,15 +335,23 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
{ {
msg = forceVent[i][1].toString(); msg = forceVent[i][1].toString();
windPriority = forceVent[i][2].toUInt(); windPriority = forceVent[i][2].toUInt();
break;
} }
} }
propertyList[name] = "- Vent - " + msg + " : " + QByteArray::number(propertiesValue[name]) + " Km/h\n"; propertyList[name] = "- Vent - " + msg + " : " + QByteArray::number(propertiesValue[name]) + " Km/h\n";
propertiesValue["forcevent"] = i; propertiesValue["forcevent"] = i;
if (i >= 5) if (i >= 5)
{ {
attachment = this->outputPath; if (announced[name] != windPriority)
{
notify (propertyList[name], priorityList[windPriority]);
announced[name] = windPriority;
break;
}
}else
{
announced[name] = 0;
} }
if (propertiesValue["forcevent"] != i) if (propertiesValue["forcevent"] != i)
@@ -357,7 +372,15 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
if (propertiesValue[name] > 50) if (propertiesValue[name] > 50)
{ {
priority[name] = qMax(priority[name], (quint8)4); if (announced[name] != 5)
{
notify (propertyList[name], priorityList[5]);
announced[name] = 5;
priority[name] = qMax(priority[name], (quint8)4);
}
}else
{
announced[name] = 0;
} }
debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG); debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
}else if (name == "rainin") }else if (name == "rainin")
@@ -382,6 +405,14 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue)); propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue; propertiesValue[name] = propertyValue;
if (announced[name] != raininPriority)
{
notify (propertyList[name], priorityList[raininPriority]);
announced[name] = raininPriority;
}
}else
{
announced[name] = 0;
} }
debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG); debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
}else if (name == "dailyrainin") }else if (name == "dailyrainin")
@@ -422,6 +453,17 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
priority[name] = setPriority(priority[name], ret.urgency); priority[name] = setPriority(priority[name], ret.urgency);
tag += ret.icons; tag += ret.icons;
if (priority[name] > 4)
{
if (announced[name] != priority[name])
{
notify (propertyList[name], priorityList[priority[name]]);
announced[name] = priority[name];
}
}else
{
announced[name] = 0;
}
propertyList["prevision"] = prevision; propertyList["prevision"] = prevision;
debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG); debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
}else if (name == "UV") }else if (name == "UV")
@@ -434,14 +476,27 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
if (compare (propertiesValue[name], propertyValue, 1) and timeUV < QDateTime::currentDateTime()) if (compare (propertiesValue[name], propertyValue, 1) and timeUV < QDateTime::currentDateTime())
{ {
//notif += formatNotifString (propertyName[name].first, propertyName[name].second , value); //notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
if (propertyValue == 5 ) if (propertyValue == 5 )
priority[name] = setPriority (priority[name], 4); priority[name] = setPriority (priority[name], 4);
if (propertyValue >= 6 ) if (propertyValue >= 6 )
priority[name] = setPriority (priority[name], 5); priority[name] = setPriority (priority[name], 5);
timeUV = timeUV.currentDateTime().addSecs(300);
propertiesValue[name] = propertyValue; propertiesValue[name] = propertyValue;
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
propertyList[name] = "- UV - " + QByteArray::number(propertyValue) + "\n"; propertyList[name] = "- UV - " + QByteArray::number(propertyValue) + "\n";
if (priority[name] > 4)
{
if (announced[name] != priority[name])
{
notify (propertyList[name], priorityList[priority[name]]);
announced[name] = priority[name];
}
}else
{
announced[name] = 0;
}
} }
debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG); debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
}else if (name == "solarradiation") }else if (name == "solarradiation")
@@ -455,9 +510,16 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
if (pair.second.toUInt() != 0) if (pair.second.toUInt() != 0)
{ {
priority[name] = 5; priority[name] = 5;
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue)); if (announced[name] == priority[name])
propertiesValue[name] = propertyValue; {
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); announced [name] = 5;
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue;
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
}
}else
{
announced [name] = 0;
} }
} }
} }
@@ -518,7 +580,6 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
QString listProperties2notify (const QMap <QByteArray, QString> &precPropertyList, 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 = ""; QString notif = "";
for (auto [name, value]: propertyName.asKeyValueRange()) for (auto [name, value]: propertyName.asKeyValueRange())
{ {