This commit is contained in:
zhongjin 2018-09-25 09:26:58 +08:00
parent 58d94c5b08
commit 0ea2955c83
3 changed files with 142 additions and 5 deletions

View File

@ -1,8 +1,8 @@
{
"common": {
"name": "rest",
"version": "0.1.1",
"title": "Javascript/Node.js based rest adapter",
"version": "0.1.2",
"title": "云控 REST 服务",
"desc": {
"en": "yunkong2 rest Adapter",
"cn": "云控 REST Adapter"
@ -23,7 +23,7 @@
},
"native": {
"test1": true,
"test2": 42,
"test2": 41,
"port": 9090,
"auth": false,
@ -41,11 +41,49 @@
"leUpdate": false,
"leCheckPort": 80,
"doorInputs": [],
"doorInputs": [
{
"type": "state",
"common": {
"role": "button",
"name": "Shuts the system running Kodi down",
"type": "boolean",
"read": false,
"write": true,
"def": false
},
"native": {}
}
],
"doorOutputs": []
},
"objects": [
],
"instanceObjects": [
{
"_id": "info",
"type": "channel",
"common": {
"name": "Information"
},
"native": {}
},
{
"_id": "info.connection",
"type": "state",
"common": {
"role": "indicator.connected",
"name": "If master connected",
"type": "boolean",
"read": true,
"write": false,
"def": false
},
"native": {}
}
]
}

99
main.js
View File

@ -243,8 +243,106 @@ function pollData() {
});
}
//zhongjin add
function createExtendObject(id, objData, callback) {
adapter.getObject(id, function (err, oldObj) {
if (!err && oldObj) {
adapter.extendObject(id, objData, callback);
} else {
adapter.setObjectNotExists(id, objData, callback);
}
});
}
function processTasks(tasks, callback) {
if (!tasks || !tasks.length) {
if (typeof callback === 'function') callback();
return;
}
let task = tasks.shift();
if (task.name === 'add') {
createExtendObject(task.id, task.obj, function () {
setTimeout(processTasks, 0, tasks, callback);
});
} else if (task.name === 'del') {
adapter.delObject(task.id, function () {
setTimeout(processTasks, 0, tasks, callback);
});
} else if (task.name === 'syncEnums') {
syncEnums('rooms', task.id, task.obj, function () {
setTimeout(processTasks, 0, tasks, callback);
});
} else {
throw 'Unknown task';
}
}
function checkObjects(options, regType, regName, regFullName, tasks, newObjects) {
let params = config.params;
let options = {
config: {
type: params.type || 'tcp',
slave: params.slave,
round: parseInt(params.round, 10) || 0,
timeout: parseInt(params.timeout, 10) || 5000,
defaultDeviceId: (params.deviceId === undefined || params.deviceId === null) ? 1 : (parseInt(params.deviceId, 10) || 0),
},
devices: {}
};
options.config.round = Math.pow(10, options.config.round);
}
function prepareConfig(config) {
}
function parseConfig(callback) {
let options = prepareConfig(adapter.config);
const params = adapter.config.params;
let tasks = [];
tasks.push({
id: 'info.pollTime',
name: 'add',
obj: {
type: 'state',
common: {
name: 'Poll time',
type: 'number',
role: '',
write: false,
read: true,
def: 0,
unit: 'ms'
},
native: {}
}
});
processTasks(tasks, function () {
// oldObjects = [];
// newObjects = [];
adapter.subscribeStates('*');
callback(options);
});
}
function main() {
//zhongjin add
parseConfig(options => {
});
//end zhongjin
// The adapters config (in the instance object everything under the attribute "native") is accessible via
// adapter.config:
adapter.log.info('config test1: ' + adapter.config.test1);
@ -316,3 +414,4 @@ function main() {
timer = setInterval(pollData, adapter.config.interval);
}
}