Make area weather alerts reusable as a subflow
This commit is contained in:
@ -2,6 +2,12 @@ const severeWarningEvents = ["Severe Thunderstorm Warning","Destructive Severe T
|
||||
const tornadoWarningEvents = ["Tornado Warning","Radar Indicated Tornado Warning","Confirmed Tornado Warning","Tornado Emergency"]
|
||||
const tornadoWatchEvents = ["Tornado Watch"]
|
||||
const severeThunderstormWatchEvents = ["Severe Thunderstorm Watch"]
|
||||
const area = msg.area
|
||||
const mqttTopic = "weather/alerts/" + area
|
||||
const tstormTopic = mqttTopic + "/severe_thunderstorm_warning"
|
||||
const tornadoWarnTopic = mqttTopic + "/tornado_warning"
|
||||
const tornadoWatchTopic = mqttTopic + "/tornado_watch"
|
||||
const severeThunderstormWatchTopic = mqttTopic + "/severe_thunderstorm_watch"
|
||||
|
||||
let alerts = msg.payload.features
|
||||
let tornado_possible = false
|
||||
@ -88,13 +94,18 @@ let severe_thunderstorm_watch = alerts.filter(function(alert) {
|
||||
|
||||
// If there are any alerts, return them
|
||||
|
||||
let allAlerts = {
|
||||
"payload": msg.payload.features
|
||||
}
|
||||
|
||||
let tstormMsg = {
|
||||
"payload": {
|
||||
"alerts": ts,
|
||||
"count": ts.length,
|
||||
"tornado_possible": tornado_possible,
|
||||
"considerable_destructive": considerable_destructive
|
||||
}
|
||||
},
|
||||
"topic": tstormTopic
|
||||
}
|
||||
|
||||
let tornadoWarnMsg = {
|
||||
@ -102,22 +113,36 @@ let tornadoWarnMsg = {
|
||||
"alerts": tornado,
|
||||
"count": tornado.length,
|
||||
"confirmed": confirmed
|
||||
}
|
||||
},
|
||||
"topic": tornadoWarnTopic
|
||||
}
|
||||
|
||||
let tornadoWatchMsg = {
|
||||
"payload": {
|
||||
"alerts": tornado_watch,
|
||||
"count": tornado_watch.length
|
||||
}
|
||||
},
|
||||
"topic": tornadoWatchTopic
|
||||
}
|
||||
|
||||
let severeThunderstormWatchMsg = {
|
||||
"payload": {
|
||||
"alerts": severe_thunderstorm_watch,
|
||||
"count": severe_thunderstorm_watch.length
|
||||
},
|
||||
"topic": severeThunderstormWatchTopic
|
||||
}
|
||||
|
||||
// Create status message for node
|
||||
|
||||
let statusMsg = {
|
||||
"status": {
|
||||
"fill": "green",
|
||||
"shape": "dot",
|
||||
"text": alerts.length + " alerts processed at " + new Date().toLocaleString()
|
||||
}
|
||||
}
|
||||
|
||||
node.send([tstormMsg,tornadoWarnMsg,tornadoWatchMsg,severeThunderstormWatchMsg])
|
||||
node.status({fill:'green',shape:'dot',text:'Alerts Updated'})
|
||||
// Send messages to output nodes
|
||||
|
||||
node.send([allAlerts,tstormMsg,tornadoWarnMsg,tornadoWatchMsg,severeThunderstormWatchMsg,statusMsg])
|
Reference in New Issue
Block a user