Developing with the dev-server
The worst way to develop an adapter is on your own home automation system. Every failed attempt cripples a running system, every change has to be uploaded, and pausing the adapter in the debugger means that nothing is controlled in the meantime.
The dev server solves this. It sets up its own small ioBroker installation in the project folder, which only recognizes this one adapter. It has its own admin, its own directory, its own objects, and doesn't interfere with anything.
Furnish
The dev-server runs in the adapter's folder, i.e., where theio-package.json lies.
npm install --global @iobroker/dev-server
dev-server setup
The setup process downloads a js-controller and an admin and places them in the subfolder..dev-server It takes a few minutes the first time, but not after that.
Useful information for setup:
--adminPort <nummer>: in case the default setting conflicts with something else.--jsController <version>and--admin <version>: to develop against a specific version, such as the oldest one that the adapter is supposed to support.--backupFile <datei>This sets up the environment from an ioBroker backup. This allows you to reproduce an error reported by a user.
The folder.dev-server belongs in.gitignore The framework generated by Adapter Creator already has it there.
Work
| command | Effect |
|---|---|
dev-server watch | It starts everything and restarts the adapter with every code change . This is the normal behavior during development. |
dev-server run | Starts the environment, but leaves the adapter running. This allows you to work on the configuration interface. |
dev-server debug | Start the adapter in a way that allows a debugger to connect.--wait He waits until the debugger arrives. |
dev-server upload | Transmits the current status to the surrounding area. Necessary after changes to theio-package.json , because it is only read during upload. |
dev-server update | Updates the js-controller and admin of the environment. |
The log runs in the terminal. This allows you to see immediately what your adapter is doing without having to search for the log in the admin panel.
!> After a change to theio-package.json A restart is not enough.dev-server upload introduces new instance objects, changed configuration settings, or a new operating mode into the environment.
Multiple environments
Profiles allow you to run multiple environments side by side, for example one with the oldest supported js-controller and one with the newest.
dev-server profile
It lists the existing profiles. The remaining commands take the profile name and then operate within that environment.
Requirements and limitations
The dev server runs on Windows, Linux, and macOS and requires at least Node.js 14. All the ports it opens are on127.0.0.1 restricted, meaning the surroundings are not accessible from the outside.
It doesn't replace a real test on a proper system. What it does replace is uploading twenty times in between.
The rest of the toolbox
In addition to the dev-server,@iobroker/adapter-dev into the project. It provides the scripts for translation and construction:
npm run translate # übersetzt neue englische Texte in alle Sprachen
npm run build # baut TypeScript und React-Oberflächen
Both are already included in the Adapter Creator framework. See io-package.json for information on handling the translations and adapter tests, in addition to the included tests.