ioBroker / ioBroker.type-detector

Helper module (not adapter) to detect types of devices
MIT License
8 stars 9 forks source link
iobroker

ioBroker.type-detector

This is not the adapter. This is help function to detect devices from ioBroker states and channels.

You can find the description of devices in DEVICES.md.

How to use

You can use this module in Browser and in Node.js projects.

Just now this module used in material adapter to detect devices and to visualize them.

The following code detects devices in some state's tree:

import ChannelDetector, { DetectOptions } from '@iobroker/type-detector';
const detector = new ChannelDetector();

const keys = Object.keys(objects);              // For optimization
const usedIds = [];                             // To not allow using of same ID in more than one device
const ignoreIndicators = ['UNREACH_STICKY'];    // Ignore indicators by name
const allowedTypes = ['button', 'rgb', 'dimmer', 'light'];  // Supported types. Leave it null if you want to get ALL devices.

const options: DetectOptions = {
    objects:            this.props.objects,
    id:                 'hm-rpc.0.LEQ1214232.1', // Channel, device or state, that must be detected
    _keysOptional:      keys,
    _usedIdsOptional:   usedIds,
    ignoreIndicators,
//    allowedTypes,
};

let controls = detector.detect(options);
if (controls) {
    controls = controls.map((control: PatternControl) => {
        const id = control.states.find((state: DetectorState) => state.id).id;
        if (id) {
            console.log(`In ${options.id} was detected "${control.type}" with following states:`);
            control.states
                .filter((state: DetectorState) => state.id)
                .forEach((state: DetectorState) => {
                    console.log(`    ${state.name} => ${state.id}`);
                });

            return {control, id};
        }
    });
} else {
    console.log(`Nothing found for ${options.id}`);
}
// Legacy
const { ChannelDetector } = require('iobroker.type-detector');
const detector = new ChannelDetector();

const keys = Object.keys(objects);              // For optimization
const usedIds = [];                             // To not allow using of same ID in more than one device
const ignoreIndicators = ['UNREACH_STICKY'];    // Ignore indicators by name
const allowedTypes = ['button', 'rgb', 'dimmer', 'light'];  // Supported types. Leave it null if you want to get ALL devices.

const options = {
    objects:            this.props.objects,
    id:                 'hm-rpc.0.LEQ1214232.1', // Channel, device or state, that must be detected
    _keysOptional:      keys,
    _usedIdsOptional:   usedIds,
    ignoreIndicators,
//    allowedTypes,
};

let controls = detector.detect(options);
if (controls) {
    controls = controls.map(control => {
        const id = control.states.find(state => state.id).id;
        if (id) {
            console.log(`In ${options.id} was detected "${control.type}" with following states:`);
            control.states
                .filter(state => state.id)
                .forEach(state => {
                    console.log(`    ${state.name} => ${state.id}`);
                });

            return {control, id};
        }
    });
} else {
    console.log(`Nothing found for ${options.id}`);
}

Changelog

4.0.1 (2024-07-26)

3.0.5 (2023-10-24)

2.0.6 (2023-10-18)

2.0.4 (2023-10-13)

2.0.3 (2023-10-09)

2.0.2 (2023-09-04)

2.0.1 (2023-08-21)

2.0.0 (2023-08-21)

1.1.2 (2023-06-06)

1.1.1 (2022-11-09)

1.1.0 (2022-05-22)

1.0.17 (2022-01-20)

1.0.15 (2021-07-09)

1.0.14 (2021-06-30)

1.0.13 (2021-06-27)

1.0.12 (2021-06-16)

1.0.11 (2021-06-11)

1.0.10 (2021-06-07)

1.0.9 (2021-06-06)

1.0.8 (2021-03-11)

1.0.7 (2020-08-12)

1.0.4 (2020-08-12)

1.0.0 (2020-08-10)

0.1.10 (2020-06-23)

0.1.9 (2020-01-12)

0.1.7 (2019-08-14)

0.1.5 (2019-07-23)

0.1.4 (2019-07-19)

0.1.3 (2019-07-16)

0.1.1 (2019-06-29)

0.1.1 (2019-05-24)

0.1.0 (2018-08-14)

License

Copyright (c) 2018-2024 Denis Haev dogafox@gmail.com

MIT License