From f5f5294410737c7f4c464e30fe08a999d7e51f0e Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Mon, 17 Sep 2018 20:37:02 -0400 Subject: [PATCH] feature: add support for upcoming device access notifications --- index.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a097b5e..d80fc1f 100644 --- a/index.js +++ b/index.js @@ -170,7 +170,7 @@ module.exports = function(app) { function handleNotificationDelta(app, id, notification, last_states) { - app.debug("notification: %O", notification) + //app.debug("notification: %O", notification) devices = readJson(app, "devices", id) @@ -252,10 +252,29 @@ function send_push(app, device, message, path, state) message = `${state.charAt(0).toUpperCase() + state.slice(1)}: ${message}` - aps = { 'aps': { 'alert': {'body': message}, 'sound': 'default' }, 'path': path } + aps = { 'aps': { 'alert': {'body': message}, 'sound': 'default' }, 'path': path, self: app.selfId } - aps["aps"]["category"] = path == "notifications.autopilot.PilotWayPointAdvance" - ? 'advance_waypoint' : (state === 'normal' ? "alarm_normal" : "alarm") + let category = (state === 'normal' ? "alarm_normal" : "alarm") + + if ( state != 'normal' ) + { + if ( path === "notifications.autopilot.PilotWayPointAdvance" ) + { + category = 'advance_waypoint' + } + else if ( path === 'notifications.anchorAlarm' || path === 'notifications.navigation.anchor') + { + category = 'anchor_alarm' + } + else if ( path.startsWith('notifications.security.accessRequest') ) + { + let parts = path.split('.') + let permissions = parts[parts.length-2] + category = `access_req_${permissions}` + } + } + + aps["aps"]["category"] = category var payload = { default: message,