diff --git a/config.js b/config.js new file mode 100644 index 0000000..19973a4 --- /dev/null +++ b/config.js @@ -0,0 +1,14 @@ +'use strict'; + +const { Database } = require('gateway-addon'); + +module.exports = { + load, +}; + +async function load(manifestId) { + const database = new Database(manifestId); + await database.open() + const config = await database.loadConfig(); + return config; +} diff --git a/manifest.json b/manifest.json index ac4c500..dfae0e3 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "manifest_version": 1, "name": "Netatmo Energy Adapter", "short_name": "Netatmo Energy", - "version": "0.0.2", + "version": "0.0.3", "options": { "schema": { "type": "object", diff --git a/netatmo-energy-adapter.js b/netatmo-energy-adapter.js index efa34dd..e18d816 100644 --- a/netatmo-energy-adapter.js +++ b/netatmo-energy-adapter.js @@ -7,6 +7,9 @@ const { } = require('gateway-addon'); const Netatmo = require('netatmo'); +const config = require('./config'); +const manifest = require('./manifest.json'); + const AVAILABLE_TYPES = [ 'NRV', ]; @@ -120,16 +123,20 @@ class RoomDevice extends Device { } class NetatmoEnergyAdapter extends Adapter { - constructor(addonManager, manifest, reportError) { - super(addonManager, 'NetatmoEnergyAdapter', manifest.name); - const config = manifest.moziot.config; + constructor(addonManager) { + super(addonManager, 'NetatmoEnergyAdapter', manifest.id); + this.init(addonManager, manifest.id); + } + + async init(addonManager, manifestId) { + const fullConfig = await config.load(manifestId); try { - this.netatmo = new Netatmo(config); + this.netatmo = new Netatmo(fullConfig); } catch(error) { console.warn(error); this.netatmo = undefined; - reportError(packageName, "Netatmo API credentials are not valid. Please provide credentials in the add-on settings."); + console.error("Netatmo API credentials are not valid. Please provide credentials in the add-on settings."); return; } diff --git a/package-lock.json b/package-lock.json index e165a45..51b479d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "netatmo-energy-adapter", - "version": "0.0.2", + "version": "0.0.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b5dfefb..e7185bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "netatmo-energy-adapter", - "version": "0.0.2", + "version": "0.0.3", "description": "Netatmo Energy Adapter for WebThings Gateway", "author": "Michael Kohler ", "main": "index.js", @@ -18,6 +18,7 @@ }, "files": [ "index.js", + "config.js", "manifest.json", "package.json", "netatmo-energy-adapter.js",