#!/usr/bin/with-contenv bashio
# ==============================================================================
# Send Almond discovery information to Home Assistant
# ==============================================================================
declare ha_config

# Wait for the Almond service to be available
bashio::net.wait_for 3000

# Prepare discovery payload
ha_config=$(\
    bashio::var.json \
        host "$(hostname)" \
        port "3001" \
)

if bashio::discovery "almond" "${ha_config}" > /dev/null; then
    bashio::log.info "Successfully send discovery information to Home Assistant."
else
    bashio::log.error "Discovery message to Home Assistant failed!"
fi
