Skip to content

Commit

Permalink
Show output from curl when level is debug
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Oct 3, 2023
1 parent 6b0d67e commit 2842190
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions addon_meterstoha/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ for key in $event_keys ; do
value="$(bashio::config "${key}_event")"
event_conf="$key:$value"
event_matching="$event_matching""[[ \"\$1\" == \"${value/\"/\\\"}\" ]] && TARGET_OPT=--$key
"
"
# shellcheck disable=SC2089
events="$events ${value//\"/\\\"}"
fi
Expand Down Expand Up @@ -137,6 +137,16 @@ if bashio::config.true keep_output ; then
RUN_OPT="${RUN_OPT} --keep-output"
fi

function debug_output
{
# command 3>&1 1>&2 2>&3 | debug_output to show stderr only when debugging
if [ "${LOG_LEVEL}" == "debug" ] ; then
cat
else
cat > /dev/null
fi
}

cat > "$CONFIG_FILE" <<EOJSON
{
$config
Expand Down Expand Up @@ -173,7 +183,7 @@ echo "Generated script '$EXEC_EVENT_SH':"
cat "$EXEC_EVENT_SH"

echo "Test access to Home Assistant API (should show '{\"message\":\"API running.\"}'"
curl -X GET -H "Authorization: Bearer ${HA_TOKEN}" -H "Content-Type: application/json" "${HA_SERVER}/api/" 2>/dev/null
curl -X GET -H "Authorization: Bearer ${HA_TOKEN}" -H "Content-Type: application/json" "${HA_SERVER}/api/" 3>&1 1>&2 2>&3 | debug_output
echo ""

HAEVENT2EXEC=./haevent2exec.py
Expand Down

0 comments on commit 2842190

Please sign in to comment.