Comparing version 0.1.7 to 0.1.8
{ | ||
"name": "soef", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "library for ioBroker", | ||
@@ -34,7 +34,7 @@ "author": { | ||
"readme": "Library for iobroker\r\n\r\n\r\n### License\r\nThe MIT License (MIT)\r\n\r\nCopyright (c) 2015-2016 soef <soef@gmx.net>\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in\r\nall copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\nTHE SOFTWARE.\r\n", | ||
"gitHead": "caa0e2c91a549537d27454ba48f847adc88186da", | ||
"_id": "soef@0.1.5", | ||
"gitHead": "a67dd8fd9aaf64f6826620ac36cb417e45c6769f", | ||
"_id": "soef@0.1.1", | ||
"scripts": {}, | ||
"_shasum": "b1605f7fcc57dae2b2e5ab836d542536f186c72a", | ||
"_from": "soef@>=0.1.4 <0.2.0" | ||
"_shasum": "2cf1ff13773a9311092a0e7c7dffaa0d8e840feb", | ||
"_from": "soef@*" | ||
} |
137
soef.js
@@ -394,8 +394,10 @@ /** | ||
var adapter; | ||
function errmsg () { console.debug("adapter not assigned, use Device.setAdapter(yourAdapter)") }; | ||
if (module.parent.exports['adapter']) { | ||
var adapter = module.parent.exports.adapter; | ||
//if (module.parent.exports['adapter']) { | ||
if (hasProp(module, 'parent.exports.adapter')) { | ||
adapter = module.parent.exports.adapter; | ||
} else { | ||
var adapter = { | ||
adapter = { | ||
setState: errmsg, | ||
@@ -703,2 +705,5 @@ setObject: errmsg, | ||
this.CDevice = function CDevice (_name, showName, list) { | ||
if (!(this instanceof that.CDevice)) { | ||
return new that.CDevice(_name, showName, list); | ||
} | ||
@@ -860,2 +865,7 @@ var deviceName = '', channelName = ''; | ||
}; | ||
this.setAndUpdate = function (id, newObj) { | ||
this.set(id, newObj); | ||
this.update(); | ||
}; | ||
this.setImmediately = this.setAndUpdate; | ||
@@ -866,3 +876,3 @@ this.update = function () { | ||
} | ||
} | ||
}; | ||
@@ -900,18 +910,28 @@ }; | ||
function savePrevVersion(_adapter) { | ||
if (!_adapter) { | ||
_adapter = adapter; | ||
function savePrevVersion() { | ||
if(!hasProp(adapter, 'ioPack.common.version')) return; | ||
var id = 'system.adapter.' + adapter.namespace; | ||
var vid = id + '.prevVersion'; | ||
function set() { | ||
adapter.states.setState(vid, { val: adapter.ioPack.common.version, ack: true, from: id }); | ||
} | ||
if(!hasProp(_adapter, 'ioPack.common.version')) return; | ||
var id = 'system.adapter.' + _adapter.namespace; | ||
var vid = id + '.prevVersion'; | ||
_adapter.states.setState(vid, { val: _adapter.ioPack.common.version, ack: true, from: id }); | ||
adapter.objects.getObject(vid, function(err, obj) { | ||
if (err || !obj) { | ||
adapter.objects.setObject(vid, { | ||
type: 'state', | ||
common: {name: 'version', role: "indicator.state", desc: 'version check for updates'}, | ||
native: {} | ||
}, function (err, obj) { | ||
set(); | ||
}); | ||
return; | ||
} | ||
set(); | ||
}) | ||
} | ||
function checkIfUpdated(doUpdateCallback, callback) { | ||
if(!adapter) { | ||
if (callback) callback(); | ||
return; | ||
} | ||
if (!doUpdateCallback) return; | ||
if(!adapter) return safeCallback(callback); | ||
if (!callback) callback = nop; | ||
@@ -923,27 +943,15 @@ var id = 'system.adapter.' + adapter.namespace; | ||
var aktVersion = parseIntVersion(adapter.ioPack.common.version); | ||
function callUpdate() { | ||
doUpdateCallback(prevVersion, aktVersion, function(err) { | ||
savePrevVersion(adapter); | ||
//adapter.states.setState(vid, { val: adapter.ioPack.common.version, ack: true, from: id }); | ||
callback(); | ||
}); | ||
} | ||
if (!err && state) { | ||
prevVersion = parseIntVersion(state.val); | ||
if (prevVersion < aktVersion) { | ||
callUpdate(); | ||
prevVersion = parseIntVersion(hasProp(state, 'val') ? state.val : '0'); | ||
if (prevVersion < aktVersion) { | ||
if (typeof doUpdateCallback == 'function') { | ||
doUpdateCallback(prevVersion, aktVersion, function (err) { | ||
savePrevVersion(); | ||
callback(); | ||
}); | ||
return; | ||
} else { | ||
callback(); | ||
savePrevVersion(); | ||
} | ||
return; | ||
} | ||
adapter.objects.setObject(vid, { | ||
type: 'state', | ||
common: {name: 'version', role: "indicator.state", desc: 'version check for updates'}, | ||
native: {} | ||
}, function (err, obj) { | ||
callUpdate(); | ||
}); | ||
callback(); | ||
}); | ||
@@ -979,4 +987,5 @@ } | ||
var timer; | ||
var initDone = false; | ||
_adapter.getForeignObject('system.adapter.' + _adapter.namespace, function(err, obj) { | ||
//if (!err && obj && obj.common && obj.common.enabled === false) { | ||
if (!err && getProp(obj, 'common.enabled') === false) { | ||
@@ -989,6 +998,15 @@ // running in debuger | ||
} | ||
if (!initDone) { | ||
if(timer) clearTimeout(timer); | ||
_devices.init(_adapter, function(err) { | ||
callback(); | ||
}); | ||
} | ||
}); | ||
timer = setTimeout(function() { | ||
initDone = true; | ||
_devices.init(_adapter, function(err) { | ||
callback(); | ||
}); | ||
}); | ||
}, 10000) | ||
}; | ||
@@ -1010,3 +1028,5 @@ exports.main = _main; | ||
} | ||
if (!fns.adapter) fns.adapter = require(__dirname + '/../../lib/utils').adapter; | ||
if (!fns.adapter) { | ||
fns.adapter = require(__dirname + '/../../lib/utils').adapter; | ||
} | ||
var options = fns.options; | ||
@@ -1041,10 +1061,14 @@ if (!options.unload) { | ||
options.ready = function () { | ||
if (fns.onUpdate) { | ||
checkIfUpdated(fns.onUpdate, function() { | ||
_main(fns.main); | ||
}); | ||
return; | ||
} | ||
savePrevVersion(); | ||
_main(fns.main); | ||
checkIfUpdated(fns.onUpdate, function() { | ||
_main(fns.main); | ||
}); | ||
//if (fns.onUpdate) { | ||
// checkIfUpdated(fns.onUpdate, function() { | ||
// _main(fns.main); | ||
// }); | ||
// return; | ||
//} | ||
//savePrevVersion(); | ||
//_main(fns.main); | ||
} | ||
@@ -1101,2 +1125,5 @@ } | ||
}; | ||
this.start = function () { | ||
this.start = this.get(); | ||
}; | ||
@@ -1114,4 +1141,10 @@ this.start = process.hrtime(); | ||
var _sprintf = require('sprintf-js'); | ||
exports.sprintf = _sprintf.sprintf; | ||
exports.vsprintf = _sprintf.vsprintf; | ||
try { | ||
var _sprintf = require('sprintf-js'); | ||
exports.sprintf = _sprintf.sprintf; | ||
exports.vsprintf = _sprintf.vsprintf; | ||
} catch(e) { | ||
exports.sprintf = function(fs) { return 'sprintf-js not loaded ' + fs} | ||
exports.vsprintf = exports.sprintf | ||
} | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39417
1013