Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eWeLink authentication #10

Merged
merged 3 commits into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"homepage": "https://github.com/ottoszika/node-red-contrib-ewelink#readme",
"node-red": {
"nodes": {
"ewlink-credentials": "src/credentials/credentials.js",
"basic": "src/basic/basic.js"
}
},
Expand Down
28 changes: 28 additions & 0 deletions src/credentials/credentials.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script type="text/javascript">
RED.nodes.registerType('ewelink-credentials', {
category: 'config',
credentials: {
email: { type: 'email' },
password: { type: 'password' },
region: { type: 'text' }
},
label: function () {
return this.credentials.email + ' | ' + this.credentials.region;
}
});
</script>

<script type="text/x-red" data-template-name="ewelink-credentials">
<div class="form-row">
<label for="node-config-input-email"><i class="fa fa-envelope"></i> Email</label>
<input type="email" id="node-config-input-email">
</div>
<div class="form-row">
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
<input type="password" id="node-config-input-password">
</div>
<div class="form-row">
<label for="node-config-input-region"><i class="fa fa-globe"></i> Region</label>
<input type="text" id="node-config-input-region">
</div>
</script>
29 changes: 29 additions & 0 deletions src/credentials/credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Credentials node.
* This is a configuration node that holds the credentials for eWeLink.
*/
module.exports = function (RED) {
/**
* Credentials node constructor.
*
* @param {object} config The configuration for the node.
*/
function CredentialsNode(config) {
// Create the node
RED.nodes.createNode(this, config);

// Unpack credentials
this.email = this.credentials.email;
this.password = this.credentials.password;
this.region = this.credentials.region;
}

// Register node
RED.nodes.registerType('ewelink-credentials', CredentialsNode, {
credentials: {
email: { type: 'email' },
password: { type: 'password' },
region: { type: 'text' }
}
});
}
49 changes: 49 additions & 0 deletions test/credentials_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var helper = require('node-red-node-test-helper');
var credentialsNode = require('../src/credentials/credentials');

describe('Credentials Node', function () {

var credentials = {
n1: {
email: 'dummy@dummy.tld',
password: 'abcd',
region: 'eu'
}
};

beforeEach(function (done) {
helper.startServer(done);
});

afterEach(function (done) {
helper.unload().then(function () {
helper.stopServer(done);
});
});

it('should be loaded', function (done) {
var flow = [{ id: 'n1', type: 'ewelink-credentials' }];
helper.load(credentialsNode, flow, credentials, function () {
var n1 = helper.getNode('n1');

n1.credentials.should.have.property('email', 'dummy@dummy.tld');
n1.credentials.should.have.property('password', 'abcd');
n1.credentials.should.have.property('region', 'eu');

done();
});
});

it('should unpack credentials', function (done) {
var flow = [{ id: 'n1', type: 'ewelink-credentials' }];
helper.load(credentialsNode, flow, credentials, function () {
var n1 = helper.getNode('n1');

n1.should.have.property('email', 'dummy@dummy.tld');
n1.should.have.property('password', 'abcd');
n1.should.have.property('region', 'eu');

done();
});
});
});