From b6bd1496109886c98bfb8b221f35b0020a547efb Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Sat, 22 Mar 2025 23:16:16 -0400 Subject: [PATCH] User ID conversion subflow --- subflows/user-conversion.js | 54 +++++++++++++++++++++++++++++++++++++ subflows/user-id-list.js | 22 +++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 subflows/user-conversion.js create mode 100644 subflows/user-id-list.js diff --git a/subflows/user-conversion.js b/subflows/user-conversion.js new file mode 100644 index 0000000..d257403 --- /dev/null +++ b/subflows/user-conversion.js @@ -0,0 +1,54 @@ +// Get the user ID list from global context + +const users = global.get("userIDList","diskCon") + +// Initialize variables + +let userTrigger = {} +let userFirstName = {} +let userLastName = {} +let hassUserID = {} +let statusTxt = {} + +// Check if the user ID is in the payload or data + +if (msg.payload && msg.payload.context && msg.payload.context.user_id) { + userTrigger = msg.payload.context.user_id +} else if (msg.data && msg.data.context && msg.data.context.user_id) { + userTrigger = msg.data.context.user_id +} else { + userTrigger = "none" +} + +// Set the status message based on the user ID + +let successTxt = `User: ${users[userTrigger].firstName}` +let errorTxt = "User not found" + +if (userTrigger === "none") { + statusTxt = errorTxt +} else { + statusTxt = successTxt +} + +// Set the user's information in the message + +msg.user = users[userTrigger] + +// Create the status message + +let statusMsg = { + "status": { + "fill": "green", + "shape": "dot", + "text": `${statusTxt} at ${new Date().toLocaleString()}` + } +} + +// Send the message and status message to the output nodes + +if (userTrigger === "none") { + node.error("User not found") +} else { + node.send([msg,statusMsg]) +} \ No newline at end of file diff --git a/subflows/user-id-list.js b/subflows/user-id-list.js new file mode 100644 index 0000000..8135655 --- /dev/null +++ b/subflows/user-id-list.js @@ -0,0 +1,22 @@ +let userIDList = { + "c3909d27048140729f002aaef0391775": { + "shortName": "tony", + "firstName": "Tony", + "lastName": "Stork", + "hassUser": "tonystork" + }, + "f387a983651a4321a7411ff8cf36f949": { + "shortName": "tina", + "firstName": "Christina", + "lastName": "Stork", + "hassUser": "christinastork" + }, + "879b4c04e32841b3ad1d2763a11b4e70": { + "shortName": "kallen", + "firstName": "Kallen", + "lastName": "Stork", + "hassUser": "kallenstork" + } +} + +global.set("userIDList",userIDList,"diskCon") \ No newline at end of file