-
Notifications
You must be signed in to change notification settings - Fork 0
/
ha_http.sh
53 lines (44 loc) · 1.02 KB
/
ha_http.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
http_is_available() {
local ip=$(get_ip "$deviceName")
if [ "$ip" == "0.0.0.0" ]; then
echo "NO"
return
fi
echo "YES"
}
http_is_playing() {
echo "YES"
}
http_lookup_cmd() {
local deviceName=$1
local cmd=$2
if [ "$cmd" == "__ON__" ]; then
cmd="On"
elif [ "$cmd" == "__OFF__" ]; then
cmd="off"
fi
echo "$cmd"
}
http_send() {
local deviceName=$1
shift
local cmd="$@"
local ip=$(get_ip "$deviceName")
if [ "$ip" == "0.0.0.0" ]; then
echo_log "http_send: corresponding IP not found"
return 1
fi
echo_log "http_send: Device found at $ip"
local cmd_exec=${deviceList["$deviceName|cmd"]}
if [ "x$cmd_exec" == "x" ]; then
cmd_exec="$cmd"
fi
cmd_exec=${cmd_exec//__IP__/$ip}
cmd_exec=${cmd_exec//__CMD__/$cmd}
echo_log "http_send: Requesting http: $ip$cmd_exec "
curl $ip$deviceURL$cmd_exec
}
export -f http_is_available
export -f http_lookup_cmd
export -f http_send
export -f http_is_playing