mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-18 13:44:20 +01:00
Add initial support for ZWave JS (#1766)
* Add initial support for ZWave JS * fix version * fix lint * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Charles Garwood <cgarwood@gmail.com> * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update zwave_js/config.json Co-authored-by: Franck Nijhof <git@frenck.dev> * Address comments * Fix install for all archs * make lint happy * Fix build * fix comment * Fix and clean zwave_js add-on (#1780) * Use new bashio feature * address ozw * update docs * Add debug support * fix template * Fix lint Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Charles Garwood <cgarwood@gmail.com> Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
40
zwave_js/rootfs/etc/cont-init.d/config.sh
Normal file
40
zwave_js/rootfs/etc/cont-init.d/config.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Generate Z-Wave JS config file
|
||||
# ==============================================================================
|
||||
declare network_key
|
||||
|
||||
readonly DOCS_EXAMPLE_KEY="2232666D100F795E5BB17F0A1BB7A146"
|
||||
|
||||
if [[ "${DOCS_EXAMPLE_KEY}" == "$(bashio::config 'network_key')" ]]; then
|
||||
bashio::log.fatal
|
||||
bashio::log.fatal 'The add-on detected that the Z-Wave network key used'
|
||||
bashio::log.fatal 'is from the documented example.'
|
||||
bashio::log.fatal
|
||||
bashio::log.fatal 'Using this key is insecure, because it is publicly'
|
||||
bashio::log.fatal 'listed in the documentation.'
|
||||
bashio::log.fatal
|
||||
bashio::log.fatal 'Please check the add-on documentation on how to'
|
||||
bashio::log.fatal 'create your own, secret, "network_key" and replace'
|
||||
bashio::log.fatal 'the one you have configured.'
|
||||
bashio::log.fatal
|
||||
bashio::log.fatal 'Click on the "Documentation" tab in the Z-Wave JS'
|
||||
bashio::log.fatal 'add-on panel for more information.'
|
||||
bashio::log.fatal
|
||||
bashio::exit.nok
|
||||
elif ! bashio::config.has_value 'network_key'; then
|
||||
bashio::log.info "No Network Key is set, generate one..."
|
||||
network_key=$(hexdump -n 16 -e '4/4 "%08X" 1 "\n"' /dev/random)
|
||||
bashio::addon.option network_key "${network_key}"
|
||||
else
|
||||
network_key=$(bashio::config 'network_key')
|
||||
fi
|
||||
|
||||
|
||||
# Generate config
|
||||
bashio::var.json \
|
||||
network_key "${network_key}" \
|
||||
logging "$(bashio::info.logging)" \
|
||||
| tempio \
|
||||
-template /usr/share/tempio/zwave_config.conf \
|
||||
-out /etc/zwave_config.json
|
||||
5
zwave_js/rootfs/etc/cont-init.d/structure.sh
Normal file
5
zwave_js/rootfs/etc/cont-init.d/structure.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Setup folder structure
|
||||
# ==============================================================================
|
||||
mkdir -p /data/cache
|
||||
18
zwave_js/rootfs/etc/services.d/zwave_js/discovery
Executable file
18
zwave_js/rootfs/etc/services.d/zwave_js/discovery
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Send zwave_js discovery information to Home Assistant
|
||||
# ==============================================================================
|
||||
declare ha_config
|
||||
|
||||
# Prepare discovery payload
|
||||
ha_config=$(\
|
||||
bashio::var.json \
|
||||
host "$(hostname)" \
|
||||
port "^3000" \
|
||||
)
|
||||
|
||||
if bashio::discovery "zwave_js" "${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
|
||||
8
zwave_js/rootfs/etc/services.d/zwave_js/finish
Normal file
8
zwave_js/rootfs/etc/services.d/zwave_js/finish
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/execlineb -S1
|
||||
# ==============================================================================
|
||||
# Take down the S6 supervision tree when Z-Wave JS fails
|
||||
# ==============================================================================
|
||||
if { s6-test ${1} -ne 0 }
|
||||
if { s6-test ${1} -ne 256 }
|
||||
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
16
zwave_js/rootfs/etc/services.d/zwave_js/run
Normal file
16
zwave_js/rootfs/etc/services.d/zwave_js/run
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/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"
|
||||
fi
|
||||
|
||||
# Send out discovery information to Home Assistant
|
||||
./discovery &
|
||||
|
||||
# Run daemon
|
||||
exec zwave-server ${SERIAL_DEVICE} --config /etc/zwave_config.json
|
||||
12
zwave_js/rootfs/usr/share/tempio/zwave_config.conf
Normal file
12
zwave_js/rootfs/usr/share/tempio/zwave_config.conf
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"logConfig": {
|
||||
"enabled": true,
|
||||
"level": {{ if eq .logging "debug" }}5{{ else }}2{{ end }},
|
||||
"forceConsole": true
|
||||
},
|
||||
"storage": {
|
||||
"cacheDir": "/data/cache",
|
||||
"throttle": "slow"
|
||||
},
|
||||
"networkKey": "{{ .network_key }}"
|
||||
}
|
||||
Reference in New Issue
Block a user