This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ioBroker.discovery is an ioBroker adapter that automatically detects devices and services on the local network (via ping, UPnP/SSDP, mDNS, TR-064, UDP, serial ports, etc.) and suggests appropriate ioBroker adapters for them. It is a singleton adapter (one instance per host).
npm test # Run mocha tests (validates package/io-package files)
npm run lint # ESLint with @iobroker/eslint-config (flat config in eslint.config.mjs)Release commands (uses @alcalzone/release-script):
npm run release-patch
npm run release-minor
npm run release-majorThe adapter starts via startAdapter() which creates a utils.Adapter instance. It listens for two messages from the admin UI:
browse: triggers a full network discovery scanlistMethods: returns available discovery methods
browse()orchestrates the scan: loads methods and adapter modules, runs all enabled discovery methods in parallel- Discovery methods (
lib/methods/*.js) scan the network and callself.addDevice()to populate a sharedg_devicesobject analyseDevices()iterates each discovered device and tests it against all adapter detection modules- Detection runs in two phases: first adapters with
dependencies=false(in parallel for IP, sequential for serial), then adapters withdependencies=true - Results are stored in
system.discoveryioBroker object with sensitive fields encrypted
10 method modules (ping, upnp, mdns, tr064, udp, serial, speedwire, wifi-mi-light, hf-lpb100, vbus) plus a ping helper. Each exports:
browse(self)- receives a Method wrapper withaddDevice(),done(),updateProgress(), timeout helperssource- method identifier stringtype- device type it produces (e.g.'ip','upnp')timeout- scan duration in ms
Methods are auto-loaded from lib/methods/ by filename (excluding files starting with _).
99 modules, each detecting a specific device/service type. Each exports:
detect(ip, device, options, callback)- tests if a device matches; adds tooptions.newInstancesif foundtype- string or array of device types to match against (e.g.['ip'],['upnp'],'serial','advice')timeout- detection timeout in ms (default 2000)dependencies- iftrue, runs after base detection phase
Modules are auto-loaded from lib/adapters/ by filename. The options object passed to detect() contains newInstances, existingInstances, enums, language, and log.
Key helpers used by adapter modules:
testPort(ip, port, timeout, options, callback)- TCP port probe with optional custom request/responsehttpGet(url, timeout, callback)/httpPost(url, data, timeout, callback)- HTTP helpersgetNextInstanceID(name, options)- generates nextsystem.adapter.NAME.NIDfindInstance(options, name, filter)- finds existing adapter instance by name and native config filtergetOwnAddress(ip)- finds local IP on same subnet as targetopenPort(name, options, onOpen, onReceived, callback)- serial port communication
- Pure JavaScript (no TypeScript transpilation), Node.js >= 20
- Callback-based async patterns throughout (error-first callbacks, not Promises)
- ESLint uses
@iobroker/eslint-configflat config; JSDoc rules are disabled - Tests use
@iobroker/testingframework with mocha - Optional dependencies (
serialport,mdns-discovery) are loaded with graceful fallback