mirror of
https://github.com/hassio-addons/bashio.git
synced 2025-05-06 12:01:25 +00:00
✨ Adds support for Hass.io Discovery (#8)
This commit is contained in:
parent
a1d16b68e0
commit
dcfc2b886f
2 changed files with 48 additions and 0 deletions
|
@ -58,6 +58,8 @@ source "${__BASHIO_LIB_DIR}/config.sh"
|
|||
source "${__BASHIO_LIB_DIR}/debug.sh"
|
||||
# shellcheck source=lib/exit.sh
|
||||
source "${__BASHIO_LIB_DIR}/exit.sh"
|
||||
# shellcheck source=lib/discovery.sh
|
||||
source "${__BASHIO_LIB_DIR}/discovery.sh"
|
||||
# shellcheck source=lib/dns.sh
|
||||
source "${__BASHIO_LIB_DIR}/dns.sh"
|
||||
# shellcheck source=lib/hardware.sh
|
||||
|
|
46
lib/discovery.sh
Normal file
46
lib/discovery.sh
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Community Hass.io Add-ons: Bashio
|
||||
# Bashio is an bash function library for use with Hass.io add-ons.
|
||||
#
|
||||
# It contains a set of commonly used operations and can be used
|
||||
# to be included in add-on scripts to reduce code duplication across add-ons.
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Publish a new configuration object for discovery.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Service name
|
||||
# $2 Configuration object (JSON)
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::discovery() {
|
||||
local service=${1}
|
||||
local config=${2}
|
||||
local payload
|
||||
|
||||
bashio::log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
payload=$(\
|
||||
bashio::var.json \
|
||||
service "${service}" \
|
||||
config "^${config}" \
|
||||
)
|
||||
|
||||
bashio::api.hassio "POST" "/discovery" "${payload}"
|
||||
bashio::cache.flush_all
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Deletes configuration object for this discovery.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 Discovery UUID
|
||||
# ------------------------------------------------------------------------------
|
||||
function bashio::discovery.delete() {
|
||||
local uuid=${1}
|
||||
|
||||
bashio::log.trace "${FUNCNAME[0]}:" "$@"
|
||||
bashio::api.hassio "DELETE" "/discovery/${uuid}"
|
||||
bashio::cache.flush_all
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue