@iobroker/adapter-core
- Version 3.3.2
- Published
- 141 kB
- No dependencies
- MIT license
Install
npm i @iobroker/adapter-core
yarn add @iobroker/adapter-core
pnpm add @iobroker/adapter-core
Overview
Core module to be used in ioBroker adapters. Acts as the bridge to js-controller.
Index
Variables
variable adapter
const adapter: AdapterConstructor;
Creates a new adapter instance
variable Adapter
const Adapter: AdapterConstructor;
Creates a new adapter instance
variable commonTools
const commonTools: { pattern2RegEx: typeof pattern2RegEx; getAdapterDir: typeof getAdapterDir; getInstalledInfo: typeof getInstalledInfo; isDocker: typeof isDocker; getLocalAddress: typeof getLocalAddress; getListenAllAddress: typeof getListenAllAddress; isLocalAddress: typeof isLocalAddress; isListenAllAddress: typeof isListenAllAddress; password: any; session: any; zipFiles: any;};
variable controllerDir
const controllerDir: string;
The root directory of JS-Controller
variable EXIT_CODES
const EXIT_CODES: Readonly<{ NO_ERROR: number; JS_CONTROLLER_STOPPED: number; INVALID_ADAPTER_CONFIG: number; NO_ADAPTER_CONFIG_FOUND: number; INVALID_CONFIG_OBJECT: number; INVALID_ADAPTER_ID: number; UNCAUGHT_EXCEPTION: number; ADAPTER_ALREADY_RUNNING: number; INSTANCE_IS_DISABLED: number; CANNOT_GZIP_DIRECTORY: number; CANNOT_FIND_ADAPTER_DIR: number; ADAPTER_REQUESTED_TERMINATION: number; UNKNOWN_PACKET_NAME: number; ADAPTER_REQUESTED_REBUILD: number; CANNOT_READ_INSTANCES: number; NO_MULTIPLE_INSTANCES_ALLOWED: number; NO_MULTIPLE_INSTANCES_ALLOWED_ON_HOST: number; NO_CONNECTION_TO_OBJ_DB: number; NO_CONNECTION_TO_STATES_DB: number; INSTANCE_ALREADY_EXISTS: number; CANNOT_INSTALL_NPM_PACKET: number; CANNOT_EXTRACT_FROM_ZIP: number; INVALID_IO_PACKAGE_JSON: number; CANNOT_COPY_DIR: number; MISSING_ADAPTER_FILES: number; INVALID_NPM_VERSION: number; INVALID_NODE_VERSION: number; INVALID_OS: number; INVALID_DEPENDENCY_VERSION: number; INVALID_ARGUMENTS: number; INVALID_PASSWORD: number; MISSING_CONFIG_JSON: number; CANNOT_DELETE_NON_DELETABLE: number; CANNOT_GET_STATES: number; CANNOT_GET_REPO_LIST: number; START_IMMEDIATELY_AFTER_STOP: number;}>;
Functions
function getAbsoluteDefaultDataDir
getAbsoluteDefaultDataDir: () => string;
Returns the absolute path of the data directory for the current host. On linux, this is usually
/opt/iobroker/iobroker-data
.
function getAbsoluteInstanceDataDir
getAbsoluteInstanceDataDir: ( adapterObjectOrNamespace: ioBroker.Adapter | string) => string;
Returns the absolute path of the data directory for the current adapter instance. On linux, this is usually
/opt/iobroker/iobroker-data/<adapterName>.<instanceNr>
Parameter adapterObjectOrNamespace
The adapter instance or namespace string (e.g. "myAdapter.0").
function getConfig
getConfig: () => Record<string, any>;
Reads the configuration file of JS-Controller
Interfaces
interface AdapterInstance
interface AdapterInstance< HasObjectsCache extends boolean | undefined = undefined, HasStatesCache extends boolean | undefined = undefined> extends ioBroker.Adapter {}
This type is used to include and exclude the states and objects cache from the adapter's type definition depending on the creation options
Type Aliases
type AdapterOptions
type AdapterOptions< HasObjectsCache extends boolean | undefined = undefined, HasStatesCache extends boolean | undefined = undefined> = Omit<ioBroker.AdapterOptions, 'objects' | 'states'> & (true extends HasObjectsCache ? { objects: true; } : { objects?: HasObjectsCache; }) & (true extends HasStatesCache ? { states: true; } : { states?: HasStatesCache; });
This type augments the ioBroker Adapter options to accept two generics for the objects and states cache
Namespaces
namespace I18n
module 'build/esm/i18n.d.ts' {}
Init internationalization
Parameter rootDir
The path, where i18n directory is located
Parameter languageOrAdapter
The adapter instance or the language to use
variable _default
const _default: { init: typeof init; translate: typeof translate; getTranslatedObject: typeof getTranslatedObject; t: typeof translate;};
variable t
const t: (key: string, ...args: (string | number | boolean)[]) => string;
Alias shortcut for translate function
function getTranslatedObject
getTranslatedObject: ( key: string, ...args: (string | number | boolean | null)[]) => ioBroker.Translated;
Get translation as ioBroker.Translated object
Parameter key
Word to translate
Parameter args
Optional parameters to replace %s
function init
init: ( rootDir: string, languageOrAdapter: ioBroker.Adapter | ioBroker.Languages) => Promise<void>;
Init internationalization
Parameter rootDir
The path, where i18n directory is located
Parameter languageOrAdapter
The adapter instance or the language to use
function translate
translate: ( key: string, ...args: (string | number | boolean | null)[]) => string;
Get translation as one string
Parameter key
Word to translate
Parameter args
Optional parameters to replace %s
namespace TokenRefresher
module 'build/esm/TokenRefresher.d.ts' {}
Token structure
class TokenRefresher
class TokenRefresher {}
TokenRefresher class manages OAuth2 access tokens for an ioBroker adapter.
constructor
constructor(adapter: ioBroker.Adapter, serviceName: string, stateName?: string);
Creates an instance of TokenRefresher.
Parameter adapter
Instance of ioBroker adapter
Parameter serviceName
Name of the service for which the tokens are managed, e.g., 'spotify', 'dropbox', etc.
Parameter stateName
Optional name of the state where tokens are stored. Defaults to 'oauth2Tokens' and that will store tokens in
ADAPTER.X.oauth2Tokens
.
property TOKEN_REFRESH_THRESHOLD_MS
static TOKEN_REFRESH_THRESHOLD_MS: number;
Threshold in milliseconds before the access token expires to trigger a refresh
method destroy
destroy: () => void;
Destroys the TokenRefresher instance, clearing any timeouts and stopping state subscriptions.
method getAccessToken
getAccessToken: () => Promise<string | undefined>;
Returns the access token if it is valid and not expired.
method onStateChange
onStateChange: (id: string, state: ioBroker.State | null | undefined) => void;
This method is called when the state changes for the token.
Parameter id
ID of the state that changed
Parameter state
Value
interface AccessTokens
interface AccessTokens {}
Token structure
property access_token
access_token: string;
The access token used for authentication
property access_token_expires_on
access_token_expires_on: string;
The date and time when the access token expires, in ISO format
property expires_in
expires_in: number;
Interval in seconds, when access token will expire
property ext_expires_in
ext_expires_in: number;
Extended expiration time in seconds, when the access token will expire
property refresh_token
refresh_token: string;
The refresh token used to obtain a new access token
property scope
scope: string;
Scopes
property token_type
token_type: 'Bearer';
Type
Package Files (5)
Dependencies (0)
No dependencies.
Dev Dependencies (23)
- @alcalzone/esm2cjs
- @alcalzone/release-script
- @alcalzone/release-script-plugin-license
- @iobroker/eslint-config
- @types/chai
- @types/chai-as-promised
- @types/mocha
- @types/node
- @types/proxyquire
- @types/sinon
- @types/sinon-chai
- chai
- chai-as-promised
- cpy-cli
- mocha
- prettier
- proxyquire
- rimraf
- sinon
- sinon-chai
- source-map-support
- ts-node
- typescript
Peer Dependencies (1)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@iobroker/adapter-core
.
- Markdown[](https://www.jsdocs.io/package/@iobroker/adapter-core)
- HTML<a href="https://www.jsdocs.io/package/@iobroker/adapter-core"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3571 ms. - Missing or incorrect documentation? Open an issue for this package.