mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 13:14:21 +01:00
OpenZWave 0.5.2 (#1489)
* OpenZWave 0.5.2 * Fix typo in code comment * LTW -> LWT * Convert mosquitto.conf dos2unix * Add additional MQTT bridge settings * Change client name to match add-on slug * Extract MQTT logic into a helper * Disable shellcheck SC1091
This commit is contained in:
56
zwave/rootfs/usr/lib/mqtt_helper.sh
Normal file
56
zwave/rootfs/usr/lib/mqtt_helper.sh
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# MQTT helpers for the zwave add-on.
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Ensure upstream MQTT server has the correct OZW status retained on shutdown.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 MQTT Server host
|
||||
# $2 MQTT Server port
|
||||
# $3 MQTT Server username
|
||||
# $4 MQTT Server password
|
||||
# $5 OZW Instance ID (optional)
|
||||
# ------------------------------------------------------------------------------
|
||||
function mqtt::ensure_ozw_offline_status() {
|
||||
local host=${1}
|
||||
local port=${2}
|
||||
local username=${3}
|
||||
local password=${4}
|
||||
local ozw_instance=${5:-}
|
||||
local ozw_status
|
||||
|
||||
bashio::log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if ! bashio::var.has_value "${ozw_instance}"; then
|
||||
ozw_instance=1
|
||||
if bashio::config.has_value 'instance'; then
|
||||
ozw_instance=$(bashio::config 'instance')
|
||||
fi
|
||||
fi
|
||||
|
||||
ozw_status=$(\
|
||||
mosquitto_sub \
|
||||
--host "${host}" \
|
||||
--port "${port}" \
|
||||
--username "${username}" \
|
||||
--pw "${password}" \
|
||||
-C 1 \
|
||||
-W 3 \
|
||||
--retained-only \
|
||||
--topic "OpenZWave/${ozw_instance}/status/" \
|
||||
)
|
||||
if bashio::var.has_value "${ozw_status}" \
|
||||
&& [[ $(bashio::jq "${ozw_status}" ".Status") != "Offline" ]];
|
||||
then
|
||||
mosquitto_pub \
|
||||
--host "${host}" \
|
||||
--port "${port}" \
|
||||
--username "${username}" \
|
||||
--pw "${password}" \
|
||||
--retain \
|
||||
--topic "OpenZWave/${ozw_instance}/status/" \
|
||||
--message "$(bashio::var.json "Status" "Offline")"
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user