Skip to main content

Development

This page covers working on the code. For running the hub as a user, see Getting started. For how the crates fit together, see Architecture.

Checks​

Run these before opening a pull request:

cargo test --workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --all --check
cargo check -p nidoo-core --target wasm32-unknown-unknown
cargo check -p nidoo-api --target wasm32-unknown-unknown
cargo check -p nidoo-web --target wasm32-unknown-unknown

The wasm32-unknown-unknown target comes with rust-toolchain.toml (stable channel). nidoo-core and nidoo-api must keep building for it, because the web UI shares them.

The tests run against recorded broker messages under crates/nidoo-core/tests/fixtures and never need a broker.

Recording fixtures​

Refresh the recording from a live house with:

MQTT_HOST=<host> MQTT_USER=<user> MQTT_PASS=<password> tools/record-fixtures.sh

The script needs mosquitto_sub and python3. It listens for six seconds to homeassistant/#, nidoo/# and zigbee2mqtt/…, then rewrites the discovery, states and ui folders under crates/nidoo-core/tests/fixtures. It leaves the fixtures untouched when no retained message arrives. MQTT_PORT (default 1883) is optional. Credentials are read from the environment only and never written anywhere.

Run the hub​

cargo run -p nidoo

The hub keeps its data in ./data (--data <dir> picks another folder) and serves the setup wizard at http://localhost:8081/setup on a first start. For a local broker and database, start the bundled ones: cargo run -p nidoo -- init-bundled && docker compose up -d --no-deps mosquitto timescaledb (host networking needs Linux, or Docker Desktop's host networking enabled on macOS), then use the credentials in data/bundled.json in the wizard. See Configuration for every key.

Web UI​

The web UI is a Leptos app that runs in the browser as wasm, built with Trunk. It lives in crates/nidoo-web.

Install the tools​

cargo install trunk --locked
cargo install wasm-pack --locked

wasm-pack fetches a matching chromedriver on first use; Google Chrome must be installed for the smoke test.

Dev loop​

Development runs in two terminals:

cargo run -p nidoo -- run # the hub on 8081
cd crates/nidoo-web && trunk serve # the UI on 127.0.0.1:3000, rebuilt on save

Open http://127.0.0.1:3000. Trunk.toml proxies /api/v1/, /ws and /mcp/ to the hub on 127.0.0.1:8081, so the UI talks to a real hub while Trunk rebuilds it on save. If your hub binds elsewhere, change the three backend entries.

Release build order​

A release build embeds the UI, so build the UI before the hub:

cd crates/nidoo-web && trunk build --release
cd ../.. && cargo build --release -p nidoo

The hub embeds crates/nidoo-web/dist/ with rust-embed when it is compiled. Rebuild the hub after every trunk build. A binary built before trunk build has no UI to serve: every path that is not /api, /ws or /mcp answers a 503 page that says the UI has not been built. index.html is never cached; hashed assets are cached for a year. A release trunk build also writes .gz copies of the wasm, js and css (and .br copies when brotli is installed), through the post_build hook in crates/nidoo-web/compress.sh; the hub sends them to browsers that accept them. Browsers offer brotli only over HTTPS, so a plain-HTTP hub sends gzip, which takes the wasm from about 11 MB to about 3.4 MB.

Version numbers​

Every merge to main bumps the patch version: the Version bump workflow (.github/workflows/version.yml) runs tools/ci/bump_version.py, which rewrites [workspace.package] version in Cargo.toml and the workspace crates in both lock files, then commits chore(release): vX.Y.Z to main and tags it. Merges that land while a bump is waiting share the next one. Settings shows the number, so it tells you which merge a hub runs. Don't bump the version in a pull request; to change the minor or major number, edit Cargo.toml by hand and the next merge goes on from there.

Smoke test​

The smoke test mounts the app in headless Chrome and checks the shell:

cd crates/nidoo-web && wasm-pack test --headless --chrome

The other tests under crates/nidoo-web/tests (cards, flow canvas, group wizard and so on) run the same way. wasm-pack test first builds every browser test file, each a debug wasm of 200 to 360 MB, about 16 GB in all, even with -- --test <file>. To run one file, call cargo with wasm-bindgen's test runner and a chromedriver that matches your Chrome (wasm-pack keeps both in its cache after its first run):

CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=/path/to/wasm-bindgen-test-runner \
CHROMEDRIVER=/path/to/chromedriver \
cargo test -p nidoo-web --target wasm32-unknown-unknown --test rich_cards

The runner's version must match wasm-bindgen in Cargo.lock. cargo test -p nidoo-web without a target runs the native tests, tests/bare_text.rs among them.

The hub's integration tests build as one binary, from crates/nidoo/tests/integration.rs, which lists each test file as a module: each test binary costs a link of the whole hub, so a new test file gets a mod line there instead of becoming a binary of its own. To run one file, filter by its module:

cargo test -p nidoo --test integration flows::

The browser tests stay one binary per file. Many of them leave their app mounted, and a test that clicks a link or goes back would be caught by an earlier test's app if they shared a page.

tools/restart.sh​

tools/restart.sh builds the web UI and the hub, stops the running hub and starts the new one, detached, from the repo root so it reads ./data. It waits up to 20 seconds for /health, and logs to <cargo target dir>/nidoo.log (set NIDOO_LOG to log elsewhere).

FlagEffect
--no-webSkip trunk build and reuse crates/nidoo-web/dist.
--debugBuild and run the debug profile instead of release.
--fastDebug profile and a Trunk dev build (no wasm-opt): the fastest dev loop.
--sweepFirst delete build artifacts untouched for 14 days (needs cargo install cargo-sweep); the current builds are kept.

It warns when the target directory passes 10 GB (TARGET_WARN_GB changes the limit). It stops previous hubs with SIGTERM, waits up to 10 seconds, then sends SIGKILL.