added urgencies notifications
This commit is contained in:
+75
-14
@@ -38,6 +38,7 @@ QStringList previsionList
|
||||
"Temps stable"
|
||||
};
|
||||
|
||||
QHash <QByteArray, quint8> announced = {};
|
||||
QMap <QByteArray, QString> precPropertyList;
|
||||
QMap <QByteArray, QPair<QString, QByteArray>> propertyName
|
||||
{
|
||||
@@ -96,7 +97,8 @@ void Pws2mqtt::init()
|
||||
httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder)
|
||||
{
|
||||
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
|
||||
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);
|
||||
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
|
||||
propertiesValue[name] = propertyValue;
|
||||
if (propertyValue > 35)
|
||||
if (propertyValue > 35 and announced[name] != 5)
|
||||
{
|
||||
priority[name] = 4;
|
||||
}else if (propertyValue > 27)
|
||||
notify (notif, priorityList[5]);
|
||||
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")
|
||||
@@ -315,7 +322,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
||||
{
|
||||
QString msg = "";
|
||||
quint8 i;
|
||||
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
||||
//static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
||||
quint8 windPriority = 1;
|
||||
|
||||
propertiesValue[name] = round(mphTokmh(value.toFloat()));
|
||||
@@ -328,15 +335,23 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
||||
{
|
||||
msg = forceVent[i][1].toString();
|
||||
windPriority = forceVent[i][2].toUInt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
propertyList[name] = "- Vent - " + msg + " : " + QByteArray::number(propertiesValue[name]) + " Km/h\n";
|
||||
propertiesValue["forcevent"] = i;
|
||||
|
||||
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)
|
||||
@@ -357,7 +372,15 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
||||
|
||||
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);
|
||||
}else if (name == "rainin")
|
||||
@@ -382,6 +405,14 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
||||
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
||||
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(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);
|
||||
}else if (name == "dailyrainin")
|
||||
@@ -422,6 +453,17 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
||||
priority[name] = setPriority(priority[name], ret.urgency);
|
||||
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;
|
||||
debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
|
||||
}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())
|
||||
{
|
||||
//notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
|
||||
|
||||
if (propertyValue == 5 )
|
||||
priority[name] = setPriority (priority[name], 4);
|
||||
if (propertyValue >= 6 )
|
||||
priority[name] = setPriority (priority[name], 5);
|
||||
timeUV = timeUV.currentDateTime().addSecs(300);
|
||||
|
||||
propertiesValue[name] = propertyValue;
|
||||
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
||||
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);
|
||||
}else if (name == "solarradiation")
|
||||
@@ -455,9 +510,16 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
||||
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);
|
||||
if (announced[name] == priority[name])
|
||||
{
|
||||
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)
|
||||
{
|
||||
static QHash <QByteArray, quint8> announced = {};
|
||||
QString notif = "";
|
||||
for (auto [name, value]: propertyName.asKeyValueRange())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user