⬆️ Upgrades Hass.io API to be compatible with Supervisor v103 (#1)

This commit is contained in:
Franck Nijhof 2018-05-10 10:32:50 +02:00 committed by GitHub
parent 88ec9f2a3d
commit 304092599a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 763 additions and 258 deletions

View file

@ -2,7 +2,8 @@
# ==============================================================================
# Community Hass.io Add-ons: Bash functions library
#
# Provides functions for reading the add-on configuration
# Provides basic functions for reading the current add-on configuration.
# For more advances options, use the hass.addons.* functions
# ==============================================================================
# ==============================================================================

View file

@ -15,12 +15,12 @@ readonly HASS_API_ENDPOINT='http://hassio'
# ==============================================================================
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/addons.sh
source "${__LIB_DIR}/modules/api/addons.sh"
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/hardware.sh
source "${__LIB_DIR}/modules/api/hardware.sh"
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/homeassistant.sh
source "${__LIB_DIR}/modules/api/homeassistant.sh"
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/host.sh
source "${__LIB_DIR}/modules/api/host.sh"
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/network.sh
source "${__LIB_DIR}/modules/api/network.sh"
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/snapshots.sh
source "${__LIB_DIR}/modules/api/snapshots.sh"
# shellcheck source=base/rootfs/usr/lib/hassio-addons/modules/api/supervisor.sh

View file

@ -190,20 +190,6 @@ hass.api.addons.info.long_description() {
hass.api.addons.info "${addon}" ".long_description"
}
# ------------------------------------------------------------------------------
# Returns the version of an add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Version of the add-on
# ------------------------------------------------------------------------------
hass.api.addons.info.version() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".version"
}
# ------------------------------------------------------------------------------
# Returns whether or not auto update is enabled for this add-on
#
@ -218,6 +204,34 @@ hass.api.addons.info.auto_update() {
hass.api.addons.info "${addon}" ".auto_update // false"
}
# ------------------------------------------------------------------------------
# Returns the URL of an add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# URL of the add-on
# ------------------------------------------------------------------------------
hass.api.addons.info.url() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".url"
}
# ------------------------------------------------------------------------------
# Returns whether or not the add-on is running deattached
#
# Arguments:
# $1 Add-on slug
# Returns:
# Whether or not the add-on is running deattached
# ------------------------------------------------------------------------------
hass.api.addons.info.detached() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".detached // false"
}
# ------------------------------------------------------------------------------
# Returns the repository slug of an add-on
#
@ -232,6 +246,20 @@ hass.api.addons.info.repository() {
hass.api.addons.info "${addon}" ".repository"
}
# ------------------------------------------------------------------------------
# Returns the version of an add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Version of the add-on
# ------------------------------------------------------------------------------
hass.api.addons.info.version() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".version"
}
# ------------------------------------------------------------------------------
# Returns the latest version of an add-on
#
@ -274,34 +302,6 @@ hass.api.addons.info.boot() {
hass.api.addons.info "${addon}" ".boot"
}
# ------------------------------------------------------------------------------
# Returns the URL of an add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# URL of the add-on
# ------------------------------------------------------------------------------
hass.api.addons.info.url() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".url"
}
# ------------------------------------------------------------------------------
# Returns whether or not the add-on is running deattached
#
# Arguments:
# $1 Add-on slug
# Returns:
# Whether or not the add-on is running deattached
# ------------------------------------------------------------------------------
hass.api.addons.info.detached() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".detached // false"
}
# ------------------------------------------------------------------------------
# Returns whether or not this add-on is being build locally
#
@ -316,6 +316,20 @@ hass.api.addons.info.build() {
hass.api.addons.info "${addon}" ".build // false"
}
# ------------------------------------------------------------------------------
# Returns options for this add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# JSON ojbect
# ------------------------------------------------------------------------------
hass.api.addons.info.boot() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".options[]"
}
# ------------------------------------------------------------------------------
# Returns a list of ports which are exposed on the host network for this add-on
#
@ -386,6 +400,34 @@ hass.api.addons.info.privileged() {
hass.api.addons.info "${addon}" ".privileged // empty"
}
# ------------------------------------------------------------------------------
# Returns the current seccomp state of this add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Seccomp state: disable, default or profile
# ------------------------------------------------------------------------------
hass.api.addons.info.seccomp() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".seccomp"
}
# ------------------------------------------------------------------------------
# Returns the current apparmor state of this add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Seccomp state: disable, default or profile
# ------------------------------------------------------------------------------
hass.api.addons.info.apparmor() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".apparmor"
}
# ------------------------------------------------------------------------------
# Returns a list devices made available to the add-on
#
@ -414,6 +456,20 @@ hass.api.addons.info.auto_uart() {
hass.api.addons.info "${addon}" ".auto_uart // false"
}
# ------------------------------------------------------------------------------
# Returns whether or not this add-on has a icon available
#
# Arguments:
# $1 Add-on slug
# Returns:
# Whether or not this add-on has a icon available
# ------------------------------------------------------------------------------
hass.api.addons.info.icon() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".icon // false"
}
# ------------------------------------------------------------------------------
# Returns whether or not this add-on has a logo available
#
@ -442,34 +498,6 @@ hass.api.addons.info.changelog() {
hass.api.addons.info "${addon}" ".changelog // false"
}
# ------------------------------------------------------------------------------
# A URL for web interface of this add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# The webui URL of the add-on
# ------------------------------------------------------------------------------
hass.api.addons.info.webui() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".webui // empty"
}
# ------------------------------------------------------------------------------
# Returns whether or not this add-on can use the STDIN on the Hass.io API
#
# Arguments:
# $1 Add-on slug
# Returns:
# Whether or not this add-on can use the STDIN
# ------------------------------------------------------------------------------
hass.api.addons.info.stdin() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".stdin // false"
}
# ------------------------------------------------------------------------------
# Returns whether or not this add-on can access the Hass.io API
#
@ -498,6 +526,34 @@ hass.api.addons.info.homeassistant_api() {
hass.api.addons.info "${addon}" ".homeassistant_api // false"
}
# ------------------------------------------------------------------------------
# Returns whether or not this add-on can use the STDIN on the Hass.io API
#
# Arguments:
# $1 Add-on slug
# Returns:
# Whether or not this add-on can use the STDIN
# ------------------------------------------------------------------------------
hass.api.addons.info.stdin() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".stdin // false"
}
# ------------------------------------------------------------------------------
# A URL for web interface of this add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# The webui URL of the add-on
# ------------------------------------------------------------------------------
hass.api.addons.info.webui() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".webui // empty"
}
# ------------------------------------------------------------------------------
# Returns whether or not this add-on can access GPIO
#
@ -554,6 +610,34 @@ hass.api.addons.info.audio_output() {
hass.api.addons.info "${addon}" ".audio_output // empty"
}
# ------------------------------------------------------------------------------
# Returns the available services for an add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# The available services for this add-on
# ------------------------------------------------------------------------------
hass.api.addons.info.services() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".services // empty"
}
# ------------------------------------------------------------------------------
# Returns the available discovery items for an add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# The available discovery items for this add-on
# ------------------------------------------------------------------------------
hass.api.addons.info.discovery() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.info "${addon}" ".discovery // empty"
}
# ------------------------------------------------------------------------------
# Install an add-on onto your Hass.io instance
#
@ -690,3 +774,116 @@ hass.api.addons.update_available() {
return "${EX_OK}"
}
# ------------------------------------------------------------------------------
# List all available stats about add-ons
#
# Arguments:
# $1 Add-on slug
# $2 jq Filter to apply on the result (optional)
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.addons.stats() {
local addon=${1}
local filter=${2:-}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.call GET GET "/addons/${addon}/logs" false "${filter}"
}
# ------------------------------------------------------------------------------
# Returns CPU usage from add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Usage in percent
# ------------------------------------------------------------------------------
hass.api.addons.stats.cpu_percent() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.stats "${addon}" ".cpu_percent"
}
# ------------------------------------------------------------------------------
# Returns memory usage from add-on
# Arguments:
# $1 Add-on slug
# Returns:
# Usage in Mb
# ------------------------------------------------------------------------------
hass.api.addons.stats.memory_usage() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.stats "${addon}" ".memory_usage"
}
# ------------------------------------------------------------------------------
# Returns memory limit from add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Usage in Mb
# ------------------------------------------------------------------------------
hass.api.addons.stats.memory_limit() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.stats "${addon}" ".memory_limit"
}
# ------------------------------------------------------------------------------
# Returns outgoing network usage from add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Usage in Mb
# ------------------------------------------------------------------------------
hass.api.addons.stats.network_tx() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.stats "${addon}" ".network_tx"
}
# ------------------------------------------------------------------------------
# Returns incoming network usage from add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Usage in Bytes
# ------------------------------------------------------------------------------
hass.api.addons.stats.network_rx() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.stats "${addon}" ".network_rx"
}
# ------------------------------------------------------------------------------
# Returns disk read usage from add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Usage in Blocks
# ------------------------------------------------------------------------------
hass.api.addons.stats.blk_read() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.stats "${addon}" ".blk_read"
}
# ------------------------------------------------------------------------------
# Returns disk write usage from add-on
#
# Arguments:
# $1 Add-on slug
# Returns:
# Usage in Blocks
# ------------------------------------------------------------------------------
hass.api.addons.stats.blk_write() {
local addon=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.addons.stats "${addon}" ".blk_write"
}

View file

@ -0,0 +1,102 @@
#!/usr/bin/env bash
# ==============================================================================
# Community Hass.io Add-ons: Bash functions library
#
# Provides access to the API functions of Hass.io: Hardware
# ==============================================================================
# ==============================================================================
# FUNCTIONS
# ==============================================================================
# ------------------------------------------------------------------------------
# Returns a list of available hardware on the host system
#
# Arguments:
# None
# Returns:
# JSON object with hardware
# ------------------------------------------------------------------------------
hass.api.hardware.info() {
local filter=${1:-}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.call GET /hardware/info false "${filter}"
}
# ------------------------------------------------------------------------------
# Returns a list of available serial devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.hardware.info.serial() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.hardware.info ".serial[]"
}
# ------------------------------------------------------------------------------
# Returns a list of available input devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.hardware.info.input() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.hardware.info ".input[]"
}
# ------------------------------------------------------------------------------
# Returns a list of available disk devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.hardware.info.disk() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.hardware.info ".disk[]"
}
# ------------------------------------------------------------------------------
# Returns a list of available disk devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.hardware.info.gpio() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.hardware.info ".gpio[]"
}
# ------------------------------------------------------------------------------
# Returns a list of available audio hardware devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.hardware.info.audio() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.hardware.info ".audio[]"
}
# ------------------------------------------------------------------------------
# Returns a list of available audio devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.hardware.audio() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.call GET /hardware/audio false ".audio[]"
}

View file

@ -127,6 +127,19 @@ hass.api.homeassistant.info.watchdog() {
hass.api.homeassistant.info ".watchdog // false"
}
# ------------------------------------------------------------------------------
# Returns the Home Assistant start up time
#
# Arguments:
# None
# Returns:
# Time in seconds
# ------------------------------------------------------------------------------
hass.api.homeassistant.info.startup_time() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.homeassistant.info ".startup_time"
}
# ------------------------------------------------------------------------------
# Updates Home Assistant to the latest version
#
@ -204,3 +217,107 @@ hass.api.homeassistant.logs() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.call GET /homeassistant/logs true
}
# ------------------------------------------------------------------------------
# List all available stats about Home Assistant
#
# Arguments:
# $1 jq Filter to apply on the result (optional)
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.homeassistant.stats() {
local filter=${1:-}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.call GET /homeassistant/stats false "${filter}"
}
# ------------------------------------------------------------------------------
# Returns CPU usage from Home Assistant
#
# Arguments:
# None
# Returns:
# Usage in percent
# ------------------------------------------------------------------------------
hass.api.homeassistant.stats.cpu_percent() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.homeassistant.stats ".cpu_percent"
}
# ------------------------------------------------------------------------------
# Returns memory usage from Home Assistant
# Arguments:
# None
# Returns:
# Usage in Mb
# ------------------------------------------------------------------------------
hass.api.homeassistant.stats.memory_usage() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.homeassistant.stats ".memory_usage"
}
# ------------------------------------------------------------------------------
# Returns memory limit from Home Assistant
#
# Arguments:
# None
# Returns:
# Usage in Mb
# ------------------------------------------------------------------------------
hass.api.homeassistant.stats.memory_limit() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.homeassistant.stats ".memory_limit"
}
# ------------------------------------------------------------------------------
# Returns outgoing network usage from Home Assistant
#
# Arguments:
# None
# Returns:
# Usage in Mb
# ------------------------------------------------------------------------------
hass.api.homeassistant.stats.network_tx() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.homeassistant.stats ".network_tx"
}
# ------------------------------------------------------------------------------
# Returns incoming network usage from Home Assistant
#
# Arguments:
# None
# Returns:
# Usage in Bytes
# ------------------------------------------------------------------------------
hass.api.homeassistant.stats.network_rx() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.homeassistant.stats ".network_rx"
}
# ------------------------------------------------------------------------------
# Returns disk read usage from Home Assistant
#
# Arguments:
# None
# Returns:
# Usage in Blocks
# ------------------------------------------------------------------------------
hass.api.homeassistant.stats.blk_read() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.homeassistant.stats ".blk_read"
}
# ------------------------------------------------------------------------------
# Returns disk write usage from Home Assistant
#
# Arguments:
# None
# Returns:
# Usage in Blocks
# ------------------------------------------------------------------------------
hass.api.homeassistant.stats.blk_write() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.homeassistant.stats ".blk_write"
}

View file

@ -23,6 +23,71 @@ hass.api.host.info() {
hass.api.call GET /host/info false "${filter}"
}
# ------------------------------------------------------------------------------
# Returns the hostname of the host system
#
# Arguments:
# None
# Returns:
# Hostname
# ------------------------------------------------------------------------------
hass.api.host.info.hostname() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".hostname"
}
# ------------------------------------------------------------------------------
# Returns a list of exposed features by the host
#
# Arguments:
# None
# Returns:
# List of features
# ------------------------------------------------------------------------------
hass.api.host.info.features() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".features[]"
}
# ------------------------------------------------------------------------------
# Returns the OS of the host system
#
# Arguments:
# None
# Returns:
# OS
# ------------------------------------------------------------------------------
hass.api.host.info.operating_system() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".operating_system"
}
# ------------------------------------------------------------------------------
# Returns the kernel of the host system
#
# Arguments:
# None
# Returns:
# OS
# ------------------------------------------------------------------------------
hass.api.host.info.kernel() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".kernel"
}
# ------------------------------------------------------------------------------
# Returns the chassis of the host system
#
# Arguments:
# None
# Returns:
# OS
# ------------------------------------------------------------------------------
hass.api.host.info.chassis() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".chassis"
}
# ------------------------------------------------------------------------------
# Returns the type of the host
#
@ -36,6 +101,19 @@ hass.api.host.info.type() {
hass.api.host.info ".type"
}
# ------------------------------------------------------------------------------
# Returns the stability channel / deployment of the system
#
# Arguments:
# None
# Returns:
# Version
# ------------------------------------------------------------------------------
hass.api.host.info.deployment() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".deployment"
}
# ------------------------------------------------------------------------------
# Returns the version of the software running on the host
#
@ -62,124 +140,6 @@ hass.api.host.info.last_version() {
hass.api.host.info ".last_version"
}
# ------------------------------------------------------------------------------
# Returns a list of exposed features by the host
#
# Arguments:
# None
# Returns:
# List of features
# ------------------------------------------------------------------------------
hass.api.host.info.features() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".features[]"
}
# ------------------------------------------------------------------------------
# Returns the hostname of the host system
#
# Arguments:
# None
# Returns:
# Hostname
# ------------------------------------------------------------------------------
hass.api.host.info.hostname() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".hostname"
}
# ------------------------------------------------------------------------------
# Returns the OS of the host system
#
# Arguments:
# None
# Returns:
# OS
# ------------------------------------------------------------------------------
hass.api.host.info.os() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".os"
}
# ------------------------------------------------------------------------------
# Returns a list of available hardware on the host system
#
# Arguments:
# None
# Returns:
# JSON object with hardware
# ------------------------------------------------------------------------------
hass.api.host.hardware() {
local filter=${1:-}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.call GET /host/hardware false "${filter}"
}
# ------------------------------------------------------------------------------
# Returns a list of available serial devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.host.hardware.serial() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.hardware ".serial[]"
}
# ------------------------------------------------------------------------------
# Returns a list of available input devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.host.hardware.input() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.hardware ".input[]"
}
# ------------------------------------------------------------------------------
# Returns a list of available disk devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.host.hardware.disk() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.hardware ".disk[]"
}
# ------------------------------------------------------------------------------
# Returns a list of available disk devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.host.hardware.gpio() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.hardware ".gpio[]"
}
# ------------------------------------------------------------------------------
# Returns a list of available audio devices on the host system
#
# Arguments:
# None
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.host.hardware.audio() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.hardware ".audio[]"
}
# ------------------------------------------------------------------------------
# Reboots the host system
#
@ -219,7 +179,6 @@ hass.api.host.update() {
hass.api.call POST /host/update
}
# ------------------------------------------------------------------------------
# Reload the host controller
#
@ -231,4 +190,4 @@ hass.api.host.update() {
hass.api.host.reload() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.call POST /host/reload
}
}

View file

@ -1,37 +0,0 @@
#!/usr/bin/env bash
# ==============================================================================
# Community Hass.io Add-ons: Bash functions library
#
# Provides access to the API functions of Hass.io: Network
# ==============================================================================
# ==============================================================================
# FUNCTIONS
# ==============================================================================
# ------------------------------------------------------------------------------
# List all available information about the network
#
# Arguments:
# $1 jq Filter to apply on the result (optional)
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.network.info() {
local filter=${1:-}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.call GET /network/info false "${filter}"
}
# ------------------------------------------------------------------------------
# Returns the hostname
#
# Arguments:
# None
# Returns:
# Hostname
# ------------------------------------------------------------------------------
hass.api.network.info.hostname() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.host.info ".hostname"
}

View file

@ -38,6 +38,8 @@ hass.api.snapshots.reload() {
# ------------------------------------------------------------------------------
# Create a new full snapshot
#
# Currently only support full, passwordless snapshotting.
#
# Arguments:
# None
# Returns:
@ -48,19 +50,6 @@ hass.api.snapshots.new.full() {
hass.api.call POST /snapshots/new/full
}
# ------------------------------------------------------------------------------
# Create a new partial snapshot
#
# Arguments:
# None
# Returns:
# None
# ------------------------------------------------------------------------------
hass.api.snapshots.new.partial() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.call POST /snapshots/new/partial
}
# ------------------------------------------------------------------------------
# List all available information about a snapshot
#
@ -77,6 +66,20 @@ hass.api.snapshots.info() {
hass.api.call GET "/snapshots/${snapshot}/info" false "${filter}"
}
# ------------------------------------------------------------------------------
# Returns the slug of a snapshot
#
# Arguments:
# $1 Snapshot slug
# Returns:
# Name
# ------------------------------------------------------------------------------
hass.api.snapshots.info.slug() {
local snapshot=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.snapshots.info "${snapshot}" ".slug"
}
# ------------------------------------------------------------------------------
# Returns the name of a snapshot
#
@ -105,6 +108,76 @@ hass.api.snapshots.info.date() {
hass.api.snapshots.info "${snapshot}" ".date"
}
# ------------------------------------------------------------------------------
# Returns the size of a snapshot
#
# Arguments:
# $1 Snapshot slug
# Returns:
# Size in Mb
# ------------------------------------------------------------------------------
hass.api.snapshots.info.size() {
local snapshot=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.snapshots.info "${snapshot}" ".size"
}
# ------------------------------------------------------------------------------
# Returns if the snapshot is protected
#
# Arguments:
# $1 Snapshot slug
# Returns:
# True if it is protected, false otherwise.
# ------------------------------------------------------------------------------
hass.api.snapshots.info.size() {
local snapshot=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.snapshots.info "${snapshot}" ".protected // false"
}
# ------------------------------------------------------------------------------
# Returns the Home Assistant version installed when this snapshot was created.
#
# Arguments:
# $1 Snapshot slug
# Returns:
# Version
# ------------------------------------------------------------------------------
hass.api.snapshots.info.homeassistant() {
local snapshot=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.snapshots.info "${snapshot}" ".homeassistant"
}
# ------------------------------------------------------------------------------
# Returns a list of installed addons when this snapshot was created
#
# Arguments:
# $1 Snapshot slug
# Returns:
# JSON Object
# ------------------------------------------------------------------------------
hass.api.snapshots.info.addons() {
local snapshot=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.supervisor.info ".addons[]"
}
# ------------------------------------------------------------------------------
# Returns a list of installed add-on repositories when this snapshot was created
#
# Arguments:
# $1 Snapshot slug
# Returns:
# List of URL's
# ------------------------------------------------------------------------------
hass.api.snapshots.info.repositories() {
local snapshot=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.supervisor.info ".repositories[]"
}
# ------------------------------------------------------------------------------
# Removes a snapshot
#
@ -120,7 +193,9 @@ hass.api.snapshots.remove() {
}
# ------------------------------------------------------------------------------
# Restores a full snapshot
# Restores a full snapshot.
#
# Currently only support full, passwordless restore.
#
# Arguments:
# $1 Snapshot slug
@ -132,17 +207,3 @@ hass.api.snapshots.restore.full() {
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.call POST "/snapshots/${snapshot}/restore/full"
}
# ------------------------------------------------------------------------------
# Restores a partial snapshot
#
# Arguments:
# $1 Snapshot slug
# Returns:
# None
# ------------------------------------------------------------------------------
hass.api.snapshots.restore.partial() {
local snapshot=${1}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.call POST "/snapshots/${snapshot}/restore/partial"
}

View file

@ -174,3 +174,108 @@ hass.api.supervisor.logs() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.call GET /supervisor/logs true
}
# ------------------------------------------------------------------------------
# List all available stats about the Supervisor
#
# Arguments:
# $1 jq Filter to apply on the result (optional)
# Returns:
# JSON object
# ------------------------------------------------------------------------------
hass.api.supervisor.stats() {
local filter=${1:-}
hass.log.trace "${FUNCNAME[0]}" "$@"
hass.api.call GET /supervisor/stats false "${filter}"
}
# ------------------------------------------------------------------------------
# Returns CPU usage from the Supervisor
#
# Arguments:
# None
# Returns:
# Usage in percent
# ------------------------------------------------------------------------------
hass.api.supervisor.stats.cpu_percent() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.supervisor.stats ".cpu_percent"
}
# ------------------------------------------------------------------------------
# Returns memory usage from the Supervisor
#
# Arguments:
# None
# Returns:
# Usage in Mb
# ------------------------------------------------------------------------------
hass.api.supervisor.stats.memory_usage() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.supervisor.stats ".memory_usage"
}
# ------------------------------------------------------------------------------
# Returns memory limit from the Supervisor
#
# Arguments:
# None
# Returns:
# Usage in Mb
# ------------------------------------------------------------------------------
hass.api.supervisor.stats.memory_limit() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.supervisor.stats ".memory_limit"
}
# ------------------------------------------------------------------------------
# Returns outgoing network usage from the Supervisor
#
# Arguments:
# None
# Returns:
# Usage in Mb
# ------------------------------------------------------------------------------
hass.api.supervisor.stats.network_tx() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.supervisor.stats ".network_tx"
}
# ------------------------------------------------------------------------------
# Returns incoming network usage from the Supervisor
#
# Arguments:
# None
# Returns:
# Usage in Bytes
# ------------------------------------------------------------------------------
hass.api.supervisor.stats.network_rx() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.supervisor.stats ".network_rx"
}
# ------------------------------------------------------------------------------
# Returns disk read usage from the Supervisor
#
# Arguments:
# None
# Returns:
# Usage in Blocks
# ------------------------------------------------------------------------------
hass.api.supervisor.stats.blk_read() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.supervisor.stats ".blk_read"
}
# ------------------------------------------------------------------------------
# Returns disk write usage from the Supervisor
#
# Arguments:
# None
# Returns:
# Usage in Blocks
# ------------------------------------------------------------------------------
hass.api.supervisor.stats.blk_write() {
hass.log.trace "${FUNCNAME[0]}"
hass.api.supervisor.stats ".blk_write"
}