Skip to content

Commit

Permalink
chore: release v1.0.14
Browse files Browse the repository at this point in the history
Add chart device
  • Loading branch information
GermanBluefox committed Jun 30, 2021
1 parent a5dddc8 commit 5d43845
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 16 deletions.
6 changes: 6 additions & 0 deletions DEVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ What is not important for detection:
| | ERROR | indicator.error | | | X | | ``/^indicator\.error$/`` |


### chart
| R | Name | Ind | Mult |
|---|-------|-----|------|
| | CHART | | |


### Light with color temperature
| R | Name | Role | Unit | Type | Wr | Ind | Mult | Regex |
|---|-------------|-------------------------------|------|---------|----|-----|------|--------------------------------------------------------------------------------|
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ if (controls) {
-->

## Changelog
### 1.0.14 (2021-06-30)
* (bluefox) Add chart device

### 1.0.13 (2021-06-27)
* (bluefox) Changed the air conditioner detection
* (Garfonso) Corrected blind with buttons
Expand Down
42 changes: 27 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var Types = {
buttonSensor: 'buttonSensor',
camera: 'camera',
url: 'url',
chart: 'chart',
image: 'image',
dimmer: 'dimmer',
door: 'door',
Expand Down Expand Up @@ -110,6 +111,12 @@ function ChannelDetector() {
}

var patterns = {
chart: {
states: [
{objectType: 'chart', name: 'CHART'}
],
type: Types.chart
},
mediaPlayer: {
// receive the state of player via media.state. Controlling of the player via buttons
states: [
Expand Down Expand Up @@ -528,7 +535,7 @@ function ChannelDetector() {
},
fireAlarm: {
states: [
{role: /^state(\.alarm)?\.fire$|^sensor(\.alarm)?\.fire/, indicator: false, type: 'boolean', name: 'ACTUAL', required: true, channelRole: /^sensor(\.alarm)?\.fire$/, defaultRole: 'sensor.alarm.fire'},
{role: /^state(\.alarm)?\.fire$|^sensor(\.alarm)?\.fire/, indicator: false, type: 'boolean', name: 'ACTUAL', required: true, channelRole: /^sensor(\.alarm)?\.fire$/, defaultRole: 'sensor.alarm.fire', defaultChannelRole: 'sensor.alarm.fire'},
// optional
SharedPatterns.unreach,
SharedPatterns.lowbat,
Expand All @@ -540,7 +547,7 @@ function ChannelDetector() {
},
floodAlarm: {
states: [
{role: /^state(\.alarm)?\.flood$|^sensor(\.alarm)?\.flood/, indicator: false, type: 'boolean', name: 'ACTUAL', required: true, channelRole: /^sensor(\.alarm)?\.flood$/, defaultRole: 'sensor.alarm.flood'},
{role: /^state(\.alarm)?\.flood$|^sensor(\.alarm)?\.flood/, indicator: false, type: 'boolean', name: 'ACTUAL', required: true, channelRole: /^sensor(\.alarm)?\.flood$/, defaultRole: 'sensor.alarm.flood', defaultChannelRole: 'sensor.alarm.flood'},
// optional
SharedPatterns.unreach,
SharedPatterns.lowbat,
Expand Down Expand Up @@ -857,8 +864,8 @@ function ChannelDetector() {
function getAllStatesInChannel(keys, channelId) {
var list = [];
var reg = new RegExp('^' + channelId.replace(/([$^.)([\]{}])/g, '\\$1') + '\\.[^.]+$');
keys.forEach(function(_id) {
if (reg.test(_id)) list.push(_id);
keys.forEach(function (_id) {
reg.test(_id) && list.push(_id);
});
return list;
}
Expand Down Expand Up @@ -911,7 +918,11 @@ function ChannelDetector() {
}
}
if (role === false) {
return;
return false;
}

if (statePattern.objectType && objects[id].type !== statePattern.objectType) {
return false;
}

if (statePattern.stateName && !statePattern.stateName.test(id)) {
Expand All @@ -923,37 +934,37 @@ function ChannelDetector() {
}

if (statePattern.ignoreRole && statePattern.ignoreRole.test(objects[id].common.role)) {
return;
return false;
}

if (statePattern.indicator === false && (objects[id].common.role || '').match(/^indicator(\.[.\w]+)?$/)) {
return;
return false;
}

if (statePattern.state && !statePattern.state.test(id.split('.').pop())) {
return;
return false;
}

if (statePattern.write !== undefined && statePattern.write !== (objects[id].common.write || false)) {
return;
return false;
}

if (statePattern.min === 'number' && typeof objects[id].common.min !== 'number') {
return;
return false;
}

if (statePattern.max === 'number' && typeof objects[id].common.max !== 'number') {
return;
return false;
}

if (statePattern.read !== undefined && statePattern.read !== (objects[id].common.read === undefined ? true : objects[id].common.read)) {
return;
return false;
}

if (statePattern.type) {
if (typeof statePattern.type === 'string') {
if (statePattern.type !== objects[id].common.type) {
return;
return false;
}
} else {
var noOneOk = true;
Expand All @@ -964,15 +975,15 @@ function ChannelDetector() {
}
}
if (noOneOk) {
return;
return false;
}
}
}

if (statePattern.enums && typeof statePattern.enums === 'function') {
var enums = this._getEnumsForId(objects, id);
if (!statePattern.enums(objects[id], enums)) {
return;
return false;
}
}

Expand Down Expand Up @@ -1131,6 +1142,7 @@ function ChannelDetector() {

function getChannelStates(objects, id, keys) {
switch (objects[id].type) {
case 'chart':
case 'state':
return [id];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.type-detector",
"version": "1.0.13",
"version": "1.0.14",
"description": "Detects devices in ioBroker for Material, Google home, Homekit, ...",
"author": {
"name": "bluefox",
Expand Down
22 changes: 22 additions & 0 deletions test/cameras.0.cameras.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"cameras.0.cameras": {
"_id": "cameras.0.cameras",
"type": "channel",
"common": {
"name": "Cameras"
},
"native": {}
},
"cameras.0.cameras.cam1": {
"_id": "cameras.0.cameras.cam1",
"common": {
"name": "Floor camera",
"desc": "Floor camera",
"role": "camera",
"type": "file"
},
"binary": true,
"type": "state",
"native": {}
}
}
92 changes: 92 additions & 0 deletions test/detector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,96 @@ describe('Test Detector', () => {

done();
});

it('Must detect cameras from states', done => {
const detector = new ChannelDetector();

const objects = require('./cameras.0.cameras.json');

Object.keys(objects).forEach(id => objects[id]._id = id);

const options = {
objects,
id: Object.keys(objects)[0],
_keysOptional: Object.keys(objects),
_usedIdsOptional: [],
//allowedTypes: [Types.airCondition], // for tests
};

const controls = detector.detect(options);

console.log(JSON.stringify(controls));
expect(controls[0].type).to.be.equal(Types.camera);

const powerId = controls[0].states.find(s => s.name === 'FILE').id;
expect(powerId).to.be.equal('cameras.0.cameras.cam1');

done();
});

it('Must detect charts from states', done => {
const detector = new ChannelDetector();

const objects = {
"echarts.0.Place.PresetMy": {
"common": {
"name": "PresetMy"
},
"native": {
"url": "",
"data": {

}
},
"type": "chart",
"_id": "echarts.0.Place.PresetMy"
}
};

Object.keys(objects).forEach(id => objects[id]._id = id);

const options = {
objects,
id: Object.keys(objects)[0],
_keysOptional: Object.keys(objects),
_usedIdsOptional: [],
//allowedTypes: [Types.airCondition], // for tests
};

const controls = detector.detect(options);

console.log(JSON.stringify(controls));
expect(controls[0].type).to.be.equal(Types.chart);

const powerId = controls[0].states.find(s => s.name === 'CHART').id;
expect(powerId).to.be.equal('echarts.0.Place.PresetMy');

done();
});

it('Must detect fire sensor from states', done => {
const detector = new ChannelDetector();

const objects = require('./fireSensor.json');

Object.keys(objects).forEach(id => objects[id]._id = id);

const options = {
objects,
id: Object.keys(objects)[0],
_keysOptional: Object.keys(objects),
_usedIdsOptional: [],
//allowedTypes: [Types.airCondition], // for tests
};

const controls = detector.detect(options);

console.log(JSON.stringify(controls));
expect(controls[0].type).to.be.equal(Types.fireAlarm);

const powerId = controls[0].states.find(s => s.name === 'ACTUAL').id;
expect(powerId).to.be.equal('alias.0.MyFolder.Gerät_1.ACTUAL');

done();
});
});
30 changes: 30 additions & 0 deletions test/fireSensor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"alias.0.MyFolder.Gerät_1": {
"_id": "alias.0.MyFolder.Gerät_1",
"common": {
"name": {
"de": "Gerät 1"
},
"role": "sensor.alarm.fire",
"icon": "",
"color": null
},
"native": {},
"type": "channel"
},
"alias.0.MyFolder.Gerät_1.ACTUAL": {
"_id": "alias.0.MyFolder.Gerät_1.ACTUAL",
"common": {
"name": "ACTUAL",
"role": "sensor.alarm.fire",
"type": "boolean",
"read": true,
"write": false,
"alias": {
"id": "consumption.0.instances.12_03b81.trigger"
}
},
"native": {},
"type": "state"
}
}

0 comments on commit 5d43845

Please sign in to comment.