Skip to content

Commit

Permalink
🔨 Rewrite add-on onto Bashio
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck committed Mar 20, 2019
1 parent 787a24b commit a788daf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
11 changes: 4 additions & 7 deletions airsonos/rootfs/etc/cont-init.d/50-airsonos.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: AirSonos
# Checks latency settings before starting the AirSonos server
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

declare latency

# Create a configuration file, if it does not exist yet
if ! hass.file_exists '/config/airsonos.xml'; then
if ! bashio::fs.file_exists '/config/airsonos.xml'; then
cp /etc/airsonos.xml /config/airsonos.xml
fi

# Warn if latency is below 500ms
latency=$(hass.config.get 'latency_rtp')
latency=$(bashio::config 'latency_rtp')
if [[ "${latency}" -lt 500 && "${latency}" -ne 0 ]]; then
hass.log.warning \
bashio::log.warning \
'Setting the RTP latency of AirPlay audio below 500ms is not recommended!'
fi
51 changes: 25 additions & 26 deletions airsonos/rootfs/etc/services.d/airsonos/run
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: AirSonos
# Runs the AirSonos server
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

declare -a options

hass.log.info 'Starting the AirSonos server'
bashio::log.info 'Starting the AirSonos server...'

# Non-interactive
options+=(-Z)
Expand All @@ -20,34 +17,36 @@ options+=(-x '/config/airsonos.xml')
options+=(-I)

# Bind to a specific interface
if hass.config.has_value 'address'; then
options+=(-b "$(hass.config.get 'address'):$(hass.config.get 'port')")
if bashio::config.has_value 'address'; then
options+=(-b "$(bashio::config 'address'):$(bashio::config 'port')")
fi

# Find the matching AirSonos log level
case "$(hass.string.lower "$(hass.config.get 'log_level')")" in
all|trace)
options+=(-d 'all=sdebug')
;;
debug)
options+=(-d 'all=debug')
;;
info|notice)
options+=(-d 'all=info')
;;
warning)
options+=(-d 'all=warn')
;;
error|fatal|off)
options+=(-d 'all=error')
;;
esac
if bashio::config.exists 'log_level'; then
case "$(bashio::string.lower "$(bashio::config 'log_level')")" in
all|trace)
options+=(-d 'all=sdebug')
;;
debug)
options+=(-d 'all=debug')
;;
info|notice)
options+=(-d 'all=info')
;;
warning)
options+=(-d 'all=warn')
;;
error|fatal|off)
options+=(-d 'all=error')
;;
esac
fi

# Set latency
options+=(-l "$(hass.config.get 'latency_rtp'):$(hass.config.get 'latency_http')")
options+=(-l "$(bashio::config 'latency_rtp'):$(bashio::config 'latency_http')")

# Drift mode?
if hass.config.true 'drift'; then
if bashio::config.true 'drift'; then
options+=(-r)
fi

Expand Down

0 comments on commit a788daf

Please sign in to comment.