Skip to content

Commit

Permalink
Directly require manifest and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKohler committed Feb 7, 2021
1 parent ea2c641 commit 3a5ef79
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
14 changes: 14 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 12 additions & 5 deletions netatmo-energy-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"main": "index.js",
Expand All @@ -18,6 +18,7 @@
},
"files": [
"index.js",
"config.js",
"manifest.json",
"package.json",
"netatmo-energy-adapter.js",
Expand Down

0 comments on commit 3a5ef79

Please sign in to comment.