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.
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}`);
}
@iobroker/type-detector
as npm modulevalve
and url
as types (they just a slider
and image
)rgbwSingle
device to typesrgbwSingle
devicergbOld
type from 2018DEVICES.md
rgbSingle
typeTIME_SUNRISE
and TIME_SUNSET
level.dimspeed
issuelevel.dimspeed
for dimmerbutton.press
Copyright (c) 2018-2024 Denis Haev dogafox@gmail.com
MIT License