From 4533f16649efd459bd71d7c61b5e07c168929a63 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 19 Aug 2019 20:28:18 +0200 Subject: [PATCH] Adds support for new Supervisor options (#10) * :sparkles: Adds support for new Supervisor options * :shirt: Make sure Supervisor debug calls are always retuning a boolean --- lib/supervisor.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/lib/supervisor.sh b/lib/supervisor.sh index 3b83ebc..c24050c 100644 --- a/lib/supervisor.sh +++ b/lib/supervisor.sh @@ -173,6 +173,34 @@ function bashio::supervisor.timezone() { fi } +# ------------------------------------------------------------------------------ +# Returns the current logging level of the Supervisor. +# +# Arguments: +# $1 Logging level to set (optional). +# ------------------------------------------------------------------------------ +function bashio::supervisor.logging() { + local logging=${1:-} + + bashio::log.trace "${FUNCNAME[0]}:" "$@" + + if bashio::var.has_value "${logging}"; then + logging=$(bashio::var.json logging "${logging}") + bashio::api.hassio POST /supervisor/options "${logging}" + bashio::cache.flush_all + else + bashio::supervisor 'supervisor.info.logging' '.logging' + fi +} + +# ------------------------------------------------------------------------------ +# Returns the ip address of the supervisor. +# ------------------------------------------------------------------------------ +function bashio::supervisor.ip_address() { + bashio::log.trace "${FUNCNAME[0]}" + bashio::supervisor 'supervisor.info.ip_address' '.ip_address' +} + # ------------------------------------------------------------------------------ # Returns the time to wait after boot in seconds. # @@ -193,6 +221,54 @@ function bashio::supervisor.wait_boot() { fi } +# ------------------------------------------------------------------------------ +# Returns if debug is enabled on the supervisor +# +# Arguments: +# $1 Set debug (optional). +# ------------------------------------------------------------------------------ +function bashio::supervisor.debug() { + local debug=${1:-} + + bashio::log.trace "${FUNCNAME[0]}:" "$@" + + if bashio::var.has_value "${debug}"; then + if bashio::var.true "${debug}"; then + debug=$(bashio::var.json debug "^true") + else + debug=$(bashio::var.json debug "^false") + fi + bashio::api.hassio POST /supervisor/options "${debug}" + bashio::cache.flush_all + else + bashio::supervisor 'supervisor.info.debug' '.debug // false' + fi +} + +# ------------------------------------------------------------------------------ +# Returns if debug block is enabled on the supervisor +# +# Arguments: +# $1 Set debug block (optional). +# ------------------------------------------------------------------------------ +function bashio::supervisor.debug_block() { + local debug=${1:-} + + bashio::log.trace "${FUNCNAME[0]}:" "$@" + + if bashio::var.has_value "${debug}"; then + if bashio::var.true "${debug}"; then + debug=$(bashio::var.json debug_block "^true") + else + debug=$(bashio::var.json debug_block "^false") + fi + bashio::api.hassio POST /supervisor/options "${debug}" + bashio::cache.flush_all + else + bashio::supervisor 'supervisor.info.debug_block' '.debug_block // false' + fi +} + # ------------------------------------------------------------------------------ # Returns a list of add-on slugs of the add-ons installed. # ------------------------------------------------------------------------------