Allow fetching configuration parameters with a default value (#86)

This commit is contained in:
Franck Nijhof 2021-11-01 03:58:21 +01:00 committed by GitHub
parent 555dce69a9
commit 733ab52aca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,6 +15,7 @@
# ------------------------------------------------------------------------------
function bashio::config() {
local key=${1}
local default_value=${2:-}
local query
local result
@ -47,7 +48,14 @@ QUERY
options=$(bashio::addon.options)
result=$(bashio::jq "${options}" "${query}")
printf "%s" "${result}"
if [[ "${result}" == "null" ]] && bashio::var.has_value "${default_value}";
then
echo "${default_value}"
else
printf "%s" "${result}"
fi
return "${__BASHIO_EXIT_OK}"
}