Skip to content

Commit

Permalink
### 2.1.1 (2016-05-21)
Browse files Browse the repository at this point in the history
* (bluefox) try to fix "Duplicate name" error
* (bluefox) modify readFile/wrieFile commands
* (gh-god) fix stop of script and unsubscribe
* (paul53) check type of set value and min, max by setState
  • Loading branch information
GermanBluefox committed May 21, 2016
1 parent ab02d77 commit 5f041e5
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -751,10 +751,11 @@ Scripts can be activated and deactivated by controlling of this state with ack=f


## Changelog
### 2.1.1 (2016-05-20)
### 2.1.1 (2016-05-21)
* (bluefox) try to fix "Duplicate name" error
* (bluefox) modify readFile/wrieFile commands
* (gh-god) fix stop of script and unsubscribe
* (paul53) check type of set value and min, max by setState

### 2.1.0 (2016-05-13)
* (bluefox) add getHistory command
Expand Down
6 changes: 3 additions & 3 deletions io-package.json
Expand Up @@ -8,9 +8,9 @@
"hobbyquaker <hq@ccu.io>"
],
"news": {
"en": "(bluefox) try to fix Duplicate name error\n(bluefox) add getFile/setFile commands\n(gh-god) fix stop of script and unsubscribe",
"de": "(bluefox) try to fix Duplicate name error\n(bluefox) add getFile/setFile commands\n(gh-god) fix stop of script and unsubscribe",
"ru": "(bluefox) try to fix Duplicate name error\n(bluefox) add getFile/setFile commands\n(gh-god) fix stop of script and unsubscribe"
"en": "(bluefox) try to fix Duplicate name error\n(bluefox) modify writeFile/readFile commands\n(gh-god) fix stop of script and unsubscribe\n(paul53) check type of set value and min, max by setState",
"de": "(bluefox) try to fix Duplicate name error\n(bluefox) modify writeFile/readFile commands\n(gh-god) fix stop of script and unsubscribe\n(paul53) check type of set value and min, max by setState",
"ru": "(bluefox) try to fix Duplicate name error\n(bluefox) modify writeFile/readFile commands\n(gh-god) fix stop of script and unsubscribe\n(paul53) check type of set value and min, max by setState"
},
"desc": "Javascript/Coffeescript Script Engine",
"platform": "Javascript/Node.js",
Expand Down
74 changes: 74 additions & 0 deletions javascript.js
Expand Up @@ -1442,6 +1442,24 @@
}
}

// Check type of state
var common = objects[id] ? objects[id].common : null;
if (common &&
common.type &&
common.type !== 'mixed' &&
common.type !== 'file' &&
common.type !== 'json' &&
common.type !== typeof state.val
) {
adapter.log.warn('Wrong type of ' + id + '.state. Please fix, while deprecated and will not work in next versions.');
//return;
}
// Check min and max of value
if (common && typeof state.val === 'number') {
if (common.min !== undefined && state.val < common.min) state.val = common.min;
if (common.max !== undefined && state.val > common.max) state.val = common.max;
}

if (states[id]) {
adapter.setForeignState(id, state, function () {
if (typeof callback === 'function') callback();
Expand Down Expand Up @@ -1653,6 +1671,62 @@

native = native || {};

// Check min, max and def values for number
if (common.type !== undefined && common.type === 'number') {
var min = 0;
var max = 0;
var def = 0;
var err;
if (common.min !== undefined) {
min = common.min;
if (typeof min !== 'number') {
min = parseFloat(min);
if (isNaN(min)) {
err = 'Wrong type of ' + id + '.common.min';
logger.error(err);
if (callback) callback(err);
return;
} else {
common.min = min;
}
}
}
if (common.max !== undefined) {
max = common.max;
if (typeof max !== 'number') {
max = parseFloat(max);
if (isNaN(max)) {
err = 'Wrong type of ' + id + '.common.max';
logger.error(err);
if (callback) callback(err);
return;
} else {
common.max = max;
}
}
}
if (common.def !== undefined) {
def = common.def;
if (typeof def !== 'number') {
def = parseFloat(def);
if (isNaN(def)) {
err = 'Wrong type of ' + id + '.common.def';
logger.error(err);
if (callback) callback(err);
return;
} else {
common.def = def;
}
}
}
if (common.min !== undefined && common.max !== undefined && min > max) {
common.max = min;
common.min = max;
}
if (common.def !== undefined && common.min !== undefined && def < min) common.def = min;
if (common.def !== undefined && common.max !== undefined && def > max) common.def = max;
}

if (forceCreation) {
adapter.setObject(name, {
common: common,
Expand Down
4 changes: 2 additions & 2 deletions test/testFunctions.js
Expand Up @@ -112,7 +112,7 @@ describe('Test JS', function() {
this.timeout(5000);
checkConnectionOfAdapter(done);
});
/*

it('Test JS: check creation of state', function (done) {
this.timeout(2000);
// add script
Expand Down Expand Up @@ -673,7 +673,7 @@ describe('Test JS', function() {
objects.setObject(script._id, script, function (err) {
expect(err).to.be.not.ok;
});
});*/
});

it('Test JS: test write file to "javascript"', function (done) {
this.timeout(5000);
Expand Down

0 comments on commit 5f041e5

Please sign in to comment.