-
Notifications
You must be signed in to change notification settings - Fork 1
/
deconz.sh
82 lines (68 loc) · 2.04 KB
/
deconz.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
#
# deconz.sh
# Copyright © 2017-2024 Erik Baauw. All rights reserved.
#
# Shell library for interacting with a deCONZ gateway.
# ===== CONFIGURATION ==========================================================
# Set default values.
: ${deconz_verbose:=true}
: ${deconz_debug:=false}
# ===== LIGHT STATE ============================================================
# Power-on color temperature.
deconz_ct_poweron=366 # 2,732 Kelvin
# Light recipe color temperatures.
deconz_ct_relaxed=447 # 2,237 Kelvin
deconz_ct_read=346 # 2,890 Kelvin
deconz_ct_concentrate=233 # 4,292 Kelvin
deconz_ct_energize=156 # 6,410 Kelvin
# ===== UTILITY FUNCTIONS ======================================================
# Return quoted string from string.
# Usage: s=$(deconz_quote string)
function deconz_quote() {
[[ "${1}" == '"'*'"' ]] && echo "${1}" || echo "\"${1}\""
}
# Remove quotes from string; return unquoted string from string.
# Usage: s=$(deconz_unquote string)
function deconz_unquote() {
[[ "${1}" == '"'*'"' ]] && eval echo "${1}" || echo "${1}"
}
# Issue message on standard error
# Usage: _deconz_msg severity [-n] [-s] message...
function _deconz_msg() {
local start="${_deconz_host:-deconz.sh}: ${1}${1:+: }"
local nflag=
shift
if [ "${1}" == "-n" ] ; then
nflag="-n"
shift
fi
if [ "${1}" == "-s" ] ; then
start=
shift
fi
echo ${nflag} "${start}${*}" >&2
}
# Issue error message
# Usage: _deconz_error [-n|-s] message...
function _deconz_error() {
_deconz_msg error "${@}"
}
# Issue warning message
# Usage: _deconz_warn [-n|-s] message...
function _deconz_warn() {
_deconz_msg warning "${@}"
}
# Issue info message when ${deconz_verbose} true
# Usage: _deconz_info [-n|-s] message...
function _deconz_info() {
${deconz_verbose} && _deconz_msg "" "${@}"
}
# Issue debug message when ${deconz_debug} is true
# Usage: _deconz_debug [-n|-s] message...
function _deconz_debug() {
${deconz_debug} && _deconz_msg debug "${@}"
}
function deconz_restart() {
deconz -t 10 restart ${deconz_verbose:+-v}
}