new
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user