@@ -14,33 +14,41 @@ function log.error_or_warning() {
1414# Makes a call to the Home Assistant REST API.
1515#
1616# Arguments:
17- # $1 HTTP Method (GET/POST)
18- # $2 API Resource requested
19- # $3 In case of a POST method, this parameter is the JSON to POST (optional)
17+ # $1 HTTP Method (GET/POST)
18+ # $2 API Resource requested
19+ # $3 In case of a POST method, this parameter is the JSON to POST (optional)
20+ # In case of a GET method, this parameter is not present
21+ # $3/4 jq filter command (optional)
2022#
21- # Options (BEFORE arguments):
22- # -f <filter> jq filter command
23- # -s "Silent" Supress error message in case of a 404 Not found HTTP status code
24- # -w "Warning only" Log only warnings instead of errors
23+ # Options (after arguments):
24+ # -s "Silent" Supress error message in case of a 404 Not found HTTP status code
25+ # -w "Warning only" Log only warnings instead of errors
2526# ------------------------------------------------------------------------------
2627function api.core() {
28+ # read arguments
29+ local method=" ${1} " ; shift
30+ local resource=" /core/api/${1} " ; shift
31+ local data=" {}"
32+ if [[ " ${method} " = " POST" && -n " ${1++} " && " ${1:: 1} " != " -" ]]; then
33+ data=" ${1} " ; shift
34+ fi
35+ local filter=
36+ if [[ -n " ${1++} " && " ${1:: 1} " != " -" ]]; then
37+ filter=" ${1} " ; shift
38+ fi
39+
2740 # read options
2841 local OPTIND o
2942 local silent=
3043 local warning_only=
31- local filter=
32-
33- while getopts " :swf:" o; do
44+ while getopts " :sw" o; do
3445 case " ${o} " in
3546 s)
3647 silent=1
3748 ;;
3849 w)
3950 warning_only=1
4051 ;;
41- f)
42- filter=" $OPTARG "
43- ;;
4452 \? )
4553 bashio::log.error " Invalid option: -${OPTARG} "
4654 return " ${__BASHIO_EXIT_NOK} "
@@ -55,11 +63,6 @@ function api.core() {
5563 done
5664 shift $(( OPTIND- 1 ))
5765
58- # read arguments
59- local method=" ${1} "
60- local resource=" /core/api/${2} "
61- local data=" ${3:- {\} } "
62-
6366 local auth_header=' Authorization: Bearer'
6467 local response
6568 local status
0 commit comments