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

# Prepare discovery payload
ha_config=$(\
    bashio::var.json \
        host "$(hostname)" \
        port "^1883" \
        username "homeassistant" \
        password "$(bashio::jq /data/auth.json '.homeassistant_password')" \
)

if bashio::discovery "ozw" "${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
