mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
76_SMAPortalSPG: FTUI widget contrib
git-svn-id: https://svn.fhem.de/fhem/trunk@19678 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
f3f8f52449
commit
3d33fef49c
66
fhem/contrib/DS_Starter/widget_smaportalspg.js
Normal file
66
fhem/contrib/DS_Starter/widget_smaportalspg.js
Normal file
@ -0,0 +1,66 @@
|
||||
/* FTUI Plugin
|
||||
* Copyright (c) 2016 Mario Stephan <mstephan@shared-files.de>
|
||||
* originally created by Thomas Nesges,
|
||||
* Under MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/* global ftui:true, Modul_widget:true */
|
||||
|
||||
"use strict";
|
||||
|
||||
var Modul_smaportalspg = function () {
|
||||
|
||||
function init_attr(elem) {
|
||||
elem.initData('get', 'STATE');
|
||||
elem.initData('max-update', 60);
|
||||
|
||||
me.addReading(elem, 'get');
|
||||
}
|
||||
|
||||
//usage of "function init()" from Modul_widget()
|
||||
|
||||
function update(dev, par) {
|
||||
|
||||
me.elements.filterDeviceReading('get', dev, par)
|
||||
.each(function (index) {
|
||||
var elem = $(this);
|
||||
var value = elem.getReading('get').val;
|
||||
//console.log('readingsgroup:',value);
|
||||
if (ftui.isValid(value)) {
|
||||
var dNow = new Date();
|
||||
|
||||
var lUpdate = elem.data('lastUpdate') || null;
|
||||
var lMaxUpdate = parseInt(elem.data('max-update'));
|
||||
if (isNaN(lMaxUpdate) || (lMaxUpdate < 1))
|
||||
lMaxUpdate = 10;
|
||||
|
||||
//console.log('readingsgroup update time stamp diff : ', dNow - lUpdate, ' param maxUPdate :' + lMaxUpdate + ' : ' + $(this).data('max-update') );
|
||||
lUpdate = (((dNow - lUpdate) / 1000) > lMaxUpdate) ? null : lUpdate;
|
||||
if (lUpdate === null) {
|
||||
//console.log('readingsgroup DO update' );
|
||||
elem.data('lastUpdate', dNow);
|
||||
|
||||
var cmd = [ 'get', elem.data('device'), "html" ].join(' ');
|
||||
ftui.log('readingsgroup update', dev, ' - ', cmd);
|
||||
|
||||
ftui.sendFhemCommand(cmd)
|
||||
.done(function (data, dev) {
|
||||
//console.log('received update for dynamic html : ', $(this) );
|
||||
elem.html(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// public
|
||||
// inherit all public members from base class
|
||||
var me = $.extend(new Modul_widget(), {
|
||||
//override or own public members
|
||||
widgetname: 'smaportalspg',
|
||||
init_attr: init_attr,
|
||||
update: update,
|
||||
});
|
||||
|
||||
return me;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user