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:
Franck Nijhof
2020-07-22 12:32:48 +02:00
committed by GitHub
parent 075e6038c5
commit d0fbf36bb9
9 changed files with 141 additions and 46 deletions

View File

@@ -1,5 +1,11 @@
# Changelog # Changelog
## 0.5.2
- Fix startup failure due to stray OZW Daemon status retained in MQTT
- Propagate shutdown OZW Daemon status to upstream MQTT on shutdown
- Update OpenZWave to 6cf3729
## 0.5.1 ## 0.5.1
- Roll-back alpine to 3.11 and qt 5.12 - Roll-back alpine to 3.11 and qt 5.12

View File

@@ -16,6 +16,7 @@ RUN \
eudev-libs \ eudev-libs \
fontconfig \ fontconfig \
mosquitto \ mosquitto \
mosquitto-clients \
openssl \ openssl \
pwgen \ pwgen \
qt5-qtbase \ qt5-qtbase \

View File

@@ -7,7 +7,7 @@
"aarch64": "homeassistant/aarch64-base:3.11" "aarch64": "homeassistant/aarch64-base:3.11"
}, },
"args": { "args": {
"OZW_VERSION": "6c2ca6131cbba4200460256293d719053107a9e8", "OZW_VERSION": "6cf372959ee88baabfe68742297e7b13f57fef14",
"QTOZW_VERSION": "3ad9138f40a856366a7d85fb110b1ed91e1534a0", "QTOZW_VERSION": "3ad9138f40a856366a7d85fb110b1ed91e1534a0",
"QTOZWADMIN_VERSION": "da04ebfbadc57484c487ebc846431eb283e83176", "QTOZWADMIN_VERSION": "da04ebfbadc57484c487ebc846431eb283e83176",
"QTMQTT_VERSION": "5.12.8", "QTMQTT_VERSION": "5.12.8",

View File

@@ -1,15 +1,9 @@
{ {
"name": "OpenZWave", "name": "OpenZWave",
"version": "0.5.1", "version": "0.5.2",
"slug": "zwave", "slug": "zwave",
"description": "Control a ZWave network with Home Assistant", "description": "Control a ZWave network with Home Assistant",
"arch": [ "arch": ["amd64", "i386", "armhf", "armv7", "aarch64"],
"amd64",
"i386",
"armhf",
"armv7",
"aarch64"
],
"url": "https://github.com/home-assistant/hassio-addons/tree/master/zwave", "url": "https://github.com/home-assistant/hassio-addons/tree/master/zwave",
"ingress": true, "ingress": true,
"ingress_entry": "vnc_lite.html", "ingress_entry": "vnc_lite.html",
@@ -28,22 +22,13 @@
"1983/tcp": "ozw-admin port", "1983/tcp": "ozw-admin port",
"5900/tcp": "VNC port" "5900/tcp": "VNC port"
}, },
"services": [ "services": ["mqtt:want"],
"mqtt:want" "discovery": ["ozw"],
],
"discovery": [
"ozw"
],
"auto_uart": true, "auto_uart": true,
"gpio": true, "gpio": true,
"apparmor": false, "apparmor": false,
"privileged": [ "privileged": ["SYS_RAWIO"],
"SYS_RAWIO" "devices": ["/dev/bus/usb:/dev/bus/usb:rwm", "/dev/mem:/dev/mem:rw"],
],
"devices": [
"/dev/bus/usb:/dev/bus/usb:rwm",
"/dev/mem:/dev/mem:rw"
],
"options": { "options": {
"device": null, "device": null,
"network_key": "" "network_key": ""

View File

@@ -0,0 +1,22 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Ensure upstream MQTT server has the correct OZW status retained on shutdown.
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/mqtt_helper.sh
declare host
declare password
declare port
declare username
if bashio::services.available "mqtt"; then
bashio::log.info "Ensure upstream MQTT server has the correct OZW status"
host=$(bashio::services "mqtt" "host")
password=$(bashio::services "mqtt" "password")
port=$(bashio::services "mqtt" "port")
username=$(bashio::services "mqtt" "username")
mqtt::ensure_ozw_offline_status \
"${host}" "${port}" "${username}" "${password}"
fi

View File

@@ -1,7 +1,10 @@
#!/usr/bin/with-contenv bashio #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Setup mqtt settings # Setup MQTT settings
# ============================================================================== # ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/mqtt_helper.sh
declare host declare host
declare password declare password
declare port declare port
@@ -18,6 +21,11 @@ else
( (
echo "connection main-mqtt" echo "connection main-mqtt"
echo "address ${host}:${port}" echo "address ${host}:${port}"
echo "remote_clientid zwave"
echo "local_clientid zwave"
echo "cleansession true"
echo "notifications true"
echo "try_private true"
) >> /etc/mosquitto.conf ) >> /etc/mosquitto.conf
# Need auth? # Need auth?
@@ -33,5 +41,13 @@ else
echo "topic # IN OpenZWave/" echo "topic # IN OpenZWave/"
) >> /etc/mosquitto.conf ) >> /etc/mosquitto.conf
bashio::log.info "Connect to internal MqTT service" # Ensure upstream MQTT server has the right OZW status
# Workaround for an incorrect retained OZW status in MQTT
# In this case, the LWT is not relayed to the upstream MQTT server.
# https://github.com/home-assistant/hassio-addons/issues/1462
mqtt::ensure_ozw_offline_status \
"${host}" "${port}" "${username}" "${password}"
bashio::log.info "Connected to internal MQTT service"
fi fi

View File

@@ -2,6 +2,9 @@
# ============================================================================== # ==============================================================================
# Start OpenZWave service for zwave radio # Start OpenZWave service for zwave radio
# ============================================================================== # ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/mqtt_helper.sh
export MQTT_PASSWORD export MQTT_PASSWORD
export OZW_NETWORK_KEY export OZW_NETWORK_KEY
@@ -20,6 +23,12 @@ fi
bashio::log.info "Starting OpenZWave..." bashio::log.info "Starting OpenZWave..."
bashio::net.wait_for 1883 bashio::net.wait_for 1883
# Ensure local MQTT server has the right OZW status
# Workaround for an incorrect retained OZW status in MQTT
# https://github.com/home-assistant/hassio-addons/issues/1462
mqtt::ensure_ozw_offline_status \
127.0.0.1 1883 ozw "${MQTT_PASSWORD}" "${OZW_INSTANCE}"
# Send out discovery information to Home Assistant # Send out discovery information to Home Assistant
./discovery & ./discovery &

View 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
}