Added "list" command

This commit is contained in:
Shy 2024-08-02 17:07:08 +02:00
parent edbc155a59
commit 1262a24b21

11
wled
View file

@ -7,7 +7,7 @@
# License: CC0
print_usage() {
echo "Usage: $0 [f(nordcenter)|w(ohnzimmer)] [on|off|1-17 (preset number)|dump]"
echo "Usage: $0 [f(nordcenter)|w(ohnzimmer)] [on|off|1-17|list]"
}
if test $# -ne 2; then
@ -41,6 +41,15 @@ case "$2" in
[1-9]|[1-9][0-7])
api_resp=$(curl -s -4 --json "{'on':true,'ps':$2}" "http://$wled_host/json")
;;
l|list)
echo "Presets on $wled_host:"
curl -s -4 "http://$wled_host/presets.json" | \
# Split into lines. One line per preset.
sed --sandbox -n 's/"\([0-9]\{1,2\}\)"/\n"\1"/gp' | \
# Extract number and name. Append final newline.
sed --sandbox -n 's/^"\([0-9]\{1,2\}\)":.*"n":"\([[:print:]]*\)".*$/\1: \2/p; a\'
exit $?
;;
dump)
curl -s -4 -w '\n' "http://$wled_host/json"
exit 0