#!/usr/bin/with-contenv bashio
# ==============================================================================
# Start Z-Wave JS service for Z-Wave radio
# ==============================================================================
SERIAL_DEVICE=$(bashio::config 'device')

# Emulate serial Hardware for test & development
if bashio::config.true 'emulate_hardware'; then
    SERIAL_DEVICE="--mock-driver"
fi

# Send out discovery information to Home Assistant
./discovery &

# Set external config directory
export ZWAVEJS_EXTERNAL_CONFIG=/data/db

# Run daemon, passing external config directory in as environment variable
exec zwave-server ${SERIAL_DEVICE} --config /etc/zwave_config.json --disable-dns-sd
