This commit is contained in:
2018-09-21 23:49:05 +08:00
parent d1436af18d
commit 9260e8e0ae
13 changed files with 71 additions and 71 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ before_script:
- 'if [[ $NPMVERSION == 5 ]]; then npm install -g npm@5; fi' - 'if [[ $NPMVERSION == 5 ]]; then npm install -g npm@5; fi'
- npm -v - npm -v
- npm install winston@2.3.1 - npm install winston@2.3.1
- 'npm install https://github.com/ioBroker/ioBroker.js-controller/tarball/master --production' - 'npm install https://git.spacen.net/yunkong2/yunkong2.js-controller/tarball/master --production'
env: env:
- CXX=g++-4.8 - CXX=g++-4.8
addons: addons:
+13 -13
View File
@@ -9,7 +9,7 @@ module.exports = function (grunt) {
var srcDir = __dirname + '/'; var srcDir = __dirname + '/';
var pkg = grunt.file.readJSON('package.json'); var pkg = grunt.file.readJSON('package.json');
var adaptName = pkg.name.substring('iobroker.'.length); var adaptName = pkg.name.substring('yunkong2.'.length);
var iopackage = grunt.file.readJSON('io-package.json'); var iopackage = grunt.file.readJSON('io-package.json');
var version = (pkg && pkg.version) ? pkg.version : iopackage.common.version; var version = (pkg && pkg.version) ? pkg.version : iopackage.common.version;
var newname = grunt.option('name'); var newname = grunt.option('name');
@@ -32,17 +32,17 @@ module.exports = function (grunt) {
console.log('Name must be lower case.'); console.log('Name must be lower case.');
process.exit(); process.exit();
} }
if (fs.existsSync(__dirname + '/admin/template-rest.png')) { if (fs.existsSync(__dirname + '/admin/rest.png')) {
fs.renameSync(__dirname + '/admin/template-rest.png', __dirname + '/admin/' + newname + '.png'); fs.renameSync(__dirname + '/admin/rest.png', __dirname + '/admin/' + newname + '.png');
} }
if (fs.existsSync(__dirname + '/widgets/template-rest.html')) { if (fs.existsSync(__dirname + '/widgets/rest.html')) {
fs.renameSync(__dirname + '/widgets/template-rest.html', __dirname + '/widgets/' + newname + '.html'); fs.renameSync(__dirname + '/widgets/rest.html', __dirname + '/widgets/' + newname + '.html');
} }
if (fs.existsSync(__dirname + '/widgets/template/js/template-rest.js')) { if (fs.existsSync(__dirname + '/widgets/template/js/rest.js')) {
fs.renameSync(__dirname + '/widgets/template/js/template-rest.js', __dirname + '/widgets/template/js/' + newname + '.js'); fs.renameSync(__dirname + '/widgets/template/js/rest.js', __dirname + '/widgets/template/js/' + newname + '.js');
} }
if (fs.existsSync(__dirname + '/widgets/template-rest')) { if (fs.existsSync(__dirname + '/widgets/rest')) {
fs.renameSync(__dirname + '/widgets/template-rest', __dirname + '/widgets/' + newname); fs.renameSync(__dirname + '/widgets/rest', __dirname + '/widgets/' + newname);
} }
} }
@@ -105,7 +105,7 @@ module.exports = function (grunt) {
}, },
{ {
match: /Template\-rest/g, match: /Template\-rest/g,
replacement: newname ? (newname[0].toUpperCase() + newname.substring(1)) : 'Template-rest' replacement: newname ? (newname[0].toUpperCase() + newname.substring(1)) : 'rest'
}, },
{ {
match: /@@Author@@/g, match: /@@Author@@/g,
@@ -175,19 +175,19 @@ module.exports = function (grunt) {
http: { http: {
get_hjscs: { get_hjscs: {
options: { options: {
url: 'https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/tasks/jscs.js' url: 'https://raw.githubusercontent.com/yunkong2/yunkong2.js-controller/master/tasks/jscs.js'
}, },
dest: 'tasks/jscs.js' dest: 'tasks/jscs.js'
}, },
get_jshint: { get_jshint: {
options: { options: {
url: 'https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/tasks/jshint.js' url: 'https://raw.githubusercontent.com/yunkong2/yunkong2.js-controller/master/tasks/jshint.js'
}, },
dest: 'tasks/jshint.js' dest: 'tasks/jshint.js'
}, },
get_jscsRules: { get_jscsRules: {
options: { options: {
url: 'https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/tasks/jscsRules.js' url: 'https://raw.githubusercontent.com/yunkong2/yunkong2.js-controller/master/tasks/jscsRules.js'
}, },
dest: 'tasks/jscsRules.js' dest: 'tasks/jscsRules.js'
} }
+18 -18
View File
@@ -1,19 +1,19 @@
![Logo](admin/template-rest.png) ![Logo](admin/rest.png)
# ioBroker.template-rest # yunkong2.rest
================= =================
This adapter is a template for the creation of an ioBroker adapter. You do not need it, at least that you plan developing your own adapter. This adapter is a template for the creation of an yunkong2 adapter. You do not need it, at least that you plan developing your own adapter.
This is extension of [ioBroker.template](https://github.com/ioBroker/ioBroker.template) adapter with REST service. This is extension of [yunkong2.template](https://git.spacen.net/yunkong2/yunkong2.template) adapter with REST service.
By default the WEB server will be started to serve HTTP GET/POST requests. It can be started as secure(https) or unsecure(http) and with authentication or without. By default the WEB server will be started to serve HTTP GET/POST requests. It can be started as secure(https) or unsecure(http) and with authentication or without.
Additionally is shown how to poll some other URL for JSON data and parse them. Additionally is shown how to poll some other URL for JSON data and parse them.
##Steps ##Steps
1. download and unpack this packet from github ```https://github.com/ioBroker/ioBroker.template/archive/master.zip``` 1. download and unpack this packet from github ```https://git.spacen.net/yunkong2/yunkong2.template/archive/master.zip```
or clone git repository ```git clone https://github.com/ioBroker/ioBroker.template.git``` or clone git repository ```git clone https://git.spacen.net/yunkong2/yunkong2.template.git```
2. download required npm packets. Write in ioBroker.template directory: 2. download required npm packets. Write in yunkong2.template directory:
```npm install``` ```npm install```
@@ -27,29 +27,29 @@ Additionally is shown how to poll some other URL for JSON data and parse them.
```npm install -g grunt-cli``` ```npm install -g grunt-cli```
4. rename directory from *ioBroker.template* (can be *ioBroker.template-master*) to *iobroker.mynewname* 4. rename directory from *yunkong2.template* (can be *yunkong2.template-master*) to *yunkong2.mynewname*
5. to use this template you should copy it into *.../iobroker/node_modules* directory and then create an instance for it with iobroker.admin 5. to use this template you should copy it into *.../yunkong2/node_modules* directory and then create an instance for it with yunkong2.admin
6. create your adapter: 6. create your adapter:
* you might want to start with main.js (code running within iobroker) and admin/index.html (the adapter settings page). * you might want to start with main.js (code running within yunkong2) and admin/index.html (the adapter settings page).
* [Adapter-Development-Documentation](https://github.com/ioBroker/ioBroker/wiki/Adapter-Development-Documentation), * [Adapter-Development-Documentation](https://git.spacen.net/yunkong2/yunkong2/wiki/Adapter-Development-Documentation),
* [Installation, setup and first steps with an ioBroker Development Environment](https://github.com/ioBroker/ioBroker/wiki/Installation,-setup-and-first-steps-with-an-ioBroker-Development-Environment) * [Installation, setup and first steps with an yunkong2 Development Environment](https://git.spacen.net/yunkong2/yunkong2/wiki/Installation,-setup-and-first-steps-with-an-yunkong2-Development-Environment)
* [Write and debug vis widgets](https://github.com/ioBroker/ioBroker/wiki/How-to-debug-vis-and-to-write-own-widget-set) * [Write and debug vis widgets](https://git.spacen.net/yunkong2/yunkong2/wiki/How-to-debug-vis-and-to-write-own-widget-set)
* files under the www folders are made available under http://<iobrokerIP>:8082/<adapter-name>/ * files under the www folders are made available under http://<yunkong2IP>:8082/<adapter-name>/
* for this to work the iobroker.vis adapter has to be installed * for this to work the yunkong2.vis adapter has to be installed
* delete this folder if you do not plan to export any files this way * delete this folder if you do not plan to export any files this way
* call ```iobroker upload <adapter-name>``` after you change files in the www folder to get the new files uploaded to vis * call ```yunkong2 upload <adapter-name>``` after you change files in the www folder to get the new files uploaded to vis
* the widget folder contains an example of a vis widget * the widget folder contains an example of a vis widget
* you might want to start with *widget/<adapter-name>.html* and *widget/js/<adapter-name>.js* * you might want to start with *widget/<adapter-name>.html* and *widget/js/<adapter-name>.js*
* call ```iobroker visdebug <adapter-name>``` to enable debugging and upload widget to "vis". (This works only from V0.7.15 of js-controller) * call ```yunkong2 visdebug <adapter-name>``` to enable debugging and upload widget to "vis". (This works only from V0.7.15 of js-controller)
* If you do not plan to export any widget then delete the whole widget folder and remove the ```"restartAdapters": ["vis"]``` statement from *io-package.json* * If you do not plan to export any widget then delete the whole widget folder and remove the ```"restartAdapters": ["vis"]``` statement from *io-package.json*
* After admin/index.html is changed you must execute ```iobroker upload mynewname``` to see changes in admin console. The same is valid for any files in *admin* and *www* directory * After admin/index.html is changed you must execute ```yunkong2 upload mynewname``` to see changes in admin console. The same is valid for any files in *admin* and *www* directory
7. change version: edit package.json and then call ```grunt p``` in your adapter directory. 7. change version: edit package.json and then call ```grunt p``` in your adapter directory.
+3 -3
View File
@@ -29,7 +29,7 @@
// Dictionary (systemDictionary is global variable from adapter-settings.js) // Dictionary (systemDictionary is global variable from adapter-settings.js)
systemDictionary = { systemDictionary = {
"template-rest adapter settings": {"de": "Beispiel", "ru": "Пример"}, "rest adapter settings": {"de": "Beispiel", "ru": "Пример"},
"test1": {"en": "Test 1", "de": "Test 1", "ru": "Тест 1"}, "test1": {"en": "Test 1", "de": "Test 1", "ru": "Тест 1"},
"test2": {"en": "Test 2", "de": "Test 2", "ru": "Тест 2"}, "test2": {"en": "Test 2", "de": "Test 2", "ru": "Тест 2"},
@@ -173,8 +173,8 @@
<div id="adapter-container"> <div id="adapter-container">
<table><tr> <table><tr>
<td><img src="template-rest.png"/></td> <td><img src="rest.png"/></td>
<td><h3 class="translate">template-rest adapter settings</h3></td> <td><h3 class="translate">rest adapter settings</h3></td>
</tr></table> </tr></table>
<table> <table>
<tr><td class="translate">test1</td><td> <input class="value" id="test1"/></td></tr> <tr><td class="translate">test1</td><td> <input class="value" id="test1"/></td></tr>
+1 -1
View File
@@ -16,7 +16,7 @@ install:
- ps: npm --version - ps: npm --version
- npm install - npm install
- npm install winston@2.3.1 - npm install winston@2.3.1
- 'npm install https://github.com/ioBroker/ioBroker.js-controller/tarball/master --production' - 'npm install https://git.spacen.net/yunkong2/yunkong2.js-controller/tarball/master --production'
test_script: test_script:
- echo %cd% - echo %cd%
- node --version - node --version
+9 -9
View File
@@ -1,12 +1,12 @@
{ {
"common": { "common": {
"name": "template-rest", "name": "rest",
"version": "0.1.0", "version": "0.1.0",
"title": "Javascript/Node.js based template-rest adapter", "title": "Javascript/Node.js based rest adapter",
"desc": { "desc": {
"en": "ioBroker template-rest Adapter", "en": "yunkong2 rest Adapter",
"de": "ioBroker template-rest Adapter", "de": "yunkong2 rest Adapter",
"ru": "ioBroker template-rest драйвер как образец" "ru": "yunkong2 rest драйвер как образец"
}, },
"news": { "news": {
"0.1.0" :{ "0.1.0" :{
@@ -30,11 +30,11 @@
], ],
"platform": "Javascript/Node.js", "platform": "Javascript/Node.js",
"mode": "daemon", "mode": "daemon",
"icon": "template-rest.png", "icon": "rest.png",
"enabled": true, "enabled": true,
"extIcon": "https://raw.githubusercontent.com/ioBroker/ioBroker.template-rest/master/admin/template-rest.png", "extIcon": "https://git.spacen.net/yunkong2/yunkong2.rest/raw/master/admin/rest.png",
"keywords": ["template-rest", "REST"], "keywords": ["rest", "REST"],
"readme": "https://github.com/ioBroker/ioBroker.template-rest/blob/master/README.md", "readme": "https://git.spacen.net/yunkong2/yunkong2.rest/blob/master/README.md",
"loglevel": "info", "loglevel": "info",
"type": "communication", "type": "communication",
"dependencies": [{"js-controller": ">=0.12.0"}] "dependencies": [{"js-controller": ">=0.12.0"}]
+2 -2
View File
@@ -27,8 +27,8 @@ let appName;
function getControllerDir(isInstall) { function getControllerDir(isInstall) {
// Find the js-controller location // Find the js-controller location
const possibilities = [ const possibilities = [
'iobroker.js-controller', 'yunkong2.js-controller',
'ioBroker.js-controller', 'yunkong2.js-controller',
]; ];
/** @type {string} */ /** @type {string} */
let controllerPath; let controllerPath;
+6 -6
View File
@@ -27,11 +27,11 @@
* "auth": false, // if basic authentication is required. If enabled, the secure connection should be used. * "auth": false, // if basic authentication is required. If enabled, the secure connection should be used.
* "secure": false, // If SSL communication must be used. Should has the name "secure", because it can be changed from console. * "secure": false, // If SSL communication must be used. Should has the name "secure", because it can be changed from console.
* "bind": "0.0.0.0", // Specific address, where the server will be started. "0.0.0.0" means that it will be available for all addresses. Should has the name "bind", because it can be changed from console. * "bind": "0.0.0.0", // Specific address, where the server will be started. "0.0.0.0" means that it will be available for all addresses. Should has the name "bind", because it can be changed from console.
* "defaultUser": "admin", // If authentication is disabled, here can be specified as which user the requests will be done to iobroker DB. * "defaultUser": "admin", // If authentication is disabled, here can be specified as which user the requests will be done to yunkong2 DB.
* "certPublic": "defaultPublic",// Required for SSL communication: name of some public certificate from iobroker DB * "certPublic": "defaultPublic",// Required for SSL communication: name of some public certificate from yunkong2 DB
* "certPrivate": "defaultPrivate"// Required for SSL communication: name of some private key from iobroker DB * "certPrivate": "defaultPrivate"// Required for SSL communication: name of some private key from yunkong2 DB
* *
* "pollURL": "", // Request all 30 seconds the JSON from this URL, parse it and store in ioBroker * "pollURL": "", // Request all 30 seconds the JSON from this URL, parse it and store in yunkong2
* "interval": 30000 // polling interval * "interval": 30000 // polling interval
* } * }
* } * }
@@ -53,7 +53,7 @@ var request = null; // will be initialized later if polling enabled
// you have to call the adapter function and pass a options object // you have to call the adapter function and pass a options object
// name has to be set and has to be equal to adapters folder name and main file name excluding extension // name has to be set and has to be equal to adapters folder name and main file name excluding extension
// adapter will be restarted automatically every time as the configuration changed, e.g system.adapter.template.0 // adapter will be restarted automatically every time as the configuration changed, e.g system.adapter.template.0
var adapter = utils.Adapter('template-rest'); var adapter = utils.Adapter('rest');
var LE = require(utils.controllerDir + '/lib/letsencrypt.js'); var LE = require(utils.controllerDir + '/lib/letsencrypt.js');
// REST server // REST server
@@ -176,7 +176,7 @@ function initWebServer(settings) {
var login = loginPass[0]; var login = loginPass[0];
var password = loginPass[1]; var password = loginPass[1];
// Check in ioBroker user and password // Check in yunkong2 user and password
adapter.checkPassword(login, password, function (result) { adapter.checkPassword(login, password, function (result) {
if (!result) { if (!result) {
adapter.log.error('Wrong user or password: ' + login); adapter.log.error('Wrong user or password: ' + login);
+7 -7
View File
@@ -1,7 +1,7 @@
{ {
"name": "iobroker.template-rest", "name": "yunkong2.rest",
"version": "0.1.0", "version": "0.1.0",
"description": "ioBroker template-rest Adapter", "description": "yunkong2 rest Adapter",
"author": { "author": {
"name": "@@Author@@", "name": "@@Author@@",
"email": "@@email@@" "email": "@@email@@"
@@ -12,16 +12,16 @@
"email": "@@email@@" "email": "@@email@@"
} }
], ],
"homepage": "https://github.com/ioBroker/ioBroker.template-rest", "homepage": "https://git.spacen.net/yunkong2/yunkong2.rest",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [
"ioBroker", "yunkong2",
"template-rest", "rest",
"REST API" "REST API"
], ],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/ioBroker/ioBroker.template-rest" "url": "https://git.spacen.net/yunkong2/yunkong2.rest"
}, },
"dependencies": { "dependencies": {
"express": "^4.13.4", "express": "^4.13.4",
@@ -41,7 +41,7 @@
"test": "node node_modules/mocha/bin/mocha --exit" "test": "node node_modules/mocha/bin/mocha --exit"
}, },
"bugs": { "bugs": {
"url": "https://github.com/ioBroker/ioBroker.template-rest/issues" "url": "https://git.spacen.net/yunkong2/yunkong2.rest/issues"
}, },
"readmeFilename": "README.md" "readmeFilename": "README.md"
} }
+2 -2
View File
@@ -321,7 +321,7 @@ function installJsController(cb) {
if (!fs.existsSync(rootDir + 'tmp/node_modules/' + appName + '.js-controller')) { if (!fs.existsSync(rootDir + 'tmp/node_modules/' + appName + '.js-controller')) {
console.log('installJsController: no js-controller => install from git'); console.log('installJsController: no js-controller => install from git');
child_process.execSync('npm install https://github.com/' + appName + '/' + appName + '.js-controller/tarball/master --prefix ./ --production', { child_process.execSync('npm install https://git.spacen.net/' + appName + '/' + appName + '.js-controller/tarball/master --prefix ./ --production', {
cwd: rootDir + 'tmp/', cwd: rootDir + 'tmp/',
stdio: [0, 1, 2] stdio: [0, 1, 2]
}); });
@@ -415,7 +415,7 @@ function clearControllerLog() {
} }
function clearDB() { function clearDB() {
var dirPath = rootDir + 'tmp/iobroker-data/sqlite'; var dirPath = rootDir + 'tmp/yunkong2-data/sqlite';
var files; var files;
try { try {
if (fs.existsSync(dirPath)) { if (fs.existsSync(dirPath)) {
+2 -2
View File
@@ -49,7 +49,7 @@ describe('Test RESTful API', function() {
}); });
it('Test RESTful API: get /api/id - must return value', function (done) { it('Test RESTful API: get /api/id - must return value', function (done) {
request('http://127.0.0.1:18183/api/system.adapter.template-rest.0.alive', function (error, response, body) { request('http://127.0.0.1:18183/api/system.adapter.rest.0.alive', function (error, response, body) {
console.log('get /api => ' + body); console.log('get /api => ' + body);
expect(error).to.be.not.ok; expect(error).to.be.not.ok;
var data = JSON.parse(body); var data = JSON.parse(body);
@@ -59,7 +59,7 @@ describe('Test RESTful API', function() {
}); });
it('Test RESTful API: get /api/plain/id - must return value', function (done) { it('Test RESTful API: get /api/plain/id - must return value', function (done) {
request('http://127.0.0.1:18183/api/plain/system.adapter.template-rest.0.alive', function (error, response, body) { request('http://127.0.0.1:18183/api/plain/system.adapter.rest.0.alive', function (error, response, body) {
console.log('get /api => ' + body); console.log('get /api => ' + body);
expect(error).to.be.not.ok; expect(error).to.be.not.ok;
expect(body).to.be.equal('Value: true'); expect(body).to.be.equal('Value: true');
+3 -3
View File
@@ -52,12 +52,12 @@ describe('Test package.json and io-package.json', function() {
console.log(); console.log();
} }
if ( if (
ioPackage.common.title.indexOf('iobroker') !== -1 || ioPackage.common.title.indexOf('yunkong2') !== -1 ||
ioPackage.common.title.indexOf('ioBroker') !== -1 || ioPackage.common.title.indexOf('yunkong2') !== -1 ||
ioPackage.common.title.indexOf('adapter') !== -1 || ioPackage.common.title.indexOf('adapter') !== -1 ||
ioPackage.common.title.indexOf('Adapter') !== -1 ioPackage.common.title.indexOf('Adapter') !== -1
) { ) {
console.log('WARNING: title contains Adapter or ioBroker. It is clear anyway, that it is adapter for ioBroker.'); console.log('WARNING: title contains Adapter or yunkong2. It is clear anyway, that it is adapter for yunkong2.');
console.log(); console.log();
} }
+4 -4
View File
@@ -35,7 +35,7 @@ describe('Test RESTful API SSL', function() {
}); });
it('Test RESTful API SSL: get /api/plain - must return welcome text', function (done) { it('Test RESTful API SSL: get /api/plain - must return welcome text', function (done) {
request('https://admin:iobroker@127.0.0.1:18184/api/plain', function (error, response, body) { request('https://admin:yunkong2@127.0.0.1:18184/api/plain', function (error, response, body) {
console.log('get /api/plain => ' + body); console.log('get /api/plain => ' + body);
expect(error).to.be.not.ok; expect(error).to.be.not.ok;
expect(body).to.be.equal('Welcome to our text REST api!'); expect(body).to.be.equal('Welcome to our text REST api!');
@@ -44,7 +44,7 @@ describe('Test RESTful API SSL', function() {
}); });
it('Test RESTful API SSL: get /api - must return welcome text', function (done) { it('Test RESTful API SSL: get /api - must return welcome text', function (done) {
request('https://admin:iobroker@127.0.0.1:18184/api', function (error, response, body) { request('https://admin:yunkong2@127.0.0.1:18184/api', function (error, response, body) {
console.log('get /api => ' + body); console.log('get /api => ' + body);
expect(error).to.be.not.ok; expect(error).to.be.not.ok;
expect(body).to.be.equal('{"message":"Welcome to our JSON REST api!"}'); expect(body).to.be.equal('{"message":"Welcome to our JSON REST api!"}');
@@ -53,7 +53,7 @@ describe('Test RESTful API SSL', function() {
}); });
it('Test RESTful API SSL: get /api/id - must return value', function (done) { it('Test RESTful API SSL: get /api/id - must return value', function (done) {
request('https://admin:iobroker@127.0.0.1:18184/api/system.adapter.template-rest.0.alive', function (error, response, body) { request('https://admin:yunkong2@127.0.0.1:18184/api/system.adapter.rest.0.alive', function (error, response, body) {
console.log('get /api => ' + body); console.log('get /api => ' + body);
expect(error).to.be.not.ok; expect(error).to.be.not.ok;
var data = JSON.parse(body); var data = JSON.parse(body);
@@ -63,7 +63,7 @@ describe('Test RESTful API SSL', function() {
}); });
it('Test RESTful API SSL: get /api/plain/id - must return value', function (done) { it('Test RESTful API SSL: get /api/plain/id - must return value', function (done) {
request('https://admin:iobroker@127.0.0.1:18184/api/plain/system.adapter.template-rest.0.alive', function (error, response, body) { request('https://admin:yunkong2@127.0.0.1:18184/api/plain/system.adapter.rest.0.alive', function (error, response, body) {
console.log('get /api => ' + body); console.log('get /api => ' + body);
expect(error).to.be.not.ok; expect(error).to.be.not.ok;
expect(body).to.be.equal('Value: true'); expect(body).to.be.equal('Value: true');