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, { type DetectOptions, type Types } from '@iobroker/type-detector';
const detector: ChannelDetector = new ChannelDetector();
const keys = Object.keys(objects); // For optimization
const usedIds: string[] = []; // To not allow using of same ID in more than one device
const ignoreIndicators: string[] = ['UNREACH_STICKY']; // Ignore indicators by name
const allowedTypes: Types[] = ['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: PatternControl[] = 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}`);
}
- (@Apollon77) Fixed default unit for Illuminance to "lux"
- (@Apollon77) Added Low-Battery state for switch to be consistent with other devices
- (@Garfonso) Added new device type - illuminance (brightness sensor)
- (@Garfonso) Added battery state
- (@Garfonso) Added the transition time state
- (@Garfonso) Allowed the mixed
device->state
anddevice->channel->state
structures - (@GermanBluefox) Used new eslint config library
- (@GermanBluefox) Types were slightly changed
- (Apollon77) Removed File state type
- (Apollon77) Adjusted Camera states to remove Binary state and replace by link
- (Apollon77) Fixed role for ACTUAL state for socket
- (Apollon77) Fix Electricity states for light type
- (Apollon77) Add Electricity states for more types
- (Apollon77) Internal Refactoring
- (bluefox) Implemented
@iobroker/type-detector
as npm module
- (bluefox) Removed
valve
andurl
as types (they just aslider
andimage
)
- (bluefox) Removed multiple for weather location
- (Garfonso) Changed detection of fire and flood sensors
- (Garfonso) Changed the role of TIME_SUNRISE and TIME_SUNSET
- (Garfonso) Added
rgbwSingle
device to types
- (bluefox) Added
rgbwSingle
device
- (bluefox) Removed
rgbOld
type from 2018
- (bluefox) Fixed creation of the
DEVICES.md
- (bluefox) Fixed the main attribute in package.json
- (bluefox) Better detection of the door devices
- (Garfonso) corrected the double states in light devices
- (Garfonso) added CIE color type as equivalent to
rgbSingle
type
- (Garfonso) blinds: corrected error in the default role for tilt
- (bluefox) Fixed the main attribute in package.json
- (algar42) extend the weather forecast device with
TIME_SUNRISE
andTIME_SUNSET
- (Garfonso) added weatherForecast tests
- (bluefox) Added chart device
- (bluefox) Changed the air conditioner detection
- (Garfonso) Corrected blind with buttons
- (bluefox) Changed the air conditioner detection
- (Garfonso) Corrected blind with buttons
- (Garfonso) Added buttons to blinds and added THE new type: blinds with only buttons
- (agross) refactoring
- (bluefox) Extend socket and light with electricity parameters
- (bluefox) Added some states to thermostat
- (bluefox) Added new types: gate, camera, flood alarm, current weather.
- (bluefox) Escape chars in IDs.
- (bluefox) Added the vacuum cleaner.
- (bluefox) Added the air conditioner.
- (Garfonso) The switch could have the boolean type
- (Garfonso) Fixed
level.dimspeed
issue
- (bluefox) Ignore
level.dimspeed
for dimmer - (bluefox) Added new type
button.press
- (Garfonso) Added "white" to rgb
- (bluefox) Add default roles
- (bluefox) Fixed search for multiple items.
- (bluefox) Added function "getPatterns".
- (bluefox) Add description to function "detect".
- (kirovilya) In some cases, devices may not have channels, but immediately have a states. For example, in the zigbee-adapter.
- (bluefox) added PRECIPITATION to weather
- (bluefox) added location detection
- (bluefox) initial commit
Copyright (c) 2018-2024 Denis Haev [email protected]
MIT License