iobroker.netatmo
Advanced tools
Comparing version 0.4.1 to 0.5.0
{ | ||
"common": { | ||
"name": "netatmo", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"title": "Netatmo Adapter", | ||
@@ -22,3 +22,4 @@ "desc": { | ||
"loglevel": "info", | ||
"type": "hardware" | ||
"type": "hardware", | ||
"localLink": "http://%ip%:%port%" | ||
}, | ||
@@ -34,3 +35,6 @@ "native": { | ||
"unknown_person_time": 24, | ||
"location_elevation": 0 | ||
"location_elevation": 0, | ||
"port": 8085, | ||
"ssl": false, | ||
"external_host": "" | ||
}, | ||
@@ -37,0 +41,0 @@ "objects": [ |
31
main.js
@@ -8,3 +8,3 @@ /* jshint -W097 */// jshint strict:false | ||
var netatmo = require('netatmo-homey'); | ||
var netatmo = require('netatmo'); | ||
var api = null; | ||
@@ -18,2 +18,4 @@ | ||
var webServer = null; | ||
var _deviceUpdateTimer; | ||
@@ -27,2 +29,14 @@ var _welcomeUpdateTimer; | ||
adapter.on('unload', function (callback) { | ||
try { | ||
if (welcome) | ||
welcome.finalize(); | ||
adapter.log.info('cleaned everything up...'); | ||
callback(); | ||
} catch (e) { | ||
callback(); | ||
} | ||
}); | ||
adapter.on('ready', function () { | ||
@@ -52,2 +66,8 @@ if (adapter.config.username && adapter.config.password) { | ||
if (typeof adapter.config.ssl === "undefined") | ||
adapter.config.ssl = false; | ||
if (!adapter.config.port) | ||
adapter.config.port = 8085; | ||
if (adapter.config.netatmoWeather) { | ||
@@ -77,3 +97,5 @@ scope += " read_station"; | ||
station = new NetatmoStation(api, adapter); | ||
station.requestUpdateWeatherStation(); | ||
_deviceUpdateTimer = setInterval(function () { | ||
@@ -86,2 +108,4 @@ station.requestUpdateWeatherStation(); | ||
welcome = new NetatmoWelcome(api, adapter); | ||
welcome.init(); | ||
welcome.requestUpdateIndoorCamera(); | ||
@@ -96,5 +120,2 @@ | ||
adapter.log.error("Please add username, password and choose at least one product within the adapter settings!"); | ||
}); | ||
}); |
@@ -12,2 +12,28 @@ module.exports = function (myapi, myadapter) { | ||
var webServer = null; | ||
var that = null; | ||
this.init = function () { | ||
that = this; | ||
if (adapter.config.external_host && adapter.config.external_host !== "" && adapter.config.port) { | ||
initWebServer(); | ||
var hookUrl = "http://" + adapter.config.external_host + ":" + adapter.config.port; | ||
api.addWebHook(hookUrl, function (err, body) { | ||
if (err) | ||
adapter.log.info("Error registering WebHook: " + JSON.stringify(err)); | ||
else | ||
adapter.log.info("Registered WebHook " + hookUrl); | ||
}); | ||
} | ||
}; | ||
this.finalize = function () { | ||
if (webServer) { | ||
adapter.log.info("Unregistering WebHook"); | ||
api.dropWebHook(); | ||
} | ||
}; | ||
this.requestUpdateIndoorCamera = function () { | ||
@@ -43,4 +69,97 @@ api.getHomeData({}, function (err, data) { | ||
}); | ||
}; | ||
function initWebServer() { | ||
if (adapter.config.ssl) { | ||
// subscribe on changes of permissions | ||
adapter.subscribeForeignObjects('system.group.*'); | ||
adapter.subscribeForeignObjects('system.user.*'); | ||
if (!adapter.config.certPublic) { | ||
adapter.config.certPublic = 'defaultPublic'; | ||
} | ||
if (!adapter.config.certPrivate) { | ||
adapter.config.certPrivate = 'defaultPrivate'; | ||
} | ||
// Load certificates | ||
adapter.getForeignObject('system.certificates', function (err, obj) { | ||
if (err || !obj || !obj.native.certificates || !adapter.config.certPublic || !adapter.config.certPrivate || !obj.native.certificates[adapter.config.certPublic] || !obj.native.certificates[adapter.config.certPrivate] | ||
) { | ||
adapter.log.error('Cannot enable secure web server, because no certificates found: ' + adapter.config.certPublic + ', ' + adapter.config.certPrivate); | ||
} else { | ||
adapter.config.certificates = { | ||
key: obj.native.certificates[adapter.config.certPrivate], | ||
cert: obj.native.certificates[adapter.config.certPublic] | ||
}; | ||
} | ||
webServer = _initWebServer(adapter.config); | ||
}); | ||
} else { | ||
webServer = _initWebServer(adapter.config); | ||
} | ||
} | ||
function _initWebServer(settings) { | ||
var server = { | ||
server: null, | ||
settings: settings | ||
}; | ||
if (settings.port) { | ||
if (settings.ssl) { | ||
if (!adapter.config.certificates) { | ||
return null; | ||
} | ||
} | ||
if (settings.ssl) { | ||
server.server = require('https').createServer(adapter.config.certificates, requestProcessor); | ||
} else { | ||
server.server = require('http').createServer(requestProcessor); | ||
} | ||
server.server.__server = server; | ||
} else { | ||
adapter.log.error('port missing'); | ||
process.exit(1); | ||
} | ||
if (server.server) { | ||
adapter.getPort(settings.port, function (port) { | ||
if (port != settings.port && !adapter.config.findNextPort) { | ||
adapter.log.error('port ' + settings.port + ' already in use'); | ||
process.exit(1); | ||
} | ||
server.server.listen(port); | ||
adapter.log.info('http' + (settings.ssl ? 's' : '') + ' server listening on port ' + port); | ||
}); | ||
} | ||
if (server.server) { | ||
return server; | ||
} else { | ||
return null; | ||
} | ||
} | ||
function requestProcessor(req, res) { | ||
req.on('data', function (chunk) { | ||
// needed dummy event ... | ||
}); | ||
req.on('end', function () { | ||
adapter.log.info("Got an realtime event!"); | ||
// TODO: Parse event instead of full update | ||
that.requestUpdateIndoorCamera(); | ||
res.writeHead(200); | ||
res.write("OK"); | ||
res.end(); | ||
}); | ||
} | ||
function getHomeName(aHomeName) { | ||
@@ -121,3 +240,2 @@ return aHomeName.replaceAll(" ", "-").replaceAll("---", "-").replaceAll("--", "-"); | ||
function getCameraName(aCameraName) { | ||
@@ -326,4 +444,2 @@ return aCameraName.replaceAll(" ", "-").replaceAll("---", "-").replaceAll("--", "-"); | ||
if (bKnown || cleanupDate < personDate) { | ||
var fullPath = aParent + ".Persons"; | ||
@@ -827,7 +943,4 @@ | ||
}); | ||
} | ||
function cleanUpUnknownPersons(home) { | ||
@@ -834,0 +947,0 @@ |
{ | ||
"name": "iobroker.netatmo", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "ioBroker netatmo Adapter", | ||
@@ -35,3 +35,4 @@ "author": { | ||
"dewpoint": "^1.0.0", | ||
"netatmo-homey": "^2.1.0" | ||
"netatmo-homey": "https://github.com/PArns/netatmo.git", | ||
"request": "^2.67.0" | ||
}, | ||
@@ -38,0 +39,0 @@ "devDependencies": { |
@@ -16,2 +16,5 @@ ![Logo](admin/netatmo.png) | ||
### 0.5.0 | ||
* (PArns) Added realtime events for Netatmo Welcome | ||
### 0.4.1 | ||
@@ -29,3 +32,3 @@ * (PArns) Removed log warnings for Wind sensor | ||
### 0.3.0 | ||
* (wep4you) Initial implementation of netatmo welcome camera | ||
* (wep4you) Initial implementation of Netatmo welcome camera | ||
@@ -32,0 +35,0 @@ ### 0.2.2 |
Sorry, the diff of this file is not supported yet
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
111937
1865
65
3
1
4
+ Addedrequest@^2.67.0
- Removedmoment@2.30.1(transitive)
- Removednetatmo-homey@2.1.0(transitive)