diff --git a/www/tablet/js/fhem-tablet-ui.js b/www/tablet/js/fhem-tablet-ui.js index ecb58465..0d371f8b 100755 --- a/www/tablet/js/fhem-tablet-ui.js +++ b/www/tablet/js/fhem-tablet-ui.js @@ -127,11 +127,10 @@ var Modul_widget = function () { function addReading(elem, key) { var data = elem.data(key); if (ftui.isValid(data)) { - data = data.toString(); - if ($.isArray(data) || !data.match(/^[#\.\[].*/)) { + if ($.isArray(data) || !data.toString().match(/^[#\.\[].*/)) { var device = elem.data('device'); if (!$.isArray(data)) { - data = new Array(data); + data = new Array(data.toString()); } for (var i = 0, len = data.length; i < len; i++) { var reading = data[i]; diff --git a/www/tablet/js/fhem-tablet-ui.min.js b/www/tablet/js/fhem-tablet-ui.min.js index db760938..deb9b97d 100755 --- a/www/tablet/js/fhem-tablet-ui.min.js +++ b/www/tablet/js/fhem-tablet-ui.min.js @@ -1 +1 @@ -"use strict";if("function"==typeof Framework7){var f7={ftui:new Framework7({animateNavBackIcon:!0}),options:{dynamicNavbar:!0,domCache:!0},views:[]};$(".view").each(function(t){var e=f7.ftui.addView("#"+$(this)[0].id,{dynamicNavbar:!0});f7.ftui.views.push(e)}),f7.ftui.onPageInit("*",function(t){ftui.log(t.name+" initialized"),ftui.initWidgets('[data-page="'+t.name+'"]')})}var Modul_widget=function(){function init(){ftui.log(1,"init widget: name="+me.widgetname+" area="+me.area),me.elements=$('[data-type="'+me.widgetname+'"]',me.area),me.elements.each(function(t){me.init_attr($(this)),me.init_ui($(this))})}function isReadOnly(t){var e=t.data("readonly");return"true"===e||"1"===e||"on"===e||1===e}function substitution(value,subst){if(ftui.isValid(subst))if($.isArray(subst)){for(var i=0,len=subst.length;len>i;i+=2)if(value==subst[i]&&len>i+1)return subst[i+1]}else{if(subst.match(/^s/)){var f=subst.substr(1,1),sub=subst.split(f);return value.replace(new RegExp(sub[1],sub[3]),sub[2])}if(subst.match(/weekdayshort/))return ftui.dateFromString(value).ee();if(subst.match(/.*\(\)/))return eval("value."+subst)}return value}function checkHide(t,e){if(ftui.isValid(t.data("hide"))){var i=t.data("hide");e===i||t.isDeviceReading("hide")&&("true"===e||"1"===e||"on"===e||1===e)||e.match(new RegExp("^"+i+"$"))?ftui.isValid(t.data("hideparents"))?t.parents(t.data("hideparents")).hide():t.hide():ftui.isValid(t.data("hideparents"))?t.parents(t.data("hideparents")).show():t.show()}}function fix(t,e){return $.isNumeric(t)&&e>=0?Number(t).toFixed(e):t}function map(t,e,i){if("object"==typeof t&&null!==t)for(var n in t)if(e===n||e.match(new RegExp("^"+n+"$")))return t[n];return i}function init_attr(t){}function init_ui(t){t.text(me.widgetname)}function addReading(t,e){var i=t.data(e);if(ftui.isValid(i)&&(i=i.toString(),$.isArray(i)||!i.match(/^[#\.\[].*/))){var n=t.data("device");$.isArray(i)||(i=new Array(i));for(var a=0,r=i.length;r>a;a++){var o=i[a];if(o.match(/:/)){var s=o.split(":");n=s[0],o=s[1]}if(ftui.isValid(n)&&ftui.isValid(o)){n=n.toString();var l="STATE"===o?n:[n,o].join("-");subscriptions[l]={},subscriptions[l].device=n,subscriptions[l].reading=o}}}}function update(t,e){ftui.log(1,"warning: "+me.widgetname+" does not implement update function")}var subscriptions={},elements,me={widgetname:"widget",area:"",isReadOnly:isReadOnly,init:init,init_attr:init_attr,init_ui:init_ui,update:update,substitution:substitution,checkHide:checkHide,fix:fix,map:map,addReading:addReading,subscriptions:subscriptions,elements:elements};return me},plugins={modules:[],addModule:function(t){this.modules.push(t)},removeArea:function(t){for(var e=this.modules.length-1;e>=0;e-=1)this.modules[e].area===t&&this.modules.splice(e,1)},updateParameters:function(){ftui.subscriptions={},ftui.subscriptionTs={},ftui.devs=[];for(var t=this.modules.length-1;t>=0;t-=1){var e=this.modules[t];for(var i in e.subscriptions){ftui.subscriptions[i]=e.subscriptions[i],ftui.subscriptionTs[i+"-ts"]=e.subscriptions[i];var n=ftui.subscriptions[i].device;ftui.devs.indexOf(n)<0&&ftui.devs.push(n)}}ftui.states.lastShortpoll=0},load:function(t,e){return ftui.log(1,"Load widget : "+t),ftui.loadPlugin(t,e)},update:function(t,e){$.each(this.modules,function(i,n){"object"==typeof n&&n.update(t,e)}),ftui.log(1,'update done for "'+t+":"+e+'"')}},ftui={version:"2.4.3",config:{DEBUG:!1,DEMO:!1,dir:"",filename:"",fhem_dir:"",debuglevel:0,doLongPoll:!1,lang:"de",shortpollInterval:0,styleCollection:{},stdColors:["green","orange","red","ligthblue","blue","gray","white","mint"]},poll:{currLine:0,xhr:null,longPollRequest:null,shortPollTimer:null,longPollTimer:null,timestamp:"01.01.1970"},states:{lastSetOnline:0,lastShortpoll:0,longPollRestart:!1},deviceStates:{},paramIdMap:{},timestampMap:{},subscriptions:{},subscriptionTs:{},gridster:{instances:{},instance:null,wx:0,wy:0,wm:5,mincols:0},init:function(){ftui.paramIdMap={},ftui.timestampMap={},ftui.loadStyleSchema(),ftui.gridster.wx=parseInt($("meta[name='widget_base_width']").attr("content")||74),ftui.gridster.wy=parseInt($("meta[name='widget_base_height']").attr("content")||71),ftui.gridster.mincols=parseInt($("meta[name='widget_min_cols']").attr("content")||$(window).width()/ftui.gridster.wx),$("meta[name='widget_margin']").attr("content")&&(ftui.gridster.wm=parseInt($("meta[name='widget_margin']").attr("content"))),ftui.config.doLongPoll="1"==$("meta[name='longpoll']").attr("content"),ftui.config.longPollFilter=$("meta[name='longpoll_filter']").attr("content")||".*",ftui.config.DEMO="1"==$("meta[name='demo']").attr("content"),ftui.config.debuglevel=$("meta[name='debug']").attr("content")||0,ftui.config.DEBUG=ftui.config.debuglevel>0,ftui.config.TOAST=$("meta[name='toast']").attr("content")||5,ftui.config.shortpollInterval=$("meta[name='shortpoll-only-interval']").attr("content")||30,ftui.config.dir=$('script[src*="fhem-tablet-ui"]').attr("src");var t=ftui.config.dir.split("/").pop();ftui.config.dir=ftui.config.dir.replace("/"+t,""),ftui.log(1,"Plugin dir: "+ftui.config.dir);var e=window.location.pathname;ftui.config.filename=e.substring(e.lastIndexOf("/")+1),ftui.log(1,"Filename: "+ftui.config.filename),ftui.config.fhem_dir=$("meta[name='fhemweb_url']").attr("content")||"/fhem/",ftui.log(1,"FHEM dir: "+ftui.config.fhem_dir);var i=navigator.language||navigator.userLanguage;ftui.config.lang=ftui.isValid(i)?i.split("-")[0]:"de";try{localStorage.setItem("ftui",ftui.version),localStorage.removeItem("ftui")}catch(n){ftui.toast("You are in Privacy Mode
Please deactivate Privacy Mode and then reload the page.","error")}$("
").prependTo("body").hide();var a=ftui.getAndroidVersion(),r=a&&parseFloat(a)<5,o=r?"touchstart":"touchstart mousedown";$("#shade").on(o,function(t){$(document).trigger("shadeClicked")}),ftui.readStatesLocal(),ftui.initPage(),$(document).on("initWidgetsDone",function(){ftui.startShortPollInterval(500)}),$(document).one("updateDone",function(){ftui.log(2,"document triggered updateDone"),ftui.initLongpoll()}),f7||$("*:not(select):not(textarea)").focus(function(){$(this).blur()}),ftui.config.debuglevel>0&&setInterval(function(){ftui.healthCheck()},6e4)},initGridster:function(t){if($.fn.gridster){ftui.gridster.instances[t]&&ftui.gridster.instances[t].destroy(),ftui.gridster.instances[t]=$(".gridster > ul",t).gridster({widget_base_dimensions:[ftui.gridster.wx,ftui.gridster.wy],widget_margins:[ftui.gridster.wm,ftui.gridster.wm],draggable:{handle:".gridster li > header"},min_cols:parseInt(ftui.gridster.mincols)}).data("gridster"),ftui.gridster.instances[t]&&("1"==$("meta[name='gridster_disable']").attr("content")&&ftui.gridster.instances[t].disable(),"1"==$("meta[name='gridster_starthidden']").attr("content")&&$(".gridster").hide());var e=$(".gridster > ul > li:has(* .gridster)");e.length>0&&e.css({"background-color":"transparent",margin:"-"+ftui.gridster.wm+"px",width:e.parent().width()-e.position().left,height:"100%"}),$(".gridster > ul > li:has(.center)").addClass("vbox"),$(".gridster > ul > li:has(.vbox)").addClass("vbox"),$(".gridster > ul > li > .hbox").addClass("center"),$(".gridster > ul > li > .vbox").addClass("center"),$(".gridster li > header ~ .hbox:only-of-type").each(function(t){$(this).css({height:"calc(100% - "+$(this).siblings("header").outerHeight()+"px)"})})}},initPage:function(t){t=ftui.isValid(t)?t:"",console.time("initPage"),ftui.log(2,"initPage - area="+t),ftui.initGridster(t);var e=$("[data-template]",t).length;ftui.log(2,"count of templates:",e),e>0?$("[data-template]",t).each(function(i){var n=$(this);$.get(n.data("template"),{},function(a){var r=n.data("parameter");for(var o in r)a=a.replace(new RegExp(o,"g"),r[o]);n.html(a),i===e-1&&ftui.initWidgets(t)})}):ftui.initWidgets(t)},initWidgets:function(t){t=ftui.isValid(t)?t:"";var e=[];ftui.log(3,plugins),plugins.removeArea(t),ftui.log(3,plugins),ftui.log(2,"initWidgets - area="+t),$("[data-type]",t).each(function(t){var i=$(this).data("type");e.indexOf(i)<0&&e.push(i)});var i=$.map(e,function(e,i){return plugins.load(e,t)});$.when.apply(this,i).then(function(){plugins.updateParameters(),ftui.log(1,"initWidgets - Done"),console.timeEnd("initPage"),$(document).trigger("initWidgetsDone",[t])})},initLongpoll:function(){if(ftui.log(2,"initLongpoll: "+ftui.config.doLongPoll),ftui.config.doLongPoll){var t=$("meta[name='longpoll-delay']").attr("content");t=$.isNumeric(t)?1e3*t:100,ftui.startLongPollInterval(t)}},startShortPollInterval:function(t){ftui.log(1,"start shortpoll in (ms):"+(t||1e3*ftui.config.shortpollInterval)),clearInterval(ftui.shortPollTimer),ftui.shortPollTimer=setTimeout(function(){ftui.shortPoll(),ftui.startShortPollInterval()},t||1e3*ftui.config.shortpollInterval)},startLongPollInterval:function(t){ftui.config.DEBUG&&t>999&&ftui.toast("Start Longpoll in "+t/1e3+"s"),clearInterval(ftui.longPollTimer),ftui.longPollTimer=setTimeout(function(){ftui.longPoll()},t),ftui.config.shortpollInterval=$("meta[name='shortpoll-interval']").attr("content")||900},shortPoll:function(){var t=(new Date).getTime()/1e3;if(!(t-ftui.states.lastShortpollShortPoll Request Failed, will retry in 3s
"+n,"error"),ftui.states.lastSetOnline=0,ftui.states.lastShortpoll=0,ftui.startShortPollInterval(3e3)})}},longPoll:function(){return ftui.config.DEMO?void console.log("DEMO-Mode: no longpoll"):ftui.xhr?void ftui.log(3,"valid ftui.xhr found"):ftui.longPollRequest?void ftui.log(3,"valid ftui.longPollRequest found"):(ftui.poll.currLine=0,ftui.config.DEBUG&&(ftui.states.longPollRestart?ftui.toast("Longpoll re-started"):ftui.toast("Longpoll started")),ftui.log(1,ftui.states.longPollRestart?"Longpoll re-started":"Longpoll started"),ftui.states.longPollRestart=!1,void(ftui.longPollRequest=$.ajax({url:ftui.config.fhem_dir,cache:!1,async:!0,data:{XHR:1,inform:"type=status;filter="+ftui.config.longPollFilter+";fmt=JSON"},xhr:function(){return ftui.xhr=new window.XMLHttpRequest,ftui.xhr.addEventListener("readystatechange",function(t){var e=t.target.responseText;if(4!=t.target.readyState&&3==t.target.readyState){var i=e.split(/\n/);i.pop();for(var n=ftui.poll.currLine,a=i.length;a>n;n++)if(ftui.log(5,i[n]),ftui.isValid(i[n])&&""!==i[n])try{var r=JSON.parse(i[n]),o=null,s=null,l=r[1]!==r[2];ftui.log(4,r);var u=ftui.paramIdMap[r[0]],f=ftui.timestampMap[r[0]];u&&(l&&(u.reading="STATE"),o=ftui.deviceStates[u.device]||{},s=o[u.reading]||{},s.val=r[1],s.valid=!0,o[u.reading]=s,ftui.deviceStates[u.device]=o,l&&ftui.subscriptions[r[0]]&&plugins.update(u.device,u.reading)),f&&!l&&(o=ftui.deviceStates[f.device]||{},s=o[f.reading]||{},s.date=r[1],o[f.reading]=s,ftui.poll.timestamp=s.date,ftui.deviceStates[f.device]=o,ftui.subscriptionTs[r[0]]&&plugins.update(f.device,f.reading))}catch(d){ftui.log(1,"Error: (longpoll) "+d)}ftui.poll.currLine=i.length,ftui.poll.currLine>9999&&(ftui.states.longPollRestart=!0,ftui.longPollRequest.abort())}},!1),ftui.xhr}}).done(function(t){ftui.xhr&&(ftui.xhr.abort(),ftui.xhr=null),ftui.longPollRequest=null,ftui.states.longPollRestart?ftui.longPoll():(ftui.log(1,"Disconnected from FHEM - poll done - "+t),ftui.restartLongPoll())}).fail(function(t,e,i){ftui.xhr&&(ftui.xhr.abort(),ftui.xhr=null),ftui.longPollRequest=null,ftui.states.longPollRestart?ftui.longPoll():(ftui.log(1,"Error while longpoll: "+e+": "+i),ftui.restartLongPoll())})))},setFhemStatus:function(t){return ftui.config.DEMO?void console.log("DEMO-Mode: no setFhemStatus"):(ftui.startShortPollInterval(),t=t.replace(" "," "),ftui.log(1,"send to FHEM: "+t),void $.ajax({async:!0,cache:!1,url:ftui.config.fhem_dir,data:{cmd:t,XHR:"1"}}).fail(function(t,e,i){ftui.toast("FHEM Command Failed
"+e+": "+i,"error")}).done(function(t){}))},loadStyleSchema:function(){$.each($('link[href$="-ui.css"],link[href$="-ui.min.css"]'),function(t,e){if(e&&e.sheet&&e.sheet.cssRules){var i=e.sheet.cssRules;for(var n in i)if(i[n].style){var a=i[n].style.cssText.split(";");a.pop();var r=i[n].selectorText,o={};for(var s in a){var l=a[s].toString().split(":");l[0].match(/color/)&&(o[$.trim(l[0])]=$.trim(l[1]).replace("! important","").replace("!important",""))}Object.keys(o).length>0&&(ftui.config.styleCollection[r]=o)}}})},onUpdateDone:function(){$(document).trigger("updateDone"),ftui.checkInvalidElements()},checkInvalidElements:function(){$(".autohide[data-get]").each(function(t){var e=$(this),i=e.getReading("get").valid;i&&i===!0?e.removeClass("invalid"):e.addClass("invalid")})},setOnline:function(){var t=(new Date).getTime()/1e3;t-ftui.states.lastSetOnline>60&&(ftui.config.DEBUG&&ftui.toast("Network connected"),ftui.states.lastSetOnline=t,ftui.states.lastShortpoll=0,ftui.startShortPollInterval(1e3),ftui.config.doLongPoll||(ftui.config.doLongPoll="1"==$("meta[name='longpoll']").attr("content"),ftui.config.doLongPoll&&ftui.startLongPollInterval(100)),ftui.log(1,"FTUI is online"))},setOffline:function(){ftui.config.DEBUG&&ftui.toast("Lost network connection"),ftui.config.doLongPoll=!1,clearInterval(ftui.shortPollTimer),clearInterval(ftui.longPollTimer),ftui.longPollRequest&&ftui.longPollRequest.abort(),ftui.saveStatesLocal(),ftui.log(1,"FTUI is offline")},readStatesLocal:function(){ftui.config.DEMO?$.ajax({async:!1,url:"/fhem/tablet/data/"+ftui.config.filename.replace(".html",".dat")}).done(function(t){ftui.deviceStates=JSON.parse(t)||{}}):ftui.deviceStates=JSON.parse(localStorage.getItem("deviceStates"))||{}},saveStatesLocal:function(){var t=JSON.stringify(ftui.deviceStates);localStorage.setItem("deviceStates",t),localStorage.setItem("shortPollDuration",ftui.poll.shortPollDuration)},restartLongPoll:function(){ftui.toast("Disconnected from FHEM"),ftui.config.doLongPoll&&(ftui.toast("Retry to connect in 10 seconds"),setTimeout(function(){ftui.longPoll()},1e4))},getDeviceParameter:function(t,e){if(t&&t.length>0){var i=ftui.deviceStates[t];return i&&i[e]?i[e]:null}return null},loadPlugin:function(t,e){var i=new $.Deferred;return ftui.log(2,"Create widget : "+t),ftui.dynamicload(ftui.config.dir+"/widget_"+t+".js",!0).done(function(){var n=[],a=window["depends_"+t];if($.isFunction(a)){var r=a();r&&(r=$.isArray(r)?r:[r],$.map(r,function(t,e){t.indexOf(".js")<0?n.push(ftui.loadPlugin(t)):n.push(ftui.dynamicload(ftui.config.dir+"/../"+t,!1))}))}else ftui.log(2,"function depends_"+t+" not found (maybe ok)");$.when.apply(this,n).always(function(){var n=window["Modul_"+t]?new window["Modul_"+t]:null;if(n){if("undefined"!=typeof e){plugins.addModule(n),ftui.isValid(e)&&(n.area=e),ftui.log(1,"Try to init plugin: "+t),n.init();for(var a in n.subscriptions)n.update(n.subscriptions[a].device,n.subscriptions[a].reading)}ftui.log(1,"Loaded plugin: "+t)}else ftui.log(1,"Failed to create widget: "+t);i.resolve()})}).fail(function(){ftui.toast("Failed to load plugin : "+t),ftui.log(1,"Failed to load plugin : "+t+' - add do your page, to see more informations about this failure'),i.resolve()}),i.promise()},dynamicload:function(t,e){ftui.config.DEBUG?!1:!0;ftui.log(3,"dynamic load file:"+t+" / async:"+e);var n=new $.Deferred,a=document.createElement("script");return a.type="text/javascript",a.async=e?!0:!1,a.src=t,a.onload=function(){ftui.log(3,"dynamic load done:"+t),n.resolve()},document.getElementsByTagName("head")[0].appendChild(a),n.promise()},healthCheck:function(){var t=new Date;t.setTime(1e3*ftui.states.lastShortpoll),console.log("--------- start healthCheck --------------"),console.log("now:",new Date),console.log("FTUI version: "+ftui.version),console.log("Longpoll: "+ftui.config.doLongPoll),console.log("Longpoll objects there: "+(ftui.isValid(ftui.longPollRequest)&&ftui.isValid(ftui.xhr))),console.log("Longpoll curent line: "+ftui.poll.currLine),console.log("Longpoll last event before: "+ftui.poll.timestamp.toDate().ago()),console.log("Shortpoll interval: "+ftui.config.shortpollInterval),console.log("Shortpoll last run before: "+t.ago()),console.log("FHEM dev/par count: "+Object.keys(ftui.paramIdMap).length),console.log("FTUI known devices count: "+Object.keys(ftui.deviceStates).length),console.log("Page length: "+$("html").html().length),console.log("Widgets count: "+$("[data-type]").length),console.log("--------- end healthCheck ---------------")},FS20:{dimmerArray:[0,6,12,18,25,31,37,43,50,56,62,68,75,81,87,93,100],dimmerValue:function(t){var e=ftui.indexOfNumeric(this.dimmerArray,t);return e>-1?this.dimmerArray[e]:0}},rgbToHsl:function(t){var e=parseInt(t.substring(0,2),16),i=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16);e/=255,i/=255,n/=255;var o,s,a=Math.max(e,i,n),r=Math.min(e,i,n),l=(a+r)/2;if(a==r)o=s=0;else{var u=a-r;switch(s=l>.5?u/(2-a-r):u/(a+r),a){case e:o=(i-n)/u+(n>i?6:0);break;case i:o=(n-e)/u+2;break;case n:o=(e-i)/u+4}o/=6}return[o,s,l]},hslToRgb:function(t,e,i){var n,a,r,s,o=function(t){return("0"+parseInt(t).toString(16)).slice(-2)};if(0===e)n=a=r=i;else{s=function(t,e,i){return 0>i&&(i+=1),i>1&&(i-=1),1/6>i?t+6*(e-t)*i:.5>i?e:2/3>i?t+(e-t)*(2/3-i)*6:t};var l=.5>i?i*(1+e):i+e-i*e,u=2*i-l;n=s(u,l,t+1/3),a=s(u,l,t),r=s(u,l,t-1/3)}return[o(Math.round(255*n)),o(Math.round(255*a)),o(Math.round(255*r))].join("")},rgbToHex:function(t){var e=t.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);return e&&4===e.length?"#"+("0"+parseInt(e[1],10).toString(16)).slice(-2)+("0"+parseInt(e[2],10).toString(16)).slice(-2)+("0"+parseInt(e[3],10).toString(16)).slice(-2):t},getGradientColor:function(t,e,i){t=this.rgbToHex(t).replace(/^\s*#|\s*$/g,""),e=this.rgbToHex(e).replace(/^\s*#|\s*$/g,""),3==t.length&&(t=t.replace(/(.)/g,"$1$1")),3==e.length&&(e=e.replace(/(.)/g,"$1$1"));var n=parseInt(t.substr(0,2),16),a=parseInt(t.substr(2,2),16),r=parseInt(t.substr(4,2),16),o=parseInt(e.substr(0,2),16),s=parseInt(e.substr(2,2),16),l=parseInt(e.substr(4,2),16),u=o-n,f=s-a,d=l-r;return u=(u*i+n).toString(16).split(".")[0],f=(f*i+a).toString(16).split(".")[0],d=(d*i+r).toString(16).split(".")[0],1==u.length&&(u="0"+u),1==f.length&&(f="0"+f),1==d.length&&(d="0"+d),"#"+u+f+d},getPart:function(t,e){if(ftui.isValid(e)){if($.isNumeric(e)){var i=ftui.isValid(t)?t.toString().split(" "):"";return i.length>=e&&e>0?i[e-1]:t}var n="";if(ftui.isValid(t)){var a=t.match(new RegExp("^"+e+"$"));if(a)for(var r=1,o=a.length;o>r;r++)n+=a[r]}return n}return t},showModal:function(t){t?$("#shade").fadeIn():$("#shade").fadeOut()},precision:function(t){var e=t+"",i=e.indexOf(".")+1;return i?e.length-i:0},indexOfGeneric:function(t,e){if(!t)return-1;for(var i=0,n=t.length;n>i;i++)if(!$.isNumeric(t[i]))return ftui.indexOfRegex(t,e);return ftui.indexOfNumeric(t,e)},indexOfNumeric:function(t,e){for(var i=-1,n=0,a=t.length;a>n;n++)Number(e)>=Number(t[n])&&(i=n);return i},indexOfRegex:function(t,e){for(var i=0,n=t.length;n>i;i++)try{var a=e.match(new RegExp("^"+t[i]+"$"));if(a)return i}catch(r){}return t.indexOf(e)},isValid:function(t){return"undefined"!=typeof t&&"undefined"!==t&&typeof t!=typeof notusedvar},dateFromString:function(t){var e=t.match(/(\d+)-(\d+)-(\d+)[_\s](\d+):(\d+):(\d+).*/),i=t.match(/(\d\d).(\d\d).(\d\d\d\d)/),n=(new Date).getTimezoneOffset();return e?new Date(+e[1],+e[2]-1,+e[3],+e[4],+e[5],+e[6]):i?new Date(+i[3],+i[2]-1,+i[1],0,-n,0,0):new Date},diffMinutes:function(t,e){var i=new Date(e-t);return(i/1e3/60).toFixed(0)},diffSeconds:function(t,e){var i=new Date(e-t);return(i/1e3).toFixed(1)},durationFromSeconds:function(t){var e=Math.floor(t/3600),i=Math.floor(t%3600/60),n=t%60,a="";return e>0&&(a+=""+e+":"+(10>i?"0":"")),a+=""+i+":"+(10>n?"0":""),a+=""+n},mapColor:function(t){return ftui.getStyle("."+t,"color")||t},parseJsonFromString:function(t){return JSON.parse(t)},getAndroidVersion:function(t){t=(t||navigator.userAgent).toLowerCase();var e=t.match(/android\s([0-9\.]*)/);return e?e[1]:!1},getStyle:function(t,e){var i=ftui.config.styleCollection[t];return i&&i[e]?i[e]:null},getClassColor:function(t){for(var e=0,i=ftui.config.stdColors.length;i>e;e++)if(t.hasClass(ftui.config.stdColors[e]))return ftui.getStyle("."+ftui.config.stdColors[e],"color");return null},getIconId:function(t){if(!t||""===t)return"?";var e=$('link[href$="font-awesome.min.css"]')[0].sheet.cssRules;for(var i in e)if(e[i].selectorText&&e[i].selectorText.match(new RegExp(t+":"))){var n=e[i].style.content;return n?(n=n.replace(/"/g,"").replace(/'/g,""),/[^\u0000-\u00ff]/.test(n)?n:String.fromCharCode(parseInt(n.replace("\\",""),16))):t}},toast:function(t,e){if(0!==ftui.config.TOAST){var i=ftui.config.TOAST;1==ftui.config.TOAST&&(i=!1),e&&"error"===e?f7?f7.ftui.addNotification({title:"FTUI",message:t,hold:1500}):$.toast&&$.toast({heading:"Error",text:t,hideAfter:2e4,icon:"error",loader:!1,stack:i}):f7?f7.ftui.addNotification({title:"FTUI",message:t,hold:1500}):$.toast&&$.toast({text:t,loader:!1,stack:i})}},log:function(t,e){ftui.config.debuglevel>=t&&console.log(e)}};$(document).on("ready",function(){ftui.init()}),$(".menu").on("click",function(){$(".menu").toggleClass("show")}),$(window).on("beforeunload",function(){ftui.log(5,"beforeunload"),ftui.setOffline()}),$(window).on("online offline",function(){ftui.log(5,"online offline"),navigator.onLine?ftui.setOnline():ftui.setOffline()}),window.onerror=function(t,e,i,n,a){var r=e.split("/").pop();return ftui.toast([r+":"+i,a].join("
"),"error"),!1},String.prototype.toDate=function(){return ftui.dateFromString(this)},String.prototype.parseJson=function(){return ftui.parseJsonFromString(this)},String.prototype.toMinFromSec=function(){var t=Number(this),e=Math.floor(t%60).toString(),i=Math.floor(t/=60).toString();return i+":"+(e[1]?e:"0"+e[0])},Date.prototype.addMinutes=function(t){return new Date(this.getTime()+6e4*t)},Date.prototype.ago=function(t){var e=new Date,i=e-this,n=i/1e3,a=Math.floor(n%60);n/=60;var r=Math.floor(n%60);n/=60;var o=Math.floor(n%24);n/=24;var u,s=Math.floor(n),l="de"===ftui.config.lang?["Tag(e)","Stunde(n)","Minute(n)","Sekunde(n)"]:["day(s)","hour(s)","minute(s)","second(s)"];return ftui.isValid(t)?(u=t.replace("dd",s),u=u.replace("hh",o>9?o:"0"+o),u=u.replace("mm",r>9?r:"0"+r),u=u.replace("ss",a>9?a:"0"+a),u=u.replace("h",o),u=u.replace("m",r),u=u.replace("s",a)):(u=s>0?s+" "+l[0]+" ":"",u+=o>0?o+" "+l[1]+" ":"",u+=r>0?r+" "+l[2]+" ":"",u+=a+" "+l[3]),u},Date.prototype.yyyymmdd=function(){var t=this.getFullYear().toString(),e=(this.getMonth()+1).toString(),i=this.getDate().toString();return t+"-"+(e[1]?e:"0"+e[0])+"-"+(i[1]?i:"0"+i[0])},Date.prototype.hhmm=function(){var t=this.getHours().toString(),e=this.getMinutes().toString();return(t[1]?t:"0"+t[0])+":"+(e[1]?e:"0"+e[0])},Date.prototype.hhmmss=function(){var t=this.getHours().toString(),e=this.getMinutes().toString(),i=this.getSeconds().toString();return(t[1]?t:"0"+t[0])+":"+(e[1]?e:"0"+e[0])+":"+(i[1]?i:"0"+i[0])},Date.prototype.ddmm=function(){var t=(this.getMonth()+1).toString(),e=this.getDate().toString();return(e[1]?e:"0"+e[0])+"."+(t[1]?t:"0"+t[0])+"."},Date.prototype.eeee=function(){var t=["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],e=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];return"de"===ftui.config.lang?t[this.getDay()]:e[this.getDay()]},Date.prototype.eee=function(){var t=["Son","Mon","Die","Mit","Don","Fre","Sam"],e=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];return"de"===ftui.config.lang?t[this.getDay()]:e[this.getDay()]},Date.prototype.ee=function(){var t=["So","Mo","Di","Mi","Do","Fr","Sa"],e=["Su","Mo","Tu","We","Th","Fr","Sa"];return"de"===ftui.config.lang?t[this.getDay()]:e[this.getDay()]},$.fn.once=function(t,e){return this.each(function(){$(this).off(t).on(t,e)})},$.fn.widgetId=function(){return["ftui",$(this).data("type"),$(this).data("device"),$(this).data("get")].join("_")},$.fn.filterData=function(t,e){return this.filter(function(){return $(this).data(t)==e})},$.fn.filterDeviceReading=function(t,e,i){return this.filter(function(){var n=$(this),a=String(n.data(t));return a===i&&String(n.data("device"))===e||a===e+":"+i||$.inArray(i,a)>-1&&String(n.data("device"))===e||$.inArray(e+":"+i,a)>-1})},$.fn.isValidData=function(t){return"undefined"!=typeof $(this).data(t)},$.fn.initData=function(t,e){var i=$(this);return i.data(t,i.isValidData(t)?i.data(t):e),i},$.fn.mappedColor=function(t){return ftui.getStyle("."+$(this).data(t),"color")||$(this).data(t)},$.fn.isDeviceReading=function(t){var e=$(this).data(t);return e&&!$.isNumeric(e)&&e.match(/:/)},$.fn.isExternData=function(t){var e=$(this).data(t);return e?e.match(/^[#\.\[].*/):""},$.fn.getReading=function(t,e){var i=String($(this).data("device")),n=$(this).data(t);if($.isArray(n)&&(n=n[e]),n=String(n),n&&n.match(/:/)){var a=n.split(":");i=a[0],n=a[1]}if(i&&i.length>0){var r=ftui.deviceStates[i];return r&&r[n]?r[n]:{}}return{}},$.fn.valOfData=function(t){var e=$(this).data(t);return ftui.isValid(e)?e.toString().match(/^[#\.\[].*/)?$(e).data("value"):e:""},$.fn.transmitCommand=function(){if(!$(this).hasClass("notransmit")){var t=[$(this).valOfData("cmd"),$(this).valOfData("device"),$(this).valOfData("set"),$(this).valOfData("value")].join(" ");ftui.setFhemStatus(t),ftui.toast(t)}}; \ No newline at end of file +"use strict";if("function"==typeof Framework7){var f7={ftui:new Framework7({animateNavBackIcon:!0}),options:{dynamicNavbar:!0,domCache:!0},views:[]};$(".view").each(function(t){var e=f7.ftui.addView("#"+$(this)[0].id,{dynamicNavbar:!0});f7.ftui.views.push(e)}),f7.ftui.onPageInit("*",function(t){ftui.log(t.name+" initialized"),ftui.initWidgets('[data-page="'+t.name+'"]')})}var Modul_widget=function(){function init(){ftui.log(1,"init widget: name="+me.widgetname+" area="+me.area),me.elements=$('[data-type="'+me.widgetname+'"]',me.area),me.elements.each(function(t){me.init_attr($(this)),me.init_ui($(this))})}function isReadOnly(t){var e=t.data("readonly");return"true"===e||"1"===e||"on"===e||1===e}function substitution(value,subst){if(ftui.isValid(subst))if($.isArray(subst)){for(var i=0,len=subst.length;len>i;i+=2)if(value==subst[i]&&len>i+1)return subst[i+1]}else{if(subst.match(/^s/)){var f=subst.substr(1,1),sub=subst.split(f);return value.replace(new RegExp(sub[1],sub[3]),sub[2])}if(subst.match(/weekdayshort/))return ftui.dateFromString(value).ee();if(subst.match(/.*\(\)/))return eval("value."+subst)}return value}function checkHide(t,e){if(ftui.isValid(t.data("hide"))){var i=t.data("hide");e===i||t.isDeviceReading("hide")&&("true"===e||"1"===e||"on"===e||1===e)||e.match(new RegExp("^"+i+"$"))?ftui.isValid(t.data("hideparents"))?t.parents(t.data("hideparents")).hide():t.hide():ftui.isValid(t.data("hideparents"))?t.parents(t.data("hideparents")).show():t.show()}}function fix(t,e){return $.isNumeric(t)&&e>=0?Number(t).toFixed(e):t}function map(t,e,i){if("object"==typeof t&&null!==t)for(var n in t)if(e===n||e.match(new RegExp("^"+n+"$")))return t[n];return i}function init_attr(t){}function init_ui(t){t.text(me.widgetname)}function addReading(t,e){var i=t.data(e);if(ftui.isValid(i)&&($.isArray(i)||!i.toString().match(/^[#\.\[].*/))){var n=t.data("device");$.isArray(i)||(i=new Array(i.toString()));for(var a=0,r=i.length;r>a;a++){var o=i[a];if(o.match(/:/)){var s=o.split(":");n=s[0],o=s[1]}if(ftui.isValid(n)&&ftui.isValid(o)){n=n.toString();var l="STATE"===o?n:[n,o].join("-");subscriptions[l]={},subscriptions[l].device=n,subscriptions[l].reading=o}}}}function update(t,e){ftui.log(1,"warning: "+me.widgetname+" does not implement update function")}var subscriptions={},elements,me={widgetname:"widget",area:"",isReadOnly:isReadOnly,init:init,init_attr:init_attr,init_ui:init_ui,update:update,substitution:substitution,checkHide:checkHide,fix:fix,map:map,addReading:addReading,subscriptions:subscriptions,elements:elements};return me},plugins={modules:[],addModule:function(t){this.modules.push(t)},removeArea:function(t){for(var e=this.modules.length-1;e>=0;e-=1)this.modules[e].area===t&&this.modules.splice(e,1)},updateParameters:function(){ftui.subscriptions={},ftui.subscriptionTs={},ftui.devs=[];for(var t=this.modules.length-1;t>=0;t-=1){var e=this.modules[t];for(var i in e.subscriptions){ftui.subscriptions[i]=e.subscriptions[i],ftui.subscriptionTs[i+"-ts"]=e.subscriptions[i];var n=ftui.subscriptions[i].device;ftui.devs.indexOf(n)<0&&ftui.devs.push(n)}}ftui.states.lastShortpoll=0},load:function(t,e){return ftui.log(1,"Load widget : "+t),ftui.loadPlugin(t,e)},update:function(t,e){$.each(this.modules,function(i,n){"object"==typeof n&&n.update(t,e)}),ftui.log(1,'update done for "'+t+":"+e+'"')}},ftui={version:"2.4.3",config:{DEBUG:!1,DEMO:!1,dir:"",filename:"",fhem_dir:"",debuglevel:0,doLongPoll:!1,lang:"de",shortpollInterval:0,styleCollection:{},stdColors:["green","orange","red","ligthblue","blue","gray","white","mint"]},poll:{currLine:0,xhr:null,longPollRequest:null,shortPollTimer:null,longPollTimer:null,timestamp:"01.01.1970"},states:{lastSetOnline:0,lastShortpoll:0,longPollRestart:!1},deviceStates:{},paramIdMap:{},timestampMap:{},subscriptions:{},subscriptionTs:{},gridster:{instances:{},instance:null,wx:0,wy:0,wm:5,mincols:0},init:function(){ftui.paramIdMap={},ftui.timestampMap={},ftui.loadStyleSchema(),ftui.gridster.wx=parseInt($("meta[name='widget_base_width']").attr("content")||74),ftui.gridster.wy=parseInt($("meta[name='widget_base_height']").attr("content")||71),ftui.gridster.mincols=parseInt($("meta[name='widget_min_cols']").attr("content")||$(window).width()/ftui.gridster.wx),$("meta[name='widget_margin']").attr("content")&&(ftui.gridster.wm=parseInt($("meta[name='widget_margin']").attr("content"))),ftui.config.doLongPoll="1"==$("meta[name='longpoll']").attr("content"),ftui.config.longPollFilter=$("meta[name='longpoll_filter']").attr("content")||".*",ftui.config.DEMO="1"==$("meta[name='demo']").attr("content"),ftui.config.debuglevel=$("meta[name='debug']").attr("content")||0,ftui.config.DEBUG=ftui.config.debuglevel>0,ftui.config.TOAST=$("meta[name='toast']").attr("content")||5,ftui.config.shortpollInterval=$("meta[name='shortpoll-only-interval']").attr("content")||30,ftui.config.dir=$('script[src*="fhem-tablet-ui"]').attr("src");var t=ftui.config.dir.split("/").pop();ftui.config.dir=ftui.config.dir.replace("/"+t,""),ftui.log(1,"Plugin dir: "+ftui.config.dir);var e=window.location.pathname;ftui.config.filename=e.substring(e.lastIndexOf("/")+1),ftui.log(1,"Filename: "+ftui.config.filename),ftui.config.fhem_dir=$("meta[name='fhemweb_url']").attr("content")||"/fhem/",ftui.log(1,"FHEM dir: "+ftui.config.fhem_dir);var i=navigator.language||navigator.userLanguage;ftui.config.lang=ftui.isValid(i)?i.split("-")[0]:"de";try{localStorage.setItem("ftui",ftui.version),localStorage.removeItem("ftui")}catch(n){ftui.toast("You are in Privacy Mode
Please deactivate Privacy Mode and then reload the page.","error")}$("
").prependTo("body").hide();var a=ftui.getAndroidVersion(),r=a&&parseFloat(a)<5,o=r?"touchstart":"touchstart mousedown";$("#shade").on(o,function(t){$(document).trigger("shadeClicked")}),ftui.readStatesLocal(),ftui.initPage(),$(document).on("initWidgetsDone",function(){ftui.startShortPollInterval(500)}),$(document).one("updateDone",function(){ftui.log(2,"document triggered updateDone"),ftui.initLongpoll()}),f7||$("*:not(select):not(textarea)").focus(function(){$(this).blur()}),ftui.config.debuglevel>0&&setInterval(function(){ftui.healthCheck()},6e4)},initGridster:function(t){if($.fn.gridster){ftui.gridster.instances[t]&&ftui.gridster.instances[t].destroy(),ftui.gridster.instances[t]=$(".gridster > ul",t).gridster({widget_base_dimensions:[ftui.gridster.wx,ftui.gridster.wy],widget_margins:[ftui.gridster.wm,ftui.gridster.wm],draggable:{handle:".gridster li > header"},min_cols:parseInt(ftui.gridster.mincols)}).data("gridster"),ftui.gridster.instances[t]&&("1"==$("meta[name='gridster_disable']").attr("content")&&ftui.gridster.instances[t].disable(),"1"==$("meta[name='gridster_starthidden']").attr("content")&&$(".gridster").hide());var e=$(".gridster > ul > li:has(* .gridster)");e.length>0&&e.css({"background-color":"transparent",margin:"-"+ftui.gridster.wm+"px",width:e.parent().width()-e.position().left,height:"100%"}),$(".gridster > ul > li:has(.center)").addClass("vbox"),$(".gridster > ul > li:has(.vbox)").addClass("vbox"),$(".gridster > ul > li > .hbox").addClass("center"),$(".gridster > ul > li > .vbox").addClass("center"),$(".gridster li > header ~ .hbox:only-of-type").each(function(t){$(this).css({height:"calc(100% - "+$(this).siblings("header").outerHeight()+"px)"})})}},initPage:function(t){t=ftui.isValid(t)?t:"",console.time("initPage"),ftui.log(2,"initPage - area="+t),ftui.initGridster(t);var e=$("[data-template]",t).length;ftui.log(2,"count of templates:",e),e>0?$("[data-template]",t).each(function(i){var n=$(this);$.get(n.data("template"),{},function(a){var r=n.data("parameter");for(var o in r)a=a.replace(new RegExp(o,"g"),r[o]);n.html(a),i===e-1&&ftui.initWidgets(t)})}):ftui.initWidgets(t)},initWidgets:function(t){t=ftui.isValid(t)?t:"";var e=[];ftui.log(3,plugins),plugins.removeArea(t),ftui.log(3,plugins),ftui.log(2,"initWidgets - area="+t),$("[data-type]",t).each(function(t){var i=$(this).data("type");e.indexOf(i)<0&&e.push(i)});var i=$.map(e,function(e,i){return plugins.load(e,t)});$.when.apply(this,i).then(function(){plugins.updateParameters(),ftui.log(1,"initWidgets - Done"),console.timeEnd("initPage"),$(document).trigger("initWidgetsDone",[t])})},initLongpoll:function(){if(ftui.log(2,"initLongpoll: "+ftui.config.doLongPoll),ftui.config.doLongPoll){var t=$("meta[name='longpoll-delay']").attr("content");t=$.isNumeric(t)?1e3*t:100,ftui.startLongPollInterval(t)}},startShortPollInterval:function(t){ftui.log(1,"start shortpoll in (ms):"+(t||1e3*ftui.config.shortpollInterval)),clearInterval(ftui.shortPollTimer),ftui.shortPollTimer=setTimeout(function(){ftui.shortPoll(),ftui.startShortPollInterval()},t||1e3*ftui.config.shortpollInterval)},startLongPollInterval:function(t){ftui.config.DEBUG&&t>999&&ftui.toast("Start Longpoll in "+t/1e3+"s"),clearInterval(ftui.longPollTimer),ftui.longPollTimer=setTimeout(function(){ftui.longPoll()},t),ftui.config.shortpollInterval=$("meta[name='shortpoll-interval']").attr("content")||900},shortPoll:function(){var t=(new Date).getTime()/1e3;if(!(t-ftui.states.lastShortpollShortPoll Request Failed, will retry in 3s
"+n,"error"),ftui.states.lastSetOnline=0,ftui.states.lastShortpoll=0,ftui.startShortPollInterval(3e3)})}},longPoll:function(){return ftui.config.DEMO?void console.log("DEMO-Mode: no longpoll"):ftui.xhr?void ftui.log(3,"valid ftui.xhr found"):ftui.longPollRequest?void ftui.log(3,"valid ftui.longPollRequest found"):(ftui.poll.currLine=0,ftui.config.DEBUG&&(ftui.states.longPollRestart?ftui.toast("Longpoll re-started"):ftui.toast("Longpoll started")),ftui.log(1,ftui.states.longPollRestart?"Longpoll re-started":"Longpoll started"),ftui.states.longPollRestart=!1,void(ftui.longPollRequest=$.ajax({url:ftui.config.fhem_dir,cache:!1,async:!0,data:{XHR:1,inform:"type=status;filter="+ftui.config.longPollFilter+";fmt=JSON"},xhr:function(){return ftui.xhr=new window.XMLHttpRequest,ftui.xhr.addEventListener("readystatechange",function(t){var e=t.target.responseText;if(4!=t.target.readyState&&3==t.target.readyState){var i=e.split(/\n/);i.pop();for(var n=ftui.poll.currLine,a=i.length;a>n;n++)if(ftui.log(5,i[n]),ftui.isValid(i[n])&&""!==i[n])try{var r=JSON.parse(i[n]),o=null,s=null,l=r[1]!==r[2];ftui.log(4,r);var u=ftui.paramIdMap[r[0]],f=ftui.timestampMap[r[0]];u&&(l&&(u.reading="STATE"),o=ftui.deviceStates[u.device]||{},s=o[u.reading]||{},s.val=r[1],s.valid=!0,o[u.reading]=s,ftui.deviceStates[u.device]=o,l&&ftui.subscriptions[r[0]]&&plugins.update(u.device,u.reading)),f&&!l&&(o=ftui.deviceStates[f.device]||{},s=o[f.reading]||{},s.date=r[1],o[f.reading]=s,ftui.poll.timestamp=s.date,ftui.deviceStates[f.device]=o,ftui.subscriptionTs[r[0]]&&plugins.update(f.device,f.reading))}catch(d){ftui.log(1,"Error: (longpoll) "+d)}ftui.poll.currLine=i.length,ftui.poll.currLine>9999&&(ftui.states.longPollRestart=!0,ftui.longPollRequest.abort())}},!1),ftui.xhr}}).done(function(t){ftui.xhr&&(ftui.xhr.abort(),ftui.xhr=null),ftui.longPollRequest=null,ftui.states.longPollRestart?ftui.longPoll():(ftui.log(1,"Disconnected from FHEM - poll done - "+t),ftui.restartLongPoll())}).fail(function(t,e,i){ftui.xhr&&(ftui.xhr.abort(),ftui.xhr=null),ftui.longPollRequest=null,ftui.states.longPollRestart?ftui.longPoll():(ftui.log(1,"Error while longpoll: "+e+": "+i),ftui.restartLongPoll())})))},setFhemStatus:function(t){return ftui.config.DEMO?void console.log("DEMO-Mode: no setFhemStatus"):(ftui.startShortPollInterval(),t=t.replace(" "," "),ftui.log(1,"send to FHEM: "+t),void $.ajax({async:!0,cache:!1,url:ftui.config.fhem_dir,data:{cmd:t,XHR:"1"}}).fail(function(t,e,i){ftui.toast("FHEM Command Failed
"+e+": "+i,"error")}).done(function(t){}))},loadStyleSchema:function(){$.each($('link[href$="-ui.css"],link[href$="-ui.min.css"]'),function(t,e){if(e&&e.sheet&&e.sheet.cssRules){var i=e.sheet.cssRules;for(var n in i)if(i[n].style){var a=i[n].style.cssText.split(";");a.pop();var r=i[n].selectorText,o={};for(var s in a){var l=a[s].toString().split(":");l[0].match(/color/)&&(o[$.trim(l[0])]=$.trim(l[1]).replace("! important","").replace("!important",""))}Object.keys(o).length>0&&(ftui.config.styleCollection[r]=o)}}})},onUpdateDone:function(){$(document).trigger("updateDone"),ftui.checkInvalidElements()},checkInvalidElements:function(){$(".autohide[data-get]").each(function(t){var e=$(this),i=e.getReading("get").valid;i&&i===!0?e.removeClass("invalid"):e.addClass("invalid")})},setOnline:function(){var t=(new Date).getTime()/1e3;t-ftui.states.lastSetOnline>60&&(ftui.config.DEBUG&&ftui.toast("Network connected"),ftui.states.lastSetOnline=t,ftui.states.lastShortpoll=0,ftui.startShortPollInterval(1e3),ftui.config.doLongPoll||(ftui.config.doLongPoll="1"==$("meta[name='longpoll']").attr("content"),ftui.config.doLongPoll&&ftui.startLongPollInterval(100)),ftui.log(1,"FTUI is online"))},setOffline:function(){ftui.config.DEBUG&&ftui.toast("Lost network connection"),ftui.config.doLongPoll=!1,clearInterval(ftui.shortPollTimer),clearInterval(ftui.longPollTimer),ftui.longPollRequest&&ftui.longPollRequest.abort(),ftui.saveStatesLocal(),ftui.log(1,"FTUI is offline")},readStatesLocal:function(){ftui.config.DEMO?$.ajax({async:!1,url:"/fhem/tablet/data/"+ftui.config.filename.replace(".html",".dat")}).done(function(t){ftui.deviceStates=JSON.parse(t)||{}}):ftui.deviceStates=JSON.parse(localStorage.getItem("deviceStates"))||{}},saveStatesLocal:function(){var t=JSON.stringify(ftui.deviceStates);localStorage.setItem("deviceStates",t),localStorage.setItem("shortPollDuration",ftui.poll.shortPollDuration)},restartLongPoll:function(){ftui.toast("Disconnected from FHEM"),ftui.config.doLongPoll&&(ftui.toast("Retry to connect in 10 seconds"),setTimeout(function(){ftui.longPoll()},1e4))},getDeviceParameter:function(t,e){if(t&&t.length>0){var i=ftui.deviceStates[t];return i&&i[e]?i[e]:null}return null},loadPlugin:function(t,e){var i=new $.Deferred;return ftui.log(2,"Create widget : "+t),ftui.dynamicload(ftui.config.dir+"/widget_"+t+".js",!0).done(function(){var n=[],a=window["depends_"+t];if($.isFunction(a)){var r=a();r&&(r=$.isArray(r)?r:[r],$.map(r,function(t,e){t.indexOf(".js")<0?n.push(ftui.loadPlugin(t)):n.push(ftui.dynamicload(ftui.config.dir+"/../"+t,!1))}))}else ftui.log(2,"function depends_"+t+" not found (maybe ok)");$.when.apply(this,n).always(function(){var n=window["Modul_"+t]?new window["Modul_"+t]:null;if(n){if("undefined"!=typeof e){plugins.addModule(n),ftui.isValid(e)&&(n.area=e),ftui.log(1,"Try to init plugin: "+t),n.init();for(var a in n.subscriptions)n.update(n.subscriptions[a].device,n.subscriptions[a].reading)}ftui.log(1,"Loaded plugin: "+t)}else ftui.log(1,"Failed to create widget: "+t);i.resolve()})}).fail(function(){ftui.toast("Failed to load plugin : "+t),ftui.log(1,"Failed to load plugin : "+t+' - add do your page, to see more informations about this failure'),i.resolve()}),i.promise()},dynamicload:function(t,e){ftui.config.DEBUG?!1:!0;ftui.log(3,"dynamic load file:"+t+" / async:"+e);var n=new $.Deferred,a=document.createElement("script");return a.type="text/javascript",a.async=e?!0:!1,a.src=t,a.onload=function(){ftui.log(3,"dynamic load done:"+t),n.resolve()},document.getElementsByTagName("head")[0].appendChild(a),n.promise()},healthCheck:function(){var t=new Date;t.setTime(1e3*ftui.states.lastShortpoll),console.log("--------- start healthCheck --------------"),console.log("now:",new Date),console.log("FTUI version: "+ftui.version),console.log("Longpoll: "+ftui.config.doLongPoll),console.log("Longpoll objects there: "+(ftui.isValid(ftui.longPollRequest)&&ftui.isValid(ftui.xhr))),console.log("Longpoll curent line: "+ftui.poll.currLine),console.log("Longpoll last event before: "+ftui.poll.timestamp.toDate().ago()),console.log("Shortpoll interval: "+ftui.config.shortpollInterval),console.log("Shortpoll last run before: "+t.ago()),console.log("FHEM dev/par count: "+Object.keys(ftui.paramIdMap).length),console.log("FTUI known devices count: "+Object.keys(ftui.deviceStates).length),console.log("Page length: "+$("html").html().length),console.log("Widgets count: "+$("[data-type]").length),console.log("--------- end healthCheck ---------------")},FS20:{dimmerArray:[0,6,12,18,25,31,37,43,50,56,62,68,75,81,87,93,100],dimmerValue:function(t){var e=ftui.indexOfNumeric(this.dimmerArray,t);return e>-1?this.dimmerArray[e]:0}},rgbToHsl:function(t){var e=parseInt(t.substring(0,2),16),i=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16);e/=255,i/=255,n/=255;var o,s,a=Math.max(e,i,n),r=Math.min(e,i,n),l=(a+r)/2;if(a==r)o=s=0;else{var u=a-r;switch(s=l>.5?u/(2-a-r):u/(a+r),a){case e:o=(i-n)/u+(n>i?6:0);break;case i:o=(n-e)/u+2;break;case n:o=(e-i)/u+4}o/=6}return[o,s,l]},hslToRgb:function(t,e,i){var n,a,r,s,o=function(t){return("0"+parseInt(t).toString(16)).slice(-2)};if(0===e)n=a=r=i;else{s=function(t,e,i){return 0>i&&(i+=1),i>1&&(i-=1),1/6>i?t+6*(e-t)*i:.5>i?e:2/3>i?t+(e-t)*(2/3-i)*6:t};var l=.5>i?i*(1+e):i+e-i*e,u=2*i-l;n=s(u,l,t+1/3),a=s(u,l,t),r=s(u,l,t-1/3)}return[o(Math.round(255*n)),o(Math.round(255*a)),o(Math.round(255*r))].join("")},rgbToHex:function(t){var e=t.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);return e&&4===e.length?"#"+("0"+parseInt(e[1],10).toString(16)).slice(-2)+("0"+parseInt(e[2],10).toString(16)).slice(-2)+("0"+parseInt(e[3],10).toString(16)).slice(-2):t},getGradientColor:function(t,e,i){t=this.rgbToHex(t).replace(/^\s*#|\s*$/g,""),e=this.rgbToHex(e).replace(/^\s*#|\s*$/g,""),3==t.length&&(t=t.replace(/(.)/g,"$1$1")),3==e.length&&(e=e.replace(/(.)/g,"$1$1"));var n=parseInt(t.substr(0,2),16),a=parseInt(t.substr(2,2),16),r=parseInt(t.substr(4,2),16),o=parseInt(e.substr(0,2),16),s=parseInt(e.substr(2,2),16),l=parseInt(e.substr(4,2),16),u=o-n,f=s-a,d=l-r;return u=(u*i+n).toString(16).split(".")[0],f=(f*i+a).toString(16).split(".")[0],d=(d*i+r).toString(16).split(".")[0],1==u.length&&(u="0"+u),1==f.length&&(f="0"+f),1==d.length&&(d="0"+d),"#"+u+f+d},getPart:function(t,e){if(ftui.isValid(e)){if($.isNumeric(e)){var i=ftui.isValid(t)?t.toString().split(" "):"";return i.length>=e&&e>0?i[e-1]:t}var n="";if(ftui.isValid(t)){var a=t.match(new RegExp("^"+e+"$"));if(a)for(var r=1,o=a.length;o>r;r++)n+=a[r]}return n}return t},showModal:function(t){t?$("#shade").fadeIn():$("#shade").fadeOut()},precision:function(t){var e=t+"",i=e.indexOf(".")+1;return i?e.length-i:0},indexOfGeneric:function(t,e){if(!t)return-1;for(var i=0,n=t.length;n>i;i++)if(!$.isNumeric(t[i]))return ftui.indexOfRegex(t,e);return ftui.indexOfNumeric(t,e)},indexOfNumeric:function(t,e){for(var i=-1,n=0,a=t.length;a>n;n++)Number(e)>=Number(t[n])&&(i=n);return i},indexOfRegex:function(t,e){for(var i=0,n=t.length;n>i;i++)try{var a=e.match(new RegExp("^"+t[i]+"$"));if(a)return i}catch(r){}return t.indexOf(e)},isValid:function(t){return"undefined"!=typeof t&&"undefined"!==t&&typeof t!=typeof notusedvar},dateFromString:function(t){var e=t.match(/(\d+)-(\d+)-(\d+)[_\s](\d+):(\d+):(\d+).*/),i=t.match(/(\d\d).(\d\d).(\d\d\d\d)/),n=(new Date).getTimezoneOffset();return e?new Date(+e[1],+e[2]-1,+e[3],+e[4],+e[5],+e[6]):i?new Date(+i[3],+i[2]-1,+i[1],0,-n,0,0):new Date},diffMinutes:function(t,e){var i=new Date(e-t);return(i/1e3/60).toFixed(0)},diffSeconds:function(t,e){var i=new Date(e-t);return(i/1e3).toFixed(1)},durationFromSeconds:function(t){var e=Math.floor(t/3600),i=Math.floor(t%3600/60),n=t%60,a="";return e>0&&(a+=""+e+":"+(10>i?"0":"")),a+=""+i+":"+(10>n?"0":""),a+=""+n},mapColor:function(t){return ftui.getStyle("."+t,"color")||t},parseJsonFromString:function(t){return JSON.parse(t)},getAndroidVersion:function(t){t=(t||navigator.userAgent).toLowerCase();var e=t.match(/android\s([0-9\.]*)/);return e?e[1]:!1},getStyle:function(t,e){var i=ftui.config.styleCollection[t];return i&&i[e]?i[e]:null},getClassColor:function(t){for(var e=0,i=ftui.config.stdColors.length;i>e;e++)if(t.hasClass(ftui.config.stdColors[e]))return ftui.getStyle("."+ftui.config.stdColors[e],"color");return null},getIconId:function(t){if(!t||""===t)return"?";var e=$('link[href$="font-awesome.min.css"]')[0].sheet.cssRules;for(var i in e)if(e[i].selectorText&&e[i].selectorText.match(new RegExp(t+":"))){var n=e[i].style.content;return n?(n=n.replace(/"/g,"").replace(/'/g,""),/[^\u0000-\u00ff]/.test(n)?n:String.fromCharCode(parseInt(n.replace("\\",""),16))):t}},toast:function(t,e){if(0!==ftui.config.TOAST){var i=ftui.config.TOAST;1==ftui.config.TOAST&&(i=!1),e&&"error"===e?f7?f7.ftui.addNotification({title:"FTUI",message:t,hold:1500}):$.toast&&$.toast({heading:"Error",text:t,hideAfter:2e4,icon:"error",loader:!1,stack:i}):f7?f7.ftui.addNotification({title:"FTUI",message:t,hold:1500}):$.toast&&$.toast({text:t,loader:!1,stack:i})}},log:function(t,e){ftui.config.debuglevel>=t&&console.log(e)}};$(document).on("ready",function(){ftui.init()}),$(".menu").on("click",function(){$(".menu").toggleClass("show")}),$(window).on("beforeunload",function(){ftui.log(5,"beforeunload"),ftui.setOffline()}),$(window).on("online offline",function(){ftui.log(5,"online offline"),navigator.onLine?ftui.setOnline():ftui.setOffline()}),window.onerror=function(t,e,i,n,a){var r=e.split("/").pop();return ftui.toast([r+":"+i,a].join("
"),"error"),!1},String.prototype.toDate=function(){return ftui.dateFromString(this)},String.prototype.parseJson=function(){return ftui.parseJsonFromString(this)},String.prototype.toMinFromSec=function(){var t=Number(this),e=Math.floor(t%60).toString(),i=Math.floor(t/=60).toString();return i+":"+(e[1]?e:"0"+e[0])},Date.prototype.addMinutes=function(t){return new Date(this.getTime()+6e4*t)},Date.prototype.ago=function(t){var e=new Date,i=e-this,n=i/1e3,a=Math.floor(n%60);n/=60;var r=Math.floor(n%60);n/=60;var o=Math.floor(n%24);n/=24;var u,s=Math.floor(n),l="de"===ftui.config.lang?["Tag(e)","Stunde(n)","Minute(n)","Sekunde(n)"]:["day(s)","hour(s)","minute(s)","second(s)"];return ftui.isValid(t)?(u=t.replace("dd",s),u=u.replace("hh",o>9?o:"0"+o),u=u.replace("mm",r>9?r:"0"+r),u=u.replace("ss",a>9?a:"0"+a),u=u.replace("h",o),u=u.replace("m",r),u=u.replace("s",a)):(u=s>0?s+" "+l[0]+" ":"",u+=o>0?o+" "+l[1]+" ":"",u+=r>0?r+" "+l[2]+" ":"",u+=a+" "+l[3]),u},Date.prototype.yyyymmdd=function(){var t=this.getFullYear().toString(),e=(this.getMonth()+1).toString(),i=this.getDate().toString();return t+"-"+(e[1]?e:"0"+e[0])+"-"+(i[1]?i:"0"+i[0])},Date.prototype.hhmm=function(){var t=this.getHours().toString(),e=this.getMinutes().toString();return(t[1]?t:"0"+t[0])+":"+(e[1]?e:"0"+e[0])},Date.prototype.hhmmss=function(){var t=this.getHours().toString(),e=this.getMinutes().toString(),i=this.getSeconds().toString();return(t[1]?t:"0"+t[0])+":"+(e[1]?e:"0"+e[0])+":"+(i[1]?i:"0"+i[0])},Date.prototype.ddmm=function(){var t=(this.getMonth()+1).toString(),e=this.getDate().toString();return(e[1]?e:"0"+e[0])+"."+(t[1]?t:"0"+t[0])+"."},Date.prototype.eeee=function(){var t=["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],e=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];return"de"===ftui.config.lang?t[this.getDay()]:e[this.getDay()]},Date.prototype.eee=function(){var t=["Son","Mon","Die","Mit","Don","Fre","Sam"],e=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];return"de"===ftui.config.lang?t[this.getDay()]:e[this.getDay()]},Date.prototype.ee=function(){var t=["So","Mo","Di","Mi","Do","Fr","Sa"],e=["Su","Mo","Tu","We","Th","Fr","Sa"];return"de"===ftui.config.lang?t[this.getDay()]:e[this.getDay()]},$.fn.once=function(t,e){return this.each(function(){$(this).off(t).on(t,e)})},$.fn.widgetId=function(){return["ftui",$(this).data("type"),$(this).data("device"),$(this).data("get")].join("_")},$.fn.filterData=function(t,e){return this.filter(function(){return $(this).data(t)==e})},$.fn.filterDeviceReading=function(t,e,i){return this.filter(function(){var n=$(this),a=String(n.data(t));return a===i&&String(n.data("device"))===e||a===e+":"+i||$.inArray(i,a)>-1&&String(n.data("device"))===e||$.inArray(e+":"+i,a)>-1})},$.fn.isValidData=function(t){return"undefined"!=typeof $(this).data(t)},$.fn.initData=function(t,e){var i=$(this);return i.data(t,i.isValidData(t)?i.data(t):e),i},$.fn.mappedColor=function(t){return ftui.getStyle("."+$(this).data(t),"color")||$(this).data(t)},$.fn.isDeviceReading=function(t){var e=$(this).data(t);return e&&!$.isNumeric(e)&&e.match(/:/)},$.fn.isExternData=function(t){var e=$(this).data(t);return e?e.match(/^[#\.\[].*/):""},$.fn.getReading=function(t,e){var i=String($(this).data("device")),n=$(this).data(t);if($.isArray(n)&&(n=n[e]),n=String(n),n&&n.match(/:/)){var a=n.split(":");i=a[0],n=a[1]}if(i&&i.length>0){var r=ftui.deviceStates[i];return r&&r[n]?r[n]:{}}return{}},$.fn.valOfData=function(t){var e=$(this).data(t);return ftui.isValid(e)?e.toString().match(/^[#\.\[].*/)?$(e).data("value"):e:""},$.fn.transmitCommand=function(){if(!$(this).hasClass("notransmit")){var t=[$(this).valOfData("cmd"),$(this).valOfData("device"),$(this).valOfData("set"),$(this).valOfData("value")].join(" ");ftui.setFhemStatus(t),ftui.toast(t)}}; \ No newline at end of file