Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Z-Wave JS Mock Server #169

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions zwave_mock_server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ARG BUILD_FROM
FROM $BUILD_FROM

ARG ZWAVEJS_SERVER_VERSION=1.38.0
ARG ZWAVEJS_VERSION=13.3.0

# install nodejs + yarn
RUN set -x \
&& apk add --no-cache \
nodejs \
npm \
yarn

# install zwave-js
RUN set -x \
&& npm install -g \
"zwave-js@${ZWAVEJS_VERSION}" \
"@zwave-js/server@${ZWAVEJS_SERVER_VERSION}" \
"[email protected]"

COPY run.sh /
RUN chmod a+x /run.sh

CMD [ "/run.sh" ]


17 changes: 17 additions & 0 deletions zwave_mock_server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Mock Server for Z-Wave JS

Run a virtual Z-Wave controller from mock files, useful for debugging and development.
This add-on consists of the Z-Wave JS Driver itself (running in mock mode) which exposes a virtual serial port on TCP port 5555. You can connect to this fake Z-Wave stick by connecting to this port from the Z-Wave JS UI or Z-Wave JS Server add-on.

For convenience, this add-on also hosts the Z-Wave JS Server directly, making it a all-in-one package to quickly fire up a mocked Z-Wave network. Simply connect to the Z-Wave JS websocket server fromm the Home Assistant Z-Wave integration.

### How to import mock/dump files ?

The mock/dump files are stored in the `addon_configs` folder.
Use either the Samba add-on, a Fileborwser add-on or the VS Code add-on to explore the files of the addon_configs share and look for a subfolder named zwave_mock_server. Place the dump files in that folder (named .js or .mock). Make sure to restart the Z-Wave JS Mock Server add-on if you placed new files in the folder.

### How to export mock/dump files ?

From within Z-Wave JS, open a Z-Wave node and click the Advanced button.
In the dialog, at 'Export json' click the 'DRIVER' button to make a Node dump in the format defined by the driver.
Rename the downloaded file so it gets the .mock extension.
19 changes: 19 additions & 0 deletions zwave_mock_server/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Z-Wave JS Mock Server
version: 1.0.0
slug: zwave_mock_server
description: Simple Z-Wave JS Mock Server for testing purposes - Instantiates a Z-Wave JS Server using mock/dump files for testing purposes.
url: https://github.com/home-assistant/addons/tree/master/zwave_mock_server
arch:
- amd64
- aarch64
map:
- addon_config:rw
init: false
advanced: false
stage: experimental
tmpfs: true
ports:
3000/tcp: 3001
agners marked this conversation as resolved.
Show resolved Hide resolved
agners marked this conversation as resolved.
Show resolved Hide resolved
discovery:
- zwave_js
hassio_api: true
marcelveldt marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions zwave_mock_server/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/with-contenv bashio

echo
echo "##################################"
echo " Z-Wave JS Mock Server"
echo "##################################"
echo
echo "Detected mock files in directory:"
echo
ls /config
echo
echo

# send discovery info to Home Assistant
declare ha_config
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

# start mock driver + zwave-server
bashio::log.info ""
bashio::log.info "Starting Z-Wave JS Mock Driver + Z-Wave Server..."
node /usr/local/bin/mock-server -c /config && \
node /usr/local/bin/zwave-server tcp://127.0.0.1:5555
Loading