Skip to content

Commit

Permalink
chore: release v0.1.14-alpha.0
Browse files Browse the repository at this point in the history
* (HGlab01) add versionInfo
* (HGlab01) add modify-methods 'toFloat' and 'toInteger'
* (DutchmanNL) couple of code improvements
  • Loading branch information
HGlab01 committed Oct 6, 2023
1 parent b5929a0 commit 67dd5cf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_OLD.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Older changes
## 0.1.9 (2022-02-15)
* (HGlab01) js-controller 4.0 readiness

## 0.1.8 (2021-11-25)
* (HGlab01) save 'warnMessages'-array as file to reimport after restart of adapter

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ https://github.com/HGlab01/ioBroker.fuelpricemonitor
Placeholder for the next version (at the beginning of the line):
### __WORK IN PROGRESS__
-->
### 0.1.14-alpha.0 (2023-10-06)
* (HGlab01) add versionInfo
* (HGlab01) add modify-methods 'toFloat' and 'toInteger'
* (DutchmanNL) couple of code improvements

### 0.1.13 (2023-10-03)
* (HGlab01) fix #113 "Cannot read properties of undefined (reading 'Warning')"

Expand All @@ -52,9 +57,6 @@ https://github.com/HGlab01/ioBroker.fuelpricemonitor
* (HGlab01) setLastStartTime() optimized
* (HGlab01) Logs improved

### 0.1.9 (2022-02-15)
* (HGlab01) js-controller 4.0 readiness

## License
MIT License

Expand Down
26 changes: 14 additions & 12 deletions _template/stateAttr.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
rootName: 'Device Info channel, // {default: NotUsed} Upper channel name
name: 'Name of state', // {default: same as id} Name definition for object
type: >typeof (value)<, // {default: typeof (value)} type of value automatically detected
read: true, // {default: true} Name defition for object
write: true, // {default: false} Name defition for object
read: true, // {default: true} Name definition for object
write: true, // {default: false} Name definition for object
role: 'indicator.info', // {default: state} Role as defined by https://github.com/ioBroker/ioBroker/blob/master/doc/STATE_ROLES.md
modify: '' // {default: ''} see below
},
*/

/**
* Defines supported methods for element modify which can be used in stateAttr.js
* In addition: 'cumstom: YOUR CALCULATION' allows any calculation, where 'value' is the input parameter.
* Example:
* In addition: 'custom: YOUR CALCULATION' allows any calculation, where 'value' is the input parameter.
* Example:
* modify: 'custom: value + 1' --> add 1 to the json-input
*
* * supported methods (as string):
Expand All @@ -31,6 +31,8 @@
* - upperCase
* - lowerCase
* - ucFirst
* - toInteger
* - toFloat
*
* Examples for usage of embeded methods:
* modify: ['multiply(3.6)', 'round(2)'] --> defined as array --> multiplied by 3.6 and then the result is rounded by 2 digits
Expand All @@ -45,35 +47,35 @@ const stateAttrb = {
'NAMEOFTHESTATE1': {
name: 'READABLE NAME/DESCRIPTION',
type: 'number|string|array|boolean...',
read: true|false,
write: true|false,
read: true | false,
write: true | false,
role: 'value',
unit: 's|°|%...',
modify: ['multiply(3.6)', 'round(2)']
},
'NAMEOFTHESTATE2': {
name: 'READABLE NAME/DESCRIPTION',
type: 'number|string|array|boolean...',
read: true|false,
write: true|false,
read: true | false,
write: true | false,
role: 'vale',
unit: 's|°|%...',
modify: 'customer: (value+1)*2+value/2'
},
'NAMEOFTHESTATE3': {
name: 'READABLE NAME/DESCRIPTION',
type: 'number|string|array|boolean...',
read: true|false,
write: true|false,
read: true | false,
write: true | false,
role: 'vale',
unit: 's|°|%...',
modify: 'upperCase'
},
'NAMEOFTHESTATE4': {
name: 'READABLE NAME/DESCRIPTION',
type: 'number|string|array|boolean...',
read: true|false,
write: true|false,
read: true | false,
write: true | false,
role: 'vale',
unit: 's|°|%...'
}
Expand Down
26 changes: 21 additions & 5 deletions jsonExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ let stateExpire = {}, warnMessages = {}, stateAttr = {};
let adapter; //adapter-object initialized by init(); other functions do not need adapter-object in their signatur

/**
* @param {object} adapter Adapter-Class (normally "this")
* @param {object} stateAttr check README
* @param {object} adapterOrigin Adapter-Class (normally "this")
* @param {object} stateAttribute check README
*/
function init(adapterOrigin, stateAttribute) {
readWarnMessages();
Expand Down Expand Up @@ -38,8 +38,10 @@ function traverseJson(jObject, parent = null, replaceName = false, replaceID = f
let id = null;
let value = null;
let name = '';
parent = parent.replace(adapter.FORBIDDEN_CHARS, '_');

if (parent != null) {
parent = parent.replace(adapter.FORBIDDEN_CHARS, '_');
}
try {
if (parent != null && level == 0) {
if (replaceName) {
Expand Down Expand Up @@ -175,6 +177,12 @@ function modify(method, value) {
case 'UCFIRST':
if (typeof value == 'string') result = value.substring(0, 1).toUpperCase() + value.substring(1).toLowerCase();
break;
case 'TOINTEGER':
result = parseInt(value);
break;
case 'TOFLOAT':
result = parseFloat(value);
break;
default:
result = value;
}
Expand Down Expand Up @@ -253,12 +261,20 @@ async function stateSetCreate(objName, name, value) {
common.type = stateAttr[name] !== undefined ? stateAttr[name].type || typeof (value) : typeof (value);
common.role = stateAttr[name] !== undefined ? stateAttr[name].role || 'state' : 'state';
common.read = true;
common.unit = stateAttr[name] !== undefined ? stateAttr[name].unit || '' : '';
//common.unit = stateAttr[name] !== undefined ? stateAttr[name].unit || '' : '';
common.write = stateAttr[name] !== undefined ? stateAttr[name].write || false : false;
common.states = stateAttr[name] !== undefined ? stateAttr[name].states || null : null;
//common.states = stateAttr[name] !== undefined ? stateAttr[name].states || null : null;
common.modify = stateAttr[name] !== undefined ? stateAttr[name].modify || '' : '';
adapter.log.silly(`MODIFY to ${name}: ${JSON.stringify(common.modify)}`);

// Only add values for unit, modify and states if needed
if (stateAttr[name] != null && stateAttr[name].unit != null) {
common.unit = stateAttr[name] !== undefined ? stateAttr[name].unit || '' : '';
}
if (stateAttr[name] != null && stateAttr[name].states != null) {
common.states = stateAttr[name] !== undefined ? stateAttr[name].states || null : null;
}

let objectDefiniton = {};
if (!adapter.createdStatesDetails[objName]) {
objectDefiniton = await adapter.getObjectAsync(objName);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker-jsonexplorer",
"version": "0.1.13",
"version": "0.1.14-alpha.0",
"description": "Creates ioBroker states based on a json-object",
"main": "jsonExplorer.js",
"scripts": {
Expand Down

0 comments on commit 67dd5cf

Please sign in to comment.