iobroker.fritzdect
Version:
ioBroker fritzbox DECT Adapter
360 lines (344 loc) • 11 kB
HTML
<html>
<head>
<!-- Load ioBroker scripts and styles-->
<link rel="stylesheet" type="text/css" href="../../css/adapter.css" />
<link rel="stylesheet" type="text/css" href="../../lib/css/materialize.css">
<script type="text/javascript" src="../../lib/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../socket.io/socket.io.js"></script>
<script type="text/javascript" src="../../js/translate.js"></script>
<script type="text/javascript" src="../../lib/js/materialize.js"></script>
<script type="text/javascript" src="../../js/adapter-settings.js"></script>
<!-- Load our own files -->
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="words.js"></script>
<script type="text/javascript">
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 init() {
$('#testd').click(testd);
$('#testg').click(testg);
$('#testt').click(testt);
$('#tests').click(tests);
$('#testc').click(testc);
$('#testo').click(testo);
$('#testr').click(testr);
}
// This will be called by the admin adapter when the settings page loads
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 === 'fritz_pw') {
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])
.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())
;
}
});
init();
onChange(false);
// reinitialize all the Materialize labels on the page if you are dynamically adding inputs:
if (M) M.updateTextFields();
}
// ehemalige load wird zu loadHelper um secrect mit aufzunehmen, wie meross
function load(settings, onChange) {
socket.emit('getObject', 'system.config', function (err, obj) {
secret = (obj.native ? obj.native.secret : '') || 'Zgfr56gFe87jJOM';
loadHelper(settings, onChange);
});
onChange(false);
}
//debug functions
function testg() {
if (!common.enabled) {
showToast(null, _('Enable first the adapter to test client.'));
return;
}
if (changed) {
showToast(null, _('First save the adapter'));
return;
}
$('#testg').addClass('disabled');
sendTo(null, 'groups', null, function (result) {
$('#testg').removeClass('disabled');
console.log("result is " + JSON.stringify(result));
showMessage(JSON.stringify(result), _('Result: '));
});
}
function testd() {
if (!common.enabled) {
showToast(null, _('Enable first the adapter to test client.'));
return;
}
if (changed) {
showToast(null, _('First save the adapter'));
return;
}
$('#testd').addClass('disabled');
sendTo(null, 'devices', null, function (result) {
$('#testd').removeClass('disabled');
console.log("result is " + JSON.stringify(result));
showMessage(JSON.stringify(result), _('Result: '));
});
}
function testt() {
if (!common.enabled) {
showToast(null, _('Enable first the adapter to test client.'));
return;
}
if (changed) {
showToast(null, _('First save the adapter'));
return;
}
$('#testt').addClass('disabled');
sendTo(null, 'templates', null, function (result) {
$('#testt').removeClass('disabled');
console.log("result is " + JSON.stringify(result));
showMessage(JSON.stringify(result), _('Result: '));
});
}
function tests() {
if (!common.enabled) {
showToast(null, _('Enable first the adapter to test client.'));
return;
}
if (changed) {
showToast(null, _('First save the adapter'));
return;
}
$('#tests').addClass('disabled');
sendTo(null, 'statistic', null, function (result) {
$('#tests').removeClass('disabled');
console.log("result is " + JSON.stringify(result));
showMessage(JSON.stringify(result), _('Result: '));
});
}
function testc() {
if (!common.enabled) {
showToast(null, _('Enable first the adapter to test client.'));
return;
}
if (changed) {
showToast(null, _('First save the adapter'));
return;
}
$('#testc').addClass('disabled');
sendTo(null, 'color', null, function (result) {
$('#testc').removeClass('disabled');
console.log("result is " + JSON.stringify(result));
showMessage(JSON.stringify(result), _('Result: '));
});
}
function testo() {
if (!common.enabled) {
showToast(null, _('Enable first the adapter to test client.'));
return;
}
if (changed) {
showToast(null, _('First save the adapter'));
return;
}
$('#testo').addClass('disabled');
sendTo(null, 'rights', null, function (result) {
$('#testo').removeClass('disabled');
console.log("result is " + JSON.stringify(result));
showMessage(JSON.stringify(result), _('Result: '));
});
}
function testr() {
if (!common.enabled) {
showToast(null, _('Enable first the adapter to test client.'));
return;
}
if (changed) {
showToast(null, _('First save the adapter'));
return;
}
$('#testr').addClass('disabled');
sendTo(null, 'trigger', null, function (result) {
$('#testr').removeClass('disabled');
console.log("result is " + JSON.stringify(result));
showMessage(JSON.stringify(result), _('Result: '));
});
}
// 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 if ($this.attr('type') === 'number') {
obj[$this.attr('id')] = parseFloat($this.val());
} else {
//obj[$this.attr('id')] = $this.val();
var value = $this.val();
if ($this.attr('id') === 'fritz_pw') {
value = encrypt(secret, value);
}
obj[$this.attr('id')] = value;
}
});
callback(obj);
}
</script>
</head>
<body>
<div class="m adapter-container">
<div class="row">
<div class="col s12 m4 l2">
<img src="fritzdect_logo.png" class="logo">
</div>
</div>
<!-- Put your content here -->
<div class="section">
<div class="row">
<div class="col s12">
<h6 class="translate sub-title">FritzBox Login and Polling</h6>
</div>
</div>
<div class="row">
<div class="col s12">
<input class="value" id="fritz_ip" /><label for="fritz_ip" class="translate">Fritzbox IP</label>
</div>
</div>
<div class="row">
<div class="col s6">
<input class="value" id="fritz_user" /><label for="fritz_user" class="translate">Fritzbox
User</label>
</div>
<div class="col s6">
<input class="value" id="fritz_pw" type="password" /><label for="fritz_pw"
class="translate">Fritzbox Password</label>
</div>
</div>
<div class="row">
<div class="col s6">
<input class="value" id="fritz_interval" type="number" /><label for="fritz_interval"
class="translate">Fritzbox
Polling Interval (sek.)</label>
</div>
</div>
</div>
<div class="section">
<div class="row">
<div class="col s12">
<h6 class="translate sub-title">Thermostat Settings</h6>
</div>
</div>
<div class="row">
<div class="col s6">
<input class="value" id="fritz_boosttime" type="number" /><label for="fritz_boosttime"
class="translate">default
time (minutes) for boost activation
</label>
</div>
<div class="col s6">
<input class="value" id="fritz_windowtime" type="number" /><label for="fritz_windowtime"
class="translate">default
time (minutes) for window open activation</label>
</div>
</div>
<div class="row">
<div class="col s6">
<input class="value" id="fritz_tsolldefault" type="number" /><label for="fritz_tsolldefault"
class="translate">default target temperature</label>
</div>
</div>
</div>
<div class="section">
<div class="row">
<div class="col s12">
<h6 class="translate sub-title">Write only Changes to Objects</h6>
</div>
</div>
<div class="row">
<div class="col s6">
<input class="value" id="fritz_writeonhyst" type="checkbox" /><span class="translate">
must be checked (true) to activate the reduced logging</span>
</div>
</div>
</div>
<div class="section">
<div class="row">
<div class="col s12">
<h6 class="translate sub-title">Adapter Options</h6>
</div>
</div>
<div class="row">
<div class="col s4">
<input class="value" id="fritz_exclude_templates" type="checkbox" /><span class="translate">
exclude templates (check if older FB)</span>
</div>
<div class="col s4">
<input class="value" id="fritz_exclude_routines" type="checkbox" /><span class="translate">
exclude routines (check if older FB)</span>
</div>
<div class="col s4">
<input class="value" id="fritz_exclude_stats" type="checkbox" /><span class="translate">
exclude statistics (check if older FB)</span>
</div>
</div>
<div class="row">
<div class="col s6">
<input class="value" id="fritz_options" /><label class="translate">options for the
http.request
(usually
empty, unless you make test)</label>
</div>
</div>
</div>
<div class="section">
<div class="row">
<div class="col s12">
<h6 class="translate sub-title">FritzBox Adapter Debugging</h6>
</div>
</div>
<div class="row">
<div class="col s2">
<a id="testd" class="btn"><span class="translate">My Devices</span></a>
</div>
<div class="col s2">
<a id="testg" class="btn"><span class="translate">My Groups</span></a>
</div>
<div class="col s2">
<a id="testt" class="btn"><span class="translate">My Templates</span></a>
</div>
<div class="col s2">
<a id="tests" class="btn"><span class="translate">My Stats</span></a>
</div>
<div class="col s2">
<a id="testo" class="btn"><span class="translate">My Rights</span></a>
</div>
<div class="col s2">
<a id="testr" class="btn"><span class="translate">My Trigger</span></a>
</div>
</div>
</div>
</body>
</html>