Skip to content

Commit

Permalink
Version 0.3.0
Browse files Browse the repository at this point in the history
* Implemented encrypted password storage
* Fixed issue with polling of states (this should fix "connection failed" of version 0.2.9)
* Correct error message in LOG when credentials are missing
  • Loading branch information
DutchmanNL committed Dec 16, 2018
1 parent 1bb2922 commit 5f4022f
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 190 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ pass = demo

## To-Do

Core-Functionality
* Adjustable polling invervall
* Better interface for adapter configuration
* Translations

Backend
* store password encrypted
* better handling of state creation and updates

## Changelog

### 0.3.0
* Implemented encrypted password storage
* Fixed issue with polling of states (this should fix "connection failed" of version 0.2.9)
* Correct error message in LOG when credentials are missing

### 0.2.9
* implemented intervall short and long, only relevant information (current consumption) is pulled short alle other (totals) on interval Long
* Implemented additional datapoints for Power, Power_x_Consumption and Power_x_Delivery, the power value can have a positive and negative number depending of if u consumer or produce for the network. Seperate - and + values to seperated datapoints.
Expand Down
102 changes: 71 additions & 31 deletions admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,85 @@
<script type="text/javascript" src="words.js"></script>

<script type="text/javascript">

// Create secrect for encrypted password storage
var secret;
function encrypt(key, value) {
var result = '';
for(var i = 0; i < value.length; ++i) {
result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));
}
return result;
}
function decrypt(key, value) {
var result = '';
for(var i = 0; i < value.length; ++i) {
result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));
}
return result;
}

function loadHelper(settings, onChange) {
// example: select elements with id=key and class=value and insert value
if (!settings) return;
$('.value').each(function () {
var $key = $(this);
var id = $key.attr('id');
if (id === 'Password') {
settings[id] = decrypt(secret, settings[id]);
}
if ($key.attr('type') === 'checkbox') {
// do not call onChange direct, because onChange could expect some arguments
$key.prop('checked', settings[id]).change(function() {
onChange();
});
} else {
// do not call onChange direct, because onChange could expect some arguments
$key.val(settings[id]).change(function() {
onChange();
}).keyup(function() {
onChange();
});
}
});
onChange(false);
// function Materialize.updateTextFields(); to reinitialize all the Materialize labels on the page if you are dynamically adding inputs.
M.updateTextFields();
}

// This will be called by the admin adapter when the settings page loads
function load(settings, onChange) {
// example: select elements with id=key and class=value and insert value
if (!settings) return;
$('.value').each(function () {
var $key = $(this);
var id = $key.attr('id');
if ($key.attr('type') === 'checkbox') {
// do not call onChange direct, because onChange could expect some arguments
$key.prop('checked', settings[id])
.on('change', () => onChange())
;
} else {
// do not call onChange direct, because onChange could expect some arguments
$key.val(settings[id])
.on('change', () => onChange())
.on('keyup', () => onChange())
;
}
});
socket.emit('getObject', 'system.config', function (err, obj) {
secret = (obj.native ? obj.native.secret : '') || 'Zgfr56gFe87jJOM';
loadHelper(settings, onChange);
});
onChange(false);
// reinitialize all the Materialize labels on the page if you are dynamically adding inputs:
if (M) M.updateTextFields();
// if (M) M.updateTextFields();
}

// This will be called by the admin adapter when the user presses the save button
function save(callback) {
// example: select elements with class=value and build settings object
var obj = {};
$('.value').each(function () {
var $this = $(this);
if ($this.attr('type') === 'checkbox') {
obj[$this.attr('id')] = $this.prop('checked');
} else {
obj[$this.attr('id')] = $this.val();
}
});
callback(obj);
}
// example: select elements with class=value and build settings object
var obj = {};
$('.value').each(function () {
var $this = $(this);
var id = $this.attr('id');
if ($this.attr('type') === 'checkbox') {
obj[id] = $this.prop('checked');
} else {
var value = $this.val();
if (id === 'Password') {
value = encrypt(secret, value);
}
obj[id] = value;
}
});

callback(obj);
}
</script>

</head>
Expand All @@ -75,11 +115,11 @@ <h1 class="translate">discovergy adapter settings</h1>
<label for="Username" class="translate">Username</label>
</div>
<div class="col s6 input-field">
<input type="text" class="value" id="Password" />
<input type="password" class="value" id="Password" />
<label for="Password" class="translate">Password</label>
</div>
<div class="col s6 input-field">
<input type="number" class="value" min="2" max="60" id="pull_Short">
<input type="number" class="value" min="1" max="60" id="pull_Short">
<label for="pull_Short" class="translate">pull_Short</label>
</div>
<div class="col s6 input-field">
Expand Down
18 changes: 15 additions & 3 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"common": {
"name": "discovergy",
"version": "0.2.9",
"version": "0.3.0",
"news": {
"0.3.1": {
"0.3.0": {
"en": "Beta",
"de": "Beta",
"ru": "Начальная версия",
Expand Down Expand Up @@ -70,5 +70,17 @@
"pull_Long": "1"
},
"objects": [],
"instanceObjects": []
"instanceObjects": [{
"_id": "info.connection",
"type": "state",
"common": {
"role": "indicator.connected",
"name": "If communication with Discovergy works",
"type": "boolean",
"read": true,
"write": false,
"def": false
},
"native": {}
}]
}
Loading

0 comments on commit 5f4022f

Please sign in to comment.