Dm-utils - Utility classes for ioBroker adapters to support ioBroker.dm

Overview

dm-utils

Utility classes for ioBroker adapters to support ioBroker.dm.

How to use

In your ioBroker adapter, add a subclass of DeviceManagement and override the methods you need (see next chapters):

Example:

  • Create a subclass:
class MyAdapterDeviceManagement extends DeviceManagement<MyAdapter> {
    // contents see in the next chapters
}
  • Instantiate the subclass in your adapter class constructor:
class MyAdapter extends utils.Adapter {
	private readonly deviceManagement: MyAdapterDeviceManagement;

	public constructor(options: Partial<utils.AdapterOptions> = {}) {
		super({
			...options,
			name: "my-adapter",
		});
		this.deviceManagement = new DmTestDeviceManagement(this);

        // ... more code here
	}

Core concepts

Structure

In the UI, there are three levels of information:

  • In the top level, a list of all adapter instances is shown (only containing adapter instances that support device management).
  • Inside the adapter instance (when expanded), a list of devices is shown.
  • Devices may contain additional details, which are shown when the row of the device is expanded.

Actions

The device manager tab allows the user to interact with the adapter instance in two ways:

  • Actions per instance are shown above the list and should contain actions like "Search devices" or "Pair new device".
  • Actions per device are shown in the device list inside an instance and should contain actions like "Edit settings" or "Remove".

When the user clicks on an action (i.e. a button in the UI), the DeviceManagement implementation's handleXxxAction() is called and the adapter can perform arbitrary actions (see below for details).

Examples

To get an idea of how to use dm-utils, please have a look at:

DeviceManagement methods to override

All methods can either return an object of the defined value or a Promise resolving to the object.

This allows you to implement the method synchronously or asynchronously, depending on your implementation.

listDevices()

This method must always be overridden (as it is abstract in the base class).

You must return an array with information about all devices of this adapter's instance.

This method is called when the user expands an instance in the list.

In most cases, you will get all states of your instance and fill the array with the relevant information.

Every array entry is an object of type DeviceInfo which has the following properties:

  • id (string): a unique (human readable) identifier of the device (it must be unique for your adapter instance only)
  • name (string or translations): the human readable name of this device
  • status (optional): the current status of the device, which can be one of:
    • "disconnected"
    • "connected"
    • an object containing:
      • icon (string): an icon depicting the status of the device (see below for details)
      • description (string, optional): a text that will be shown as a tooltip on the status
  • actions (array, optional): an array of actions that can be performed on the device; each object contains:
    • id (string): unique identifier to recognize an action (never shown to the user)
    • icon (string): an icon shown on the button (see below for details)
    • description (string, optional): a text that will be shown as a tooltip on the button
    • disabled (boolean, optional): if set to true, the button can't be clicked but is shown to the user
  • hasDetails (boolean, optional): if set to true, the row of the device can be expanded and details are shown below

getInstanceInfo()

This method allows the device manager tab to gather some general information about the instance. It is called when the user opens the tab.

If you override this method, the returned object must contain:

  • apiVersion (string): the supported API version; must currently always be "v1"
  • actions (array, optional): an array of actions that can be performed on the instance; each object contains:
    • id (string): unique identifier to recognize an action (never shown to the user)
    • icon (string): an icon shown on the button (see below for details)
    • title (string): the title shown next to the icon on the button
    • description (string, optional): a text that will be shown as a tooltip on the button
    • disabled (boolean, optional): if set to true, the button can't be clicked but is shown to the user

getDeviceDetails(id: string)

This method is called if a device's hasDetails is set to true and the user clicks on the expander.

The returned object must contain:

  • id (string): the id given as parameter to the method call
  • schema (Custom JSON form schema): the schema of the Custom JSON form to show below the device information
  • data (object, optional): the data used to populate the Custom JSON form

For more details about the schema, see here.

Please keep in mind that there is no "Save" button, so in most cases, the form shouldn't contain editable fields, but you may use sendTo<xxx> objects to send data to the adapter.

`handleInstanceAction(actionId: string, context: ActionContext)

This method is called when to user clicks on an action (i.e. button) for an adapter instance.

The parameters of this method are:

  • actionId (string): the id that was given in getInstanceInfo() --> actions[].id
  • context (object): object containing helper methods that can be used when executing the action

The returned object must contain:

  • refresh (boolean): set this to true if you want the list to be reloaded after this action

This method can be implemented asynchronously and can take a lot of time to complete.

See below for how to interact with the user.

`handleDeviceAction(deviceId: string, actionId: string, context: ActionContext)

This method is called when to user clicks on an action (i.e. button) for a device.

The parameters of this method are:

  • deviceId (string): the id that was given in listDevices() --> [].id
  • actionId (string): the id that was given in listDevices() --> [].actions[].id
  • context (object): object containing helper methods that can be used when executing the action

The returned object must contain:

  • refresh (string / boolean): the following values are allowed:
    • "device": if you want the device details to be reloaded after this action
    • "instance": if you want the entire device list to be reloaded after this action
    • false: if you don't want anything to be refreshed (important: this is a boolean, not a string!)

This method can be implemented asynchronously and can take a lot of time to complete.

See below for how to interact with the user.

Action sequences

To allow your adapter to interact with the user, you can use "actions".

As described above, there are actions on the instance and on devices. The behavior of both methods are similar.

Inside an action method (handleInstanceAction() or handleDeviceAction()) you can perform arbitrary actions, like talking to a device or API and you can interact with the user. For interactions, there are methods you can call on context:

showMessage(text: ioBroker.StringOrTranslated)

Shows a message to the user.

The method has the following parameter:

  • text (string or translation): the text to show to the user

This asynchronous method returns (or rather: the Promise is resolved) once the user has clicked on "OK".

showConfirmation(text: ioBroker.StringOrTranslated)

Let's the user confirm an action by showing a message with an "OK" and "Cancel" button.

The method has the following parameter:

  • text (string or translation): the text to show to the user

This asynchronous method returns (or rather: the Promise is resolved) once the user has clicked a button in the dialog:

  • true if the user clicked "OK"
  • false if the user clicked "Cancel"

showForm(schema: JsonFormSchema, data?: JsonFormData)

Shows a dialog with a Custom JSON form that can be edited by the user.

The method has the following parameters:

  • schema (Custom JSON form schema): the schema of the Custom JSON form to show in the dialog
  • data (object, optional): the data used to populate the Custom JSON form

This asynchronous method returns (or rather: the Promise is resolved) once the user has clicked a button in the dialog:

  • the form data, if the user clicked "OK"
  • undefined, if the user clicked "Cancel"

Your own adapter methods

You can easily call synchronous or asynchronous methods on your adapter. The adapter object is available as this.adapter in the action handler methods.

You might also like...

A utility for creating toggleable items with JavaScript. Inspired by bootstrap's toggle utility. Implemented in vanillaJS in a functional style.

LUX TOGGLE Demo: https://jesschampion.github.io/lux-toggle/ A utility for creating toggleable dom elements with JavaScript. Inspired by bootstrap's to

Oct 3, 2020

utility library for promise, support both commonjs and ESM

promising-utils A utility library for promise, supports both commonjs and ESM npm install promising-utils --save yarn add promising-utils wait Used wh

Oct 18, 2022

Small library to create classes without using class syntax.

Clazz.js Small library to create classes without using class syntax. Compatibility For internet explorer 11 or higher. Example script src="Clazz.js"

Dec 25, 2021

A concise collection of classes for PHP, Python, JavaScript and Ruby to calculate great circle distance, bearing, and destination from geographic coordinates

GreatCircle A set of three functions, useful in geographical calculations of different sorts. Available for PHP, Python, Javascript and Ruby. Live dem

Sep 30, 2022

Qwerty is the first social website focused on connecting students with similar classes and gender identities

Qwerty is the first social website focused on connecting students with similar classes and gender identities

🌈 Qwerty 🌈 Qwerty is the first social website focused on connecting students with similar classes and gender identities. To get started simply input

Oct 21, 2022

This plugin add a new utilities classes so you can use from 0% to 100%!

This plugin add new utilities classes so you can use from 0% to 100%!

Apr 3, 2022

linuxbu - a chrome extension that helps you to enter SBU classes via html-view in linux

linuxbu is a chrome extension that helps you to enter SBU classes via html-view in linux

Dec 19, 2022

Personal project to a student schedule classes according his course level. Using GraphQL, Clean Code e Clean Architecture.

Personal project to a student schedule classes according his course level. Using GraphQL, Clean Code e Clean Architecture.

classes-scheduler-graphql This is a personal project for student scheduling, with classes according his course level. I intend to make just the backen

Jul 9, 2022

A new project from Edgemony classes

A new project from Edgemony classes

TRICILY A new project from Edgemony classes Technologies used HTML5 CSS3 SASS Javascript React.js Next.js Musement API Made with ❀ Features Designed

Jun 11, 2022
Owner
Samuel Weibel
Software developer with a passion for the internet of things. Currently working mostly on ioBroker projects.
Samuel Weibel
đŸ€– Tailwind CSS assistant helps you to edit classes (includes JIT & ignores purge), toggle breakpoint classes on an element and view current breakpoint

Tailwind CSS Assistant See it in action on this example website ?? ✅ Small JavaScript package that helps you work with Tailwind CSS by... Showing you

Mark Mead 30 Dec 28, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till mÀnniskor pÄ flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
An npm package with Tailwind CSS utility classes for creating responsive grid columns without media queries using auto fit.

Grid Auto Fit for Tailwind CSS A plugin that helps you create a responsive grid layout in Tailwind CSS without using media queries. It uses the auto-f

Thirus 80 Dec 28, 2022
Query for CSS brower support data, combined from caniuse and MDN, including version support started and global support percentages.

css-browser-support Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentage

Stephanie Eckles 65 Nov 2, 2022
Temporal-time-utils - This is a library with some reusable functions for Temporal.io TypeScript SDK

temporal-time-utils This is a library with some reusable functions for Temporal.io TypeScript SDK: sleepUntil: sleep to a specific date, instead of by

swyx 15 Oct 18, 2022
DevArms - a collection of developer utils that gives you extra arms to reach more in your tasks

DevArms is a collection of developer utils that gives you extra arms to reach more in your tasks. It runs completely offline, and cross-platform across Windows, Mac and Linux. Written in Rust, React. Powered by Tauri.

Qiushi Pan 82 Dec 18, 2022
SUID is all a set of utils and components ported from MUI Core and much more.

Solid.js User Interface Design (SUID) A port of Material-UI (MUI) built with Solid.js SUID is all a set of utils and components ported from MUI Core a

null 311 Jan 1, 2023
Simple utils to pack arrays, objects and strings to a flat object (and back again).

packrup Simple utils to pack (and unpack) arrays and strings to a flat object. Status: In Development Please report any issues ?? Made possible by my

Harlan Wilton 15 Dec 23, 2022