From 1f4f444bbc5a71e6cad04fad0cfcb1d5e886ecad Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Fri, 20 Oct 2023 18:29:55 -0400 Subject: [PATCH] Forgot a node from the sports flow --- sports/init.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 sports/init.js diff --git a/sports/init.js b/sports/init.js new file mode 100644 index 0000000..06ef7aa --- /dev/null +++ b/sports/init.js @@ -0,0 +1,41 @@ +const states = global.get('homeassistant.homeAssistant.states') +const team = flow.get("activeEvent", "diskCon") +const room = flow.get("activeRoom", "diskCon") + +if (team === 'No events today') { + node.status({ fill: "red", shape: "ring", text: "No events today" }) + node.done +} else { + const lowerTeam = team.toLowerCase() + const convertTeam = lowerTeam.replaceAll(" ", "_") + const sensor = "sensor." + convertTeam + const getInhibitSensor = "binary_sensor." + convertTeam + "_inhibit" + const inhibit = states[getInhibitSensor].state + const teamSensor = states[sensor] + const lowerRoom = room.toLowerCase() + const convertRoom = lowerRoom.replaceAll(" ","_") + const teamColors = teamSensor.attributes.team_colors + const oppColors = teamSensor.attributes.opponent_colors + + flow.set("team", convertTeam, "diskCon") + flow.set("inhibit", inhibit, "diskCon") + flow.set("teamSensor", teamSensor, "diskCon") + flow.set("room", convertRoom, "diskCon") + flow.set("teamColors", teamColors, "diskCon") + flow.set("oppColors", oppColors, "diskCon") + + let sendTeam = { + "payload": teamColors, + "topic": "teamColors" + } + + let sendOpp = { + "payload": oppColors, + "topic": "oppColors" + } + + node.send([[sendTeam,sendOpp]]) + + node.status({fill:"green",shape:"dot",text:"Team: " + team}) + node.log("Active sports team changed to " + team) +} \ No newline at end of file