### Subscribe to Install Event Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Register a listener function to be called when the adapter is installed or updated. Useful for one-time setup tasks. ```typescript on("install", listener: ReadyHandler): this ``` -------------------------------- ### Custom Adapter Installation Logic Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Implement custom installation logic for an adapter by listening for the 'install' event or passing an 'install' function to the constructor. This runs after npm installation. ```typescript this.on('install', () => { this.log.info('Performing installation logic ...') // Perform your installation logic }); ``` -------------------------------- ### Configure Redis as States DB Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md When prompted during 'iobroker setup custom', enter 'redis' for the states DB type to switch ioBroker's state storage to Redis. This example shows the relevant prompt and input. ```bash Type of objects DB [file, redis], default [file]: Host of objects DB(file), default[127.0.0.1]: Port of objects DB(file), default[9001]: Type of states DB [file, redis], default [file]: redis Host of states DB (redis), default[127.0.0.1]: Port of states DB (redis), default[6379]: Data directory (file), default[../../../iobroker-data/]: Host name of this machine [FastPC]: creating conf/iobroker.json ``` -------------------------------- ### Install ioBroker via Script Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Use this command to install ioBroker on Debian-based systems by downloading and executing an installation script. ```bash curl -sLf https://iobroker.net/install.sh | bash - ``` -------------------------------- ### Start ioBroker Controller (Linux Foreground) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Starts the ioBroker controller in the foreground on Linux systems, allowing you to watch the logs directly in the console. Requires being in the ioBroker directory. ```bash node node_modules/iobroker.js-controller/controller.js ``` -------------------------------- ### Start ioBroker Controller (Linux Background) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Starts the ioBroker controller in the background on Linux systems. Use 'iobroker logs --watch' to monitor the logs. ```bash iobroker start ``` -------------------------------- ### Get Enum Tree (JavaScript Example) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves the enum tree. If no enum is specified, all enums are returned. This example demonstrates how to fetch and process all enums. ```javascript adapter.getEnums(function (err, enums, requestEnum) { // All enums if (err) adapter.log.error('Cannot get object: ' + err); for (var e in enums) { adapter.log.debug('Enum "' + e + '" has following members: ' + enums[e].common.members.join(', ')); } }); ``` -------------------------------- ### Install Dependencies Source: https://github.com/iobroker/iobroker.js-controller/blob/master/CLAUDE.md Installs project dependencies, ignoring scripts during the preinstall phase. This is required because the preinstall script needs built code. ```bash # Install (--ignore-scripts required because preinstall needs built code) npm ci --ignore-scripts ``` -------------------------------- ### Install Dependencies Source: https://github.com/iobroker/iobroker.js-controller/blob/master/CONTRIBUTING.md Installs project dependencies using npm ci, ignoring scripts. This command should be run in the root folder of the project. ```bash npm ci --ignore-scripts ``` -------------------------------- ### Example: Subscribe to all states of the current adapter Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Demonstrates how to subscribe to all states belonging to the current adapter instance using the subscribeStates method with a wildcard pattern. ```javascript adapter.subscribeStates('*'); // subscribe for all states of this adapter ``` -------------------------------- ### installNodeModule Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Installs a specified npm module with given options. Returns a promise that resolves to a CommandResult. ```APIDOC ## installNodeModule ### Description Installs a specified npm module with given options. Returns a promise that resolves to a CommandResult. ### Method `installNodeModule(moduleName, options)` ### Parameters #### Path Parameters - **moduleName** (string) - The name of the npm module to install. - **options** (InstallNodeModuleOptions) - Version information and other options for the installation. ### Returns `Promise` - A promise that resolves to the result of the installation command. ``` -------------------------------- ### Install Nightly Release Source: https://github.com/iobroker/iobroker.js-controller/blob/master/CONTRIBUTING.md Installs the latest nightly release of ioBroker.js-controller. This is useful for testing code changes in a running environment. ```bash npm i iobroker.js-controller@dev ``` -------------------------------- ### Install Node Module with Version Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Installs a specified Node.js module with an optional version. Use this method to manage adapter-specific dependencies. ```typescript const result = await adapter.installNodeModule('axios', { version: '1.0.0' }); if (result.success) { // successfully installed } ``` -------------------------------- ### Set ioBroker Hostname in Configuration Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Configure a specific hostname for the ioBroker instance by editing the 'iobroker.json' file before the first start. Ensure the hostname is not changed after the initial setup. ```json5 { "system": { // ... "hostname": "local", // ... }, } ``` -------------------------------- ### Example Usage of readFile Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Demonstrates how to use the readFile method to read the content of a file. It includes error handling and logging the file content. ```javascript adapter.readFile('vis-2.0', '/main/vis-views.json', function (err, data) { // All enums if (err) adapter.log.error('Cannot read file: ' + err); adapter.log.info('Content of file is: ' + data); }); ``` -------------------------------- ### listInstalledNodeModules Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Lists all additional installed Node.js modules for this adapter. Returns a promise that resolves to an array of strings, where each string is a module name. ```APIDOC ## listInstalledNodeModules ### Description Lists all additional installed Node.js modules for this adapter. Returns a promise that resolves to an array of strings, where each string is a module name. ### Method `listInstalledNodeModules()` ### Returns `Promise` - A promise that resolves to an array of installed module names. ``` -------------------------------- ### Add a new Admin UI instance Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Installs a new Admin UI instance on an alternate port if the default port is occupied. The port can be changed to any available one. ```bash iobroker add admin --enabled --port 8090 ``` -------------------------------- ### Configure Memory Limits for Adapter Startup Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Set warning and error thresholds for available RAM before starting adapter processes. These limits can be configured in iobroker.json. ```json { "system": { "memLimitWarn": 100, "memLimitWarnComment": "If the available RAM is below this threshold on adapter start, a warning will be logged.", "memLimitError": 50, "memLimitErrorComment": "If the available RAM is below this threshold on adapter start, an error will be logged." } // ... } ``` -------------------------------- ### Stop ioBroker and Setup Custom Configuration Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Use these commands to stop the ioBroker service and initiate the custom configuration process, which allows changing database types. ```bash iobroker stop iobroker setup custom ``` -------------------------------- ### Run Full Test Suite Source: https://github.com/iobroker/iobroker.js-controller/blob/master/CLAUDE.md Executes the complete test suite for the controller package. Requires Redis to be installed locally and not used by ioBroker on the same DB ports. ```bash # Tests (require Redis installed locally; no ioBroker instance using same DB ports) npm test # packages/controller/test/*.ts ``` -------------------------------- ### List Installed Node Modules Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Retrieves a list of all Node.js modules installed by the current adapter. Useful for auditing dependencies. ```typescript const installedNodeModules = await adapter.listInstalledNodeModules(); adapter.log.info(`Installed modules are: ${installedNodeModules.join(', ')}`); ``` -------------------------------- ### Subscribe to Ready Event Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Register a listener function to be called once the adapter is fully initialized and ready to operate. This is a common starting point for adapter logic. ```typescript on("ready", listener: ReadyHandler): this ``` -------------------------------- ### Run Tests Source: https://github.com/iobroker/iobroker.js-controller/blob/master/CONTRIBUTING.md Executes all tests locally using npm run test. Ensure no other ioBroker instance is running and a Redis DB is installed. ```bash npm run test ``` -------------------------------- ### Write File to Database Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Example of writing file content to the database for a specified adapter and path. Handles potential errors during the write operation. ```javascript adapter.writeFile('vis-2.0', '/main/vis-views.json', data, function (err) { err && adapter.log.error('Cannot write file: ' + err); }); ``` -------------------------------- ### Get Channels Callback (With Parent and Options) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves a list of channels for a specific parent device, with additional options, using a callback. ```javascript getChannels(parentDevice, options, callback) ``` -------------------------------- ### Extend Object - Example 1 Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Demonstrates how to extend an existing object with new common properties and modify native properties. The 'type' property is preserved. ```javascript { common: { desc: 'New description', min: 0, max: 100 }, native: { unused: null } } ``` -------------------------------- ### Configure Redis as Objects/File DB Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md To store objects and files in Redis, enter 'redis' when prompted for the 'Type of objects DB' during 'iobroker setup custom'. This is available from js-controller 2.0.0. ```bash Type of objects DB [file, redis], default [file]: redis ``` -------------------------------- ### Ignore Specific Adapter Version Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Use the CLI to ignore a specific adapter version or a range of versions. This prevents accidental installation of unsuitable versions. ```bash iobroker version --ignore ``` ```bash iobroker version --recognize ``` ```bash iobroker version --ignore ~1.5.0 ``` -------------------------------- ### Extend Object - Example 2 Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Shows the resulting object structure after extending with new common properties and modifying native properties. Note that 'native' is an empty object if all its properties were set to null. ```javascript { common: { desc: 'New description', min: 0, max: 100 }, type: 'state', native: {} } ``` -------------------------------- ### Get Free Port Asynchronously Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md This asynchronous function finds the first free TCP port starting from the given number and returns a Promise that resolves with the port number. ```javascript const port = await adapter.getPortAsync(8081); adapter.log.debug('Following port is free: ' + port); ``` -------------------------------- ### Manually Run Adapter Instance for Debugging Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Execute an adapter's main JavaScript file from the command line for detailed console logging. Use the --force and --logs flags. ```bash node node_modules/iobroker.adaptername/main.js --force --logs ``` -------------------------------- ### setStateChanged Callback Example Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Example of using the callback function with setStateChanged to handle potential errors or log changes. ```javascript function (err, id, notChanged) { if (err) adapter.log.error('Cannot set value for "' + id + '": ' + err); if (!notChanged) adapter.log.debug('Value was changed'); } ``` -------------------------------- ### Get Channels Of Callback Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves channels associated with the adapter instance using a callback. This method is specifically for getting channels 'of' the adapter. ```javascript getChannelsOf(callback) ``` -------------------------------- ### Build Project Source: https://github.com/iobroker/iobroker.js-controller/blob/master/CONTRIBUTING.md Builds the entire project using npm run build. Lerna manages the build order automatically. This command should be run in the root folder. ```bash npm run build ``` -------------------------------- ### StateRedisClient Constructor Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/-internal-/classes/StateRedisClient.md Initializes a new instance of the StateRedisClient class. It requires settings to configure the client. ```APIDOC ## new StateRedisClient(settings) ### Description Initializes a new instance of the StateRedisClient class. ### Parameters #### Path Parameters - **settings** (StatesSettings) - Required - The settings object for the state client. ``` -------------------------------- ### getEnum Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves enum trees. If no enum is specified, all enums are returned. An example usage is provided. ```APIDOC ## getEnum ### Description Retrieves enum trees. If no enum name is specified, all enums will be returned. ### Example Usage ```js adapter.getEnums(function (err, enums, requestEnum) { // All enums if (err) adapter.log.error('Cannot get object: ' + err); for (var e in enums) { adapter.log.debug('Enum "' + e + '" has following members: ' + enums[e].common.members.join(', ')); } }); ``` ### Parameters #### enumName - **enumName** (string) - The name of the enum to retrieve (e.g., 'rooms', 'function'), or an empty string ('') to get all enums. #### userContext - **userContext** (any) - Optional user context. ``` -------------------------------- ### Get Adapter Objects Asynchronously Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Asynchronously retrieves all states, channels, devices, and folders belonging to this adapter. ```typescript getAdapterObjectsAsync(): Promise> ``` -------------------------------- ### mkdir Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Creates a directory. This method has two overloaded signatures, one with a callback and one with options and a callback. ```APIDOC ## mkdir (with callback) ### Description Creates a directory with a callback. ### Method `mkdir(adapterName, path, callback)` ### Parameters #### Path Parameters - **adapterName** (string | null) - The name of the adapter. Can be null. - **path** (string) - The path of the directory to create. - **callback** (ErrnoCallback) - The callback function to be executed after the operation. ### Returns `void` ``` ```APIDOC ## mkdir (with options and callback) ### Description Creates a directory with specified options and a callback. ### Method `mkdir(adapterName, path, options, callback)` ### Parameters #### Path Parameters - **adapterName** (string | null) - The name of the adapter. Can be null. - **path** (string) - The path of the directory to create. - **options** (unknown) - Unknown options for directory creation. - **callback** (ErrnoCallback) - The callback function to be executed after the operation. ### Returns `void` ``` -------------------------------- ### Uninstall Node Module Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Removes a previously installed Node.js module. Ensure the module is no longer needed before uninstalling. ```typescript const result = await adapter.uninstallNodeModule('axios'); if (result.success) { // successfully uninstalled } ``` -------------------------------- ### Get Channels Callback (With Parent) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves a list of channels belonging to a specific parent device using a callback. ```javascript getChannels(parentDevice, callback) ``` -------------------------------- ### Directly Execute TypeScript Adapters Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Configure an adapter's 'package.json' to use a '.ts' file as its main entry point, enabling direct execution without prior compilation. Ensure source files are included in the npm package. ```json { "main": "src/main.ts" } ``` -------------------------------- ### Import Node Module Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Imports a previously installed Node.js module. This mimics the behavior of JavaScript's 'import' operator. ```typescript const module = await adapter.importNodeModule('axios'); ``` -------------------------------- ### Get Session Information Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves session information based on a provided ID. This function can return a Promise or use a callback. ```javascript adapter.getSession(sessionId, (err, session) => { if (err) { adapter.log.error('Error getting session: ' + err); } else { adapter.log.info('Session data: ' + JSON.stringify(session)); } }); ``` -------------------------------- ### Build All Packages Source: https://github.com/iobroker/iobroker.js-controller/blob/master/CLAUDE.md Builds all packages within the monorepo. Lerna manages the build order using project references. ```bash # Build all packages (Lerna handles build order via project references) npm run build ``` -------------------------------- ### getSuitableLicenses Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves a list of suitable licenses. It can fetch licenses used by other instances or only for the current instance, and can be filtered by adapter name. ```APIDOC ## getSuitableLicenses ### Description Retrieves a list of suitable licenses. It can fetch licenses used by other instances or only for the current instance, and can be filtered by adapter name. ### Method `getSuitableLicenses(all?, adapterName?)` ### Parameters #### Query Parameters - **all?** (boolean) - Optional. If true, returns licenses used by other instances; if false, returns licenses only for this instance. - **adapterName?** (string) - Optional. Return licenses for a specific adapter. ### Returns `Promise` - A promise that resolves to a list of suitable licenses. ``` -------------------------------- ### Callback for getEnums Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Callback function to handle the result of getEnums. Logs errors and provides an example structure of the returned enums object. ```javascript function (err, enums) { // requestEnum is _enum if (err) adapter.log.error('Cannot get object: ' + err); // Result is like // { // "enum.rooms": { // "enum.rooms.livingroom": { // common: { // members: ['ID1', 'ID2'] // } // }, // "enum.rooms.sleepingroom": { // common: { // members: ['ID3', 'ID4'] // } // } // }, // "enum.functions": { // "enum.rooms.light": { // common: { // members: ['ID1', 'ID6'] // } // }, // "enum.rooms.weather": { // common: { // members: ['ID4', 'ID7'] // } // } // } // } } ``` -------------------------------- ### mkdir Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/-internal-/classes/ObjectsInRedisClient.md Creates a new directory in the object storage, with an optional callback. ```APIDOC ## mkdir(id, dirName?, options?, callback?) ### Description Creates a new directory in the object storage, with an optional callback. ### Method (Implicitly a method call within the ObjectsInRedisClient class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **id** (string) - The ID of the parent directory or object. * **dirName?** (string) - The name of the directory to create. * **options?** (CallOptions | null) - Optional call options. * **callback?** (ErrorCallback) - An optional callback function for error handling. ``` -------------------------------- ### Get Plugin Instance Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves an instance of a specific plugin by its name. Returns the plugin instance or null if the plugin is not found or inactive. ```typescript getPluginInstance(name: string): Plugin | null ``` -------------------------------- ### Get Plugin Configuration Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves the configuration for a specific plugin by its name. Returns the configuration object or null if the plugin is not found or inactive. ```typescript getPluginConfig(name: string): Record | null ``` -------------------------------- ### Get Foreign States (Callback) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Reads all states matching a pattern from the database using a callback. This is useful for fetching multiple states at once. ```javascript adapter.getStates('*', function (err, states) { for (var id in states) { adapter.log.debug('"' + id + '" = "' + states[id].val); } }); ``` ```typescript getForeignStates(pattern: Pattern, callback: GetStatesCallback): void ``` -------------------------------- ### Adapter Options Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/-internal-/interfaces/AdapterOptions.md This section outlines the optional configuration properties for an adapter. These properties allow customization of adapter behavior, such as handling state changes, managing object checks, and subscribing to system events. ```APIDOC ## Adapter Options ### Description Configuration options for an adapter instance. ### Properties - **useFormatDate?** (boolean) - Optional. If true, the date format from system.config will be used. - **subscribable?** (boolean) - Optional. If true, other instances can retrieve states of this adapter automatically. - **states?** (boolean) - Optional. If true, oStates will be enabled, providing a list of all state values that will be updated automatically. - **strictObjectChecks?** (boolean) - Optional. Defaults to true. If true, the adapter will warn if states are set without a corresponding existing object. - **systemConfig?** (boolean) - Optional. If true, the systemConfig (iobroker.json) will be available in `this.systemConfig`. - **stateChange?** (`StateChangeHandler`) - Optional. A callback function `(id, obj)` that will be called when a state changes. - **uiClientSubscribe?** (`UserInterfaceClientSubscribeHandler`) - Optional. A callback function that will be called when a new UI client subscribes. - **uiClientUnsubscribe?** (`UserInterfaceClientUnsubscribeHandler`) - Optional. A callback function that will be called when a new UI client unsubscribes. - **unload?** (`UnloadHandler`) - Optional. A callback function to stop the adapter. - **reconnect?** () => `MaybePromise` - Optional. Called on reconnection to the database. - **subscribesChange?** ((subs: Record) => void) - Optional. Callback function for subscribing to changes. It receives an object where keys are subscription patterns and values specify a regular expression. ``` -------------------------------- ### getChannelsOfAsync Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Asynchronously retrieves channels associated with a parent device. It can be called with no arguments to get all channels or with a parent device and optional options. ```APIDOC ## getChannelsOfAsync ### Description Asynchronously retrieves channels associated with a parent device. Returns a Promise that resolves with an array of ChannelObjects. ### Method Async ### Returns - **Promise** - A promise that resolves with an array of channel objects. ### Parameters #### parentDevice - **parentDevice** (string) - The ID of the parent device (optional). #### options - **options** (unknown) - Additional options for the retrieval (optional). ``` -------------------------------- ### Configure Syslog Logging in iobroker.json Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Sets up ioBroker to log messages to a syslog server. This configuration includes host, port, protocol, and other parameters, and is managed within iobroker.json. ```json5 { // ... "log": { // ... "transport": { // ... "syslog1": { "type": "syslog", "enabled": false, "host": "localhost", "host_comment": "The host running syslogd, defaults to localhost.", "port_comment": "The port on the host that syslog is running on, defaults to syslogd's default port(514/UDP).", "protocol": "udp4", "protocol_comment": "The network protocol to log over (e.g. tcp4, udp4, unix, unix-connect, etc).", "path_comment": "The path to the syslog dgram socket (i.e. /dev/log or /var/run/syslog for OS X).", "facility_comment": "Syslog facility to use (Default: local0).", "localhost": "iobroker", "localhost_comment": "Host to indicate that log messages are coming from (Default: localhost).", "sysLogType_comment": "The type of the syslog protocol to use (Default: BSD).", "app_name_comment": "The name of the application (Default: process.title).", "eol_comment": "The end of line character to be added to the end of the message (Default: Message without modifications)." } } } // ... } ``` -------------------------------- ### Get Channels Callback (No Parent) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves a list of all channels for the adapter instance using a callback. This version does not specify a parent device. ```javascript getChannels(callback) ``` -------------------------------- ### Set a value in Redis Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/db-states-file/README.md Demonstrates how to set a key-value pair in Redis using the ioredis client. ```javascript redis.set("foo", "bar") ``` -------------------------------- ### createDeviceAsync Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Asynchronously creates a device. This method is deprecated and `extendObject` should be used instead. ```APIDOC ## createDeviceAsync ### Description Asynchronously creates an object with the type 'device'. This method is deprecated. ### Method `createDeviceAsync` ### Parameters #### deviceName - **deviceName** (string) - The name of the device to create. #### common? - **common?** (Partial) - Optional common properties for the device. ### Returns - [`SetObjectPromise`](../-internal-/type-aliases/SetObjectPromise.md) - A promise that resolves with the result of the object creation. ### Deprecated use `extendObject` instead ``` -------------------------------- ### Configure File-Based Logging in iobroker.json Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Defines the default file logging settings, including log level, retention period, and output to stdout. This configuration is stored in the iobroker.json file. ```json5 { // ... "log": { "level": "info", "maxDays": 7, "noStdout": true, "transport": { "file1": { "type": "file", "enabled": true, "filename": "log/iobroker", "fileext": ".log", "maxsize": null, "maxFiles": null }, }, // ... }, } ``` -------------------------------- ### Define Adapter Dependencies with Version Range Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Specify adapter dependencies with a version range using JSON5 format in io-package.json. This ensures compatibility with specific versions of other adapters. ```json5 { "dependencies": [ { "js-controller": ">=2.0.0" } ], } ``` -------------------------------- ### Get Foreign State Async Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Reads a state's value from the database asynchronously. This is the preferred method for modern asynchronous programming patterns. ```typescript getForeignStateAsync(id: string, options?: unknown): GetStatePromise ``` -------------------------------- ### Get Devices (Async) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Asynchronously retrieves a list of all device objects within the adapter instance. Returns a Promise that resolves with an array of DeviceObject. ```typescript getDevicesAsync(options?: unknown): Promise; /** * Returns a list of all devices in this adapter instance */ ``` -------------------------------- ### Adapter Methods Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md This section details the methods available on the Adapter class for processing logs and managing log subscriptions. ```APIDOC ## Adapter Methods This section details the methods of the Adapter class. ### `processLog?` - **Description**: Processes a log message. - **Optional**: Yes - **Parameters**: - `msg` (`LogMessage`): The log message to process. - **Returns**: `void` ### `requireLog?` - **Description**: Starts or stops subscribing to log messages. The method is only available if `logTransporter` is active. - **Optional**: Yes - **Parameters**: - `isActive` (`boolean`): If log subscription should be activated or deactivated. - `options?` (`object`): Optional configuration for log subscription. - **Returns**: `void` | `Promise` - **Note**: Stopping will take effect after 10 seconds, not immediately. ``` -------------------------------- ### Get All Channels (Async) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Asynchronously retrieves a list of all channel objects within the adapter instance. Returns a Promise that resolves with an array of ChannelObject. ```typescript getChannelsOfAsync(): Promise; /** * Returns a list of all channels in this adapter instance */ ``` ```typescript getChannelsOfAsync(parentDevice: string, options?: unknown): Promise; /** * Returns a list of all channels in this adapter instance */ ``` -------------------------------- ### restart Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Restarts an instance of the adapter. ```APIDOC ## restart() ### Description Restarts an instance of the adapter. ### Returns - `void` ``` -------------------------------- ### Get Channels Async (No Parent) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Asynchronously retrieves a list of all channels for the adapter instance, returning a Promise. This version does not specify a parent device. ```javascript getChannelsAsync() ``` -------------------------------- ### Get Adapter Objects with Callback Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Retrieves all states, channels, and devices associated with the current adapter. Uses a callback function to process the results. ```javascript function (objects) { for (var id in objects) { adapter.log.debug(id); } } ``` ```typescript getAdapterObjects(callback: (objects) => void): Promise> ``` -------------------------------- ### mkdirAsync Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/-internal-/classes/ObjectsInRedisClient.md Asynchronously creates a new directory in the object storage. ```APIDOC ## mkdirAsync(id, dirName?, options?) ### Description Asynchronously creates a new directory in the object storage. ### Method (Implicitly a method call within the ObjectsInRedisClient class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **id** (string) - The ID of the parent directory or object. * **dirName?** (string) - The name of the directory to create. * **options?** (CallOptions) - Optional call options. ### Returns `Promise` - A promise that resolves when the directory is created. ``` -------------------------------- ### Define Simple Adapter Dependency Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Declare a simple adapter dependency in io-package.json when the specific version does not matter, only the presence of the adapter. ```json5 { "dependencies": [ "web" ], } ``` -------------------------------- ### Get Channels Async (With Parent and Options) Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Asynchronously retrieves a list of channels belonging to a specific parent device, with optional parameters, returning a Promise. ```javascript getChannelsAsync(parentDevice, options?) ``` -------------------------------- ### ConnectionOptions Interface Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/-internal-/interfaces/ConnectionOptions.md Defines the configuration options for establishing a connection. This interface includes properties for host, port, authentication credentials, data directory, logging preferences, and backup settings. ```APIDOC ## Interface: ConnectionOptions Defined in: db-base/build/esm/lib/inMemFileDB.d.ts:10 ### Properties - **host** (string | string[]) - Required - The host address or an array of host addresses for the connection, used with sentinels. - **port** (number | number[]) - Required - The port number or an array of port numbers for the connection, used with sentinels. - **options** (Record) - Required - Additional options for the connection. - **pass?** (string) - Optional - The password for authentication. - **sentinelName?** (string) - Optional - The name of the sentinel to connect to. - **enhancedLogging?** (boolean) - Optional - Enables enhanced logging for the connection. - **backup?** (BackupOptions) - Optional - Configuration for backup operations. - **dataDir?** (string) - Optional - The relative path to the data directory. ``` -------------------------------- ### createDeviceAsync Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Creates a device and its corresponding object. This method is deprecated and `extendObject` should be used instead. ```APIDOC ## createDeviceAsync ### Description Creates a device and its corresponding object. This method is deprecated and `extendObject` should be used instead. ### Method Signature `createDeviceAsync(deviceName: string, common: Partial, native?: Record): SetObjectPromise` ### Parameters * **deviceName** (string) - The name of the device to create. * **common** (Partial) - Common properties for the device. * **native?** (Record) - Optional native properties for the device. ### Returns `SetObjectPromise` - A promise that resolves when the device object is created. ### Deprecated Use `extendObject` instead. ``` ```APIDOC ## createDeviceAsync ### Description Creates a device and its corresponding object. This method is deprecated and `extendObject` should be used instead. ### Method Signature `createDeviceAsync(deviceName: string, common: Partial, native: Record, options?: unknown): SetObjectPromise` ### Parameters * **deviceName** (string) - The name of the device to create. * **common** (Partial) - Common properties for the device. * **native** (Record) - Native properties for the device. * **options?** (unknown) - Optional options. ### Returns `SetObjectPromise` - A promise that resolves when the device object is created. ### Deprecated Use `extendObject` instead. ``` -------------------------------- ### Send Async Command to Host for Controller Upgrade Source: https://github.com/iobroker/iobroker.js-controller/blob/master/README.md Initiates an asynchronous upgrade of the controller on a specified host. The controller will host a web server for status checks during the upgrade. ```typescript sendToHostAsync('system.host.test', 'upgradeController', { version: '5.0.5', adminInstance: 0 }); ``` -------------------------------- ### getPortAsync Source: https://github.com/iobroker/iobroker.js-controller/blob/master/packages/controller/doc/classes/AdapterClass.md Asynchronously finds the first free TCP port starting with the given port number. Returns a Promise that resolves with the free port number. ```APIDOC ## getPortAsync(port) ### Description Asynchronously finds the first free TCP port starting with the given port number. Returns a Promise that resolves with the free port number. ### Parameters #### port `number` - The port number to start the search for a free port. ### Returns `Promise` - A promise that resolves with the first available free port. ### Defined in [adapter/src/lib/adapter/adapter.ts:318](https://github.com/ioBroker/ioBroker.js-controller/blob/02dddaf5516d05753a8e9aab3348cecbe1788c1d/packages/adapter/src/lib/adapter/adapter.ts#L318) ```