Update main.js
This commit is contained in:
parent
6e4d2c9b21
commit
809ce35c23
54
main.js
54
main.js
@ -58,7 +58,10 @@ const adapter = new utils.Adapter('doorgate');
|
||||
/*Variable declaration, since ES6 there are let to declare variables. Let has a more clearer definition where
|
||||
it is available then var.The variable is available inside a block and it's childs, but not outside.
|
||||
You can define the same variable name inside a child without produce a conflict with the variable of the parent block.*/
|
||||
|
||||
let variable = 1234;
|
||||
let objects = {};
|
||||
|
||||
|
||||
// is called when adapter shuts down - callback has to be called under any circumstances!
|
||||
adapter.on('unload', function (callback) {
|
||||
@ -241,13 +244,64 @@ function pollData() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function prepareConfig(config) {
|
||||
let params = config.params;
|
||||
|
||||
let options = {
|
||||
config: {
|
||||
type: params.type || 'tcp',
|
||||
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.objects = objects;
|
||||
|
||||
return options;
|
||||
|
||||
}
|
||||
|
||||
function parseConfig(callback) {
|
||||
|
||||
|
||||
adapter.log.info('初始化: ' + adapter.config.door);
|
||||
|
||||
let options = prepareConfig(adapter.config);
|
||||
const params = adapter.config.params;
|
||||
|
||||
|
||||
adapter.getForeignObjects(adapter.namespace + '.*', (err, list) => {
|
||||
let oldObjects = list;
|
||||
let newObjects = [];
|
||||
|
||||
// adapter.config.door.sort(sortByAddress);
|
||||
|
||||
let tasks = [];
|
||||
|
||||
checkObjects(adapter.config, 'door', 'door', 'Door', tasks, newObjects);
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function checkObjects(options, regType, regName, regFullName, tasks, newObjects) {
|
||||
|
||||
adapter.log.info(JSON.parse(options));
|
||||
|
||||
}
|
||||
|
||||
function sortByAddress(a, b) {
|
||||
let ad = parseFloat(a.deviceId);
|
||||
let bd = parseFloat(b.deviceId);
|
||||
return ((ad < bd) ? -1 : ((ad > bd) ? 1 : 0));
|
||||
}
|
||||
|
||||
|
||||
function main() {
|
||||
|
||||
// The adapters config (in the instance object everything under the attribute "native") is accessible via
|
||||
|
Loading…
Reference in New Issue
Block a user