Skip to content

Commit

Permalink
non-numeric values check
Browse files Browse the repository at this point in the history
  • Loading branch information
phifogg committed Jul 23, 2023
1 parent f83ed01 commit b0b4003
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,19 @@ class Sainlogic extends utils.Adapter {
verify_datapoint(obj_id, that, attrdef, attrname, value) {

// check target type and type-cast if needed
let val_obj = { val: '', ack: true };

let default_value = '';
if (attrdef.type == 'number'){
if (value != null) {
value = parseFloat(value);
} else {
value = 0;
default_value = 0;
}
}
val_obj = { val: value, ack: true };

this.getObject(obj_id, function (err, obj) {
if (err || obj == null) {



that.log.info('Creating new data point: ' + obj_id);
that.setObjectNotExists(obj_id, {
type: 'state',
Expand All @@ -158,7 +155,7 @@ class Sainlogic extends utils.Adapter {
role: attrdef.role,
min: attrdef.min,
max: attrdef.max,
def: val_obj.val,
def: default_value,
read: true,
write: false,
mobile: {
Expand All @@ -171,15 +168,15 @@ class Sainlogic extends utils.Adapter {
// eslint-disable-next-line no-unused-vars
}, function (err, obj) {
// now update the value
that.setStateAsync(obj_id, val_obj);
that.setStateAsync(obj_id, { val: value, ack: true });
});
}
else {
if (attrdef.unit_config != null) {
that.checkUnit(attrdef, obj);
}
// now update the value
that.setStateAsync(obj_id, val_obj);
that.setStateAsync(obj_id, { val: value, ack: true });
}


Expand Down

0 comments on commit b0b4003

Please sign in to comment.