use for-loop instead of while/shift.
This commit is contained in:
parent
6f99f677e6
commit
f3dd1edb12
1 changed files with 8 additions and 10 deletions
18
wled
18
wled
|
@ -86,13 +86,13 @@ case "$arg_inst" in
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Parse and execute command argument against given instances.
|
# Parse and execute command argument against given instances.
|
||||||
while test $# -gt 0; do
|
for wled_host; do
|
||||||
case "$arg_cmnd" in
|
case "$arg_cmnd" in
|
||||||
on) # Switch on.
|
on) # Switch on.
|
||||||
api_resp=$(curl_send '{"on":true}' "http://$1/json")
|
api_resp=$(curl_send '{"on":true}' "http://$wled_host/json")
|
||||||
;;
|
;;
|
||||||
off) # Switch off.
|
off) # Switch off.
|
||||||
api_resp=$(curl_send '{"on":false}' "http://$1/json")
|
api_resp=$(curl_send '{"on":false}' "http://$wled_host/json")
|
||||||
;;
|
;;
|
||||||
-b|--brightness) # Set brightness.
|
-b|--brightness) # Set brightness.
|
||||||
if test -z "$arg_param"; then
|
if test -z "$arg_param"; then
|
||||||
|
@ -108,15 +108,15 @@ while test $# -gt 0; do
|
||||||
echo "Error: parameter for brightness is out of range." >&2
|
echo "Error: parameter for brightness is out of range." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
api_resp=$(curl_send "{'bri':$bright}" "http://$1/json")
|
api_resp=$(curl_send "{'bri':$bright}" "http://$wled_host/json")
|
||||||
;;
|
;;
|
||||||
[1-9]|1[0-7]) # Switch to preset.
|
[1-9]|1[0-7]) # Switch to preset.
|
||||||
api_resp=$(curl_send "{'ps':$arg_cmnd}" "http://$1/json")
|
api_resp=$(curl_send "{'ps':$arg_cmnd}" "http://$wled_host/json")
|
||||||
;;
|
;;
|
||||||
l|list) # List presets.
|
l|list) # List presets.
|
||||||
printf "loading ...\r"
|
printf "loading ...\r"
|
||||||
active_ps=$(active_preset "$1")
|
active_ps=$(active_preset "$wled_host")
|
||||||
curl_fetch "http://$1/presets.json" | \
|
curl_fetch "http://$wled_host/presets.json" | \
|
||||||
# Split into lines - one line per preset.
|
# Split into lines - one line per preset.
|
||||||
sed --sandbox 's/"1\?[0-9]"[[:space:]]*:/\n&/g' | \
|
sed --sandbox 's/"1\?[0-9]"[[:space:]]*:/\n&/g' | \
|
||||||
# Extract number and name of every preset. Right-align numbers.
|
# Extract number and name of every preset. Right-align numbers.
|
||||||
|
@ -130,7 +130,7 @@ while test $# -gt 0; do
|
||||||
# Sort.
|
# Sort.
|
||||||
sort -b -n | \
|
sort -b -n | \
|
||||||
# Prepend description and mark active preset.
|
# Prepend description and mark active preset.
|
||||||
sed --sandbox -e "1i\\Presets on $1:" \
|
sed --sandbox -e "1i\\Presets on $wled_host:" \
|
||||||
-e "s/^ \?$active_ps:.*/& */"
|
-e "s/^ \?$active_ps:.*/& */"
|
||||||
;;
|
;;
|
||||||
"") # Missing command.
|
"") # Missing command.
|
||||||
|
@ -155,7 +155,5 @@ while test $# -gt 0; do
|
||||||
if test -n "$api_resp" && echo "$api_resp" | grep -qv '{\s*"success"\s*:\s*true\s*}'; then
|
if test -n "$api_resp" && echo "$api_resp" | grep -qv '{\s*"success"\s*:\s*true\s*}'; then
|
||||||
echo "Warning: unexpected responce from WLED API." >&2
|
echo "Warning: unexpected responce from WLED API." >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shift
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue