Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate strathcole/iob-lib to local repository #84

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"eslint.enable": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"json.schemas": [
{
"fileMatch": [
"io-package.json"
],
"url": "https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/schemas/io-package.json"
},
{
"fileMatch": [
"admin/jsonConfig.json",
"admin/jsonCustom.json",
"admin/jsonTab.json"
],
"url": "https://raw.githubusercontent.com/ioBroker/adapter-react-v5/main/schemas/jsonConfig.json"
}
]
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ This adapter would not have been possible without the great work of Marius Burka
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->

### **WORK IN PROGRESS**
* (Feuersturm) Migrate @strathcole/iob-lib to local repository (#27)

### 2.0.1 (2024-12-15)
* (Feuersturm) Some minor corrections to installations news and some internal changes at pacakging have been applied.

Expand Down
136 changes: 136 additions & 0 deletions lib/iob-lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// migrated iob-lib.js from https://github.com/pixcept/iob-lib/ to local repository
// https://github.com/iobroker-community-adapters/ioBroker.rainbird/issues/27

'use strict';

let adapter;

let objectStates = {};

function init(adapterInstance) {

Check warning on line 10 in lib/iob-lib.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Missing JSDoc comment
adapter = adapterInstance;
}

function createOrSetState(id, setobj, setval) {

Check warning on line 14 in lib/iob-lib.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Missing JSDoc comment
if (objectStates[id] && objectStates[id] === true) {
adapter.setState(id, setval, true);
} else {
adapter.getObject(id, function (err, obj) {
if (err || !obj) {
adapter.setObject(id, setobj, function () {
objectStates[id] = true;
adapter.setState(id, setval, true);
});
} else {
objectStates[id] = true;
adapter.setState(id, setval, true);
}
});
}
}

function setOrUpdateState(id, name, setval, setunit, settype, setrole, setstates) {

Check warning on line 32 in lib/iob-lib.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Missing JSDoc comment
if (objectStates[id] && objectStates[id] === true) {
adapter.setState(id, setval, true);
return;
}

if (!setunit) {
setunit = '';
}
if (!settype) {
settype = 'number';
}
if (!setrole) {
setrole = 'value';
}

let read = true;
let write = false;
if (setrole.substr(0, 6) === 'button') {
read = false;
write = true;
} else if (setrole.substr(0, 5) === 'level' || setrole.substr(0, 6) === 'switch') {
read = true;
write = true;
}

let obj = {
type: 'state',
common: {
name: name,
type: settype,
role: setrole,
read: read,
write: write,
unit: setunit,
},
native: {},
};
if (setstates) {
obj['common']['states'] = setstates;
}
createOrSetState(id, obj, setval);
}

function setOrUpdateObject(id, name, settype, callback) {

Check warning on line 76 in lib/iob-lib.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Missing JSDoc comment
if (objectStates[id] && objectStates[id] === true) {
return callback && callback();
}

if (!settype) {
settype = 'channel';
}

let setObj = {
type: settype,
common: {
name: name,
},
native: {},
};

adapter.getObject(id, function (err, obj) {
if (!err && obj) {
adapter.extendObject(id, setObj, function () {
objectStates[id] = true;
return callback && callback();
});
} else {
adapter.setObject(id, setObj, function () {
objectStates[id] = true;
return callback && callback();
});
}
});
}

function delObjectIfExists(id, callback) {

Check warning on line 108 in lib/iob-lib.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Missing JSDoc comment
adapter.getObject(id, function (err, _obj) {
if (!err) {
adapter.delObject(id, function (_err) {
delete objectStates[id];
callback && callback();
});
} else {
callback && callback();
}
});
}

function decrypt(key, value) {

Check warning on line 121 in lib/iob-lib.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Missing JSDoc comment
var result = '';
for (var i = 0; i < value.length; ++i) {
result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));
}
return result;
}

module.exports = {
init: init,
setOrUpdateObject: setOrUpdateObject,
createOrSetState: createOrSetState,
setOrUpdateState: setOrUpdateState,
delObjectIfExists: delObjectIfExists,
decrypt: decrypt,
};
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const utils = require('@iobroker/adapter-core'); // Get common adapter utils
const ioBLib = require('@strathcole/iob-lib').ioBLib;
const ioBLib = require('./lib/iob-lib');

const rainbird = require('./lib/rainbird');

Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"dependencies": {
"@iobroker/adapter-core": "^3.2.3",
"@strathcole/iob-lib": "^0.1.2",
"request": "^2.88.0"
},
"devDependencies": {
Expand Down
Loading