Files
HA-NerdFlows-Functions/weather/defiance.js

58 lines
1.4 KiB
JavaScript

let alerts = msg.payload.features
let tornado_possible = false
// Filter for Severe Thunderstorm Warnings
let ts = alerts.filter(function(alert) {
if (alert.properties &&
alert.properties.event === "Severe Thunderstorm Warning") {
return true
}
})
// Filter for Severe Thunderstorm Warnings with tornado detection
// that have a tornado possible parameter
let tstp = alerts.filter(function(alert) {
if (alert.properties &&
alert.properties.event === "Severe Thunderstorm Warning" &&
alert.properties.parameters &&
alert.properties.parameters.tornadoDetection &&
alert.properties.parameters.tornadoDetection.length > 0) {
let tornadoPossible = alert.properties.parameters.tornadoDetection[0]
return tornadoPossible === "POSSIBLE"
}
})
if (tstp.length > 0) {
tornado_possible = true
}
// Filter for Tornado Warnings
let tornado = alerts.filter(function(alert) {
if (alert.properties &&
alert.properties.event === "Tornado Warning") {
return true
}
})
// If there are any alerts, return them
let tstormMsg = {
"payload": {
"alerts": ts,
"count": ts.length,
"tornado_possible": tornado_possible
}
}
let tornadoWarnMsg = {
"payload": {
"alerts": tornado,
"count": tornado.length
}
}
node.send([tstormMsg,tornadoWarnMsg])
node.status({fill:'green',shape:'dot',text:'Alerts Updated'})