3 lines
44 KiB
JavaScript
3 lines
44 KiB
JavaScript
"use strict";var servConn={_socket:null,_onConnChange:null,_onUpdate:null,_isConnected:!1,_disconnectedSince:null,_connCallbacks:{onConnChange:null,onUpdate:null,onRefresh:null,onAuth:null,onCommand:null,onError:null},_authInfo:null,_isAuthDone:!1,_isAuthRequired:!1,_authRunning:!1,_cmdQueue:[],_connTimer:null,_type:"socket.io",_timeout:0,_reconnectInterval:1e4,_reloadInterval:30,_cmdData:null,_cmdInstance:null,_isSecure:!1,_defaultMode:1604,_useStorage:!1,_objects:null,_enums:null,_autoSubscribe:!0,namespace:"vis.0",getType:function(){return this._type},getIsConnected:function(){return this._isConnected},getIsLoginRequired:function(){return this._isSecure},getUser:function(){return this._user},setReloadTimeout:function(e){this._reloadInterval=parseInt(e,10)},setReconnectInterval:function(e){this._reconnectInterval=parseInt(e,10)},_checkConnection:function(e,t){return this._isConnected?!this._queueCmdIfRequired(e,t)&&(null!==this._socket||(console.log("socket.io not initialized"),!1)):(console.log("No connection!"),!1)},_monitor:function(){if(!this._timer){var e=(new Date).getTime();this._reloadInterval&&e-this._lastTimer>1e3*this._reloadInterval?this.reload():this._lastTimer=e;var t=this;this._timer=setTimeout(function(){t._timer=null,t._monitor()},1e4)}},_onAuth:function(e,t){var n=this;this._isSecure=t,this._isSecure&&(n._lastTimer=(new Date).getTime(),this._monitor()),this._autoSubscribe&&this._socket.emit("subscribe","*"),e&&this._socket.emit("subscribeObjects","*"),!0!==this._isConnected&&(this._isConnected=!0,this._connCallbacks.onConnChange&&setTimeout(function(){n._socket.emit("authEnabled",function(e,t){n._user=t,n._connCallbacks.onConnChange(n._isConnected),"undefined"!=typeof app&&app.onConnChange(n._isConnected)})},0))},reconnect:function(e){var t=this;e.mayReconnect&&!e.mayReconnect()||this._connectInterval||(this._connectInterval=setInterval(function(){console.log("Trying connect..."),t._socket.connect(),t._countDown=Math.floor(t._reconnectInterval/1e3),"undefined"!=typeof $&&$(".splash-screen-text").html(t._countDown+"...").css("color","red")},this._reconnectInterval),this._countDown=Math.floor(this._reconnectInterval/1e3),"undefined"!=typeof $&&$(".splash-screen-text").html(this._countDown+"..."),this._countInterval=setInterval(function(){t._countDown--,"undefined"!=typeof $&&$(".splash-screen-text").html(t._countDown+"...")},1e3))},reload:function(){"yunkong2.net"===window.location.host||"yunkong2.biz"===window.location.host?window.location="/":window.location.reload()},init:function(n,t,i,e){var r=this;if("undefined"!=typeof socketNamespace&&(this.namespace=socketNamespace),(n=n||{}).name||(n.name=this.namespace),void 0!==e&&(this._autoSubscribe=e),(document.URL.split("/local/")[1]||"undefined"==typeof socketUrl&&!n.connLink||"undefined"!=typeof socketUrl&&"local"===socketUrl)&&(this._type="local"),"undefined"!=typeof session){var o=session.get("user");o&&(r._authInfo={user:o,hash:session.get("hash"),salt:session.get("salt")})}this._connCallbacks=t;var a=n.connLink||window.localStorage.getItem("connLink");if(a||"undefined"==typeof socketUrl||(a=socketUrl),n.socketSession||"undefined"==typeof socketSession||(n.socketSession=socketSession),void 0===n.socketForceWebSockets&&"undefined"!=typeof socketForceWebSockets&&(n.socketForceWebSockets=socketForceWebSockets),"local"===this._type)this._isConnected=!0,this._connCallbacks.onConnChange&&this._connCallbacks.onConnChange(this._isConnected),"undefined"!=typeof app&&app.onConnChange(this._isConnected);else if("undefined"!=typeof io){var s;if(n.socketSession=n.socketSession||"nokey",a?void 0!==(s=a)&&":"===a[0]&&(a=location.protocol+"//"+location.hostname+a):s=location.protocol+"//"+location.host,this._socket)try{this._socket.close(),this._socket=null}catch(e){console.log("Cannot close connection: "+e)}this._socket=io.connect(s,{query:"key="+n.socketSession,"reconnection limit":1e4,"max reconnection attempts":1/0,reconnection:!1,upgrade:!n.socketForceWebSockets,rememberUpgrade:n.socketForceWebSockets,transports:n.socketForceWebSockets?["websocket"]:void 0}),this._socket.on("connect",function(){if(r._disconnectedSince){var e=(new Date).getTime()-r._disconnectedSince;console.log("was offline for "+e/1e3+"s"),r._reloadInterval&&e>1e3*r._reloadInterval&&!r.authError&&r.reload(),r._disconnectedSince=null}r._connectInterval&&(clearInterval(r._connectInterval),r._connectInterval=null),r._countInterval&&(clearInterval(r._countInterval),r._countInterval=null);var t=document.getElementById("server-disconnect");t&&(t.style.display="none"),r._socket.emit("name",n.name),console.log((new Date).toISOString()+" Connected => authenticate"),setTimeout(function(){r.waitConnect=setTimeout(function(){console.error("No answer from server"),r.authError||r.reload()},6e3),r._socket.emit("authenticate",function(e,t){r.waitConnect&&(clearTimeout(r.waitConnect),r.waitConnect=null),console.log((new Date).toISOString()+" Authenticated: "+e),e?r._onAuth(i,t):console.log("permissionError")})},50)}),this._socket.on("reauthenticate",function(e){r._connCallbacks.onConnChange&&(r._connCallbacks.onConnChange(!1),"undefined"==typeof app||r.authError||app.onConnChange(!1)),console.warn("reauthenticate"),r.waitConnect&&(clearTimeout(r.waitConnect),r.waitConnect=null),t.onAuthError?r.authError||(r.authError=!0,t.onAuthError(e)):r.reload()}),this._socket.on("connect_error",function(){"undefined"!=typeof $&&$(".splash-screen-text").css("color","#002951"),r.reconnect(n)}),this._socket.on("disconnect",function(){if(r._disconnectedSince=(new Date).getTime(),r._isConnected=!1,r._connCallbacks.onConnChange)setTimeout(function(){var e=document.getElementById("server-disconnect");e&&(e.style.display=""),r._connCallbacks.onConnChange(r._isConnected),"undefined"!=typeof app&&app.onConnChange(r._isConnected)},5e3);else{var e=document.getElementById("server-disconnect");e&&(e.style.display="")}r.reconnect(n)}),this._socket.on("reconnect",function(){var e=(new Date).getTime()-r._disconnectedSince;console.log("was offline for "+e/1e3+"s"),r._reloadInterval&&e>1e3*r._reloadInterval&&r.reload()}),this._socket.on("objectChange",function(e,t){if(r._useStorage&&"undefined"!=typeof storage){var n=r._objects||storage.get("objects");n&&(t?n[e]=t:n[e]&&delete n[e],storage.set("objects",n))}r._connCallbacks.onObjectChange&&r._connCallbacks.onObjectChange(e,t)}),this._socket.on("stateChange",function(e,t){if(e&&null!==t&&"object"==typeof t)if(r._connCallbacks.onCommand&&e===r.namespace+".control.command"){if(t.ack)return;if(t.val&&"string"==typeof t.val&&"{"===t.val[0]&&"}"===t.val[t.val.length-1])try{t.val=JSON.parse(t.val)}catch(e){console.log("Command seems to be an object, but cannot parse it: "+t.val)}t.val&&t.val.instance?r._connCallbacks.onCommand(t.val.instance,t.val.command,t.val.data)&&r.setState(e,{val:"",ack:!0}):r._connCallbacks.onCommand(r._cmdInstance,t.val,r._cmdData)&&r.setState(e,{val:"",ack:!0})}else e===r.namespace+".control.data"?r._cmdData=t.val:e===r.namespace+".control.instance"?r._cmdInstance=t.val:r._connCallbacks.onUpdate&&r._connCallbacks.onUpdate(e,t)}),this._socket.on("permissionError",function(e){r._connCallbacks.onError?r._connCallbacks.onError(e):console.log("permissionError")}),this._socket.on("error",function(e){"Invalid password or user name"===e?(console.warn("reauthenticate"),r.waitConnect&&(clearTimeout(r.waitConnect),r.waitConnect=null),t.onAuthError?r.authError||(r.authError=!0,t.onAuthError(e)):r.reload()):(console.error("Socket error: "+e),"undefined"!=typeof $&&$(".splash-screen-text").css("color","#002951"),r.reconnect(n))})}},logout:function(e){this._isConnected?this._socket.emit("logout",e):console.log("No connection!")},getVersion:function(t){this._checkConnection("getVersion",arguments)&&this._socket.emit("getVersion",function(e){t&&t(e)})},subscribe:function(e,t){this._checkConnection("subscribe",arguments)&&this._socket.emit("subscribe",e,t)},unsubscribe:function(e,t){this._checkConnection("unsubscribe",arguments)&&this._socket.emit("unsubscribe",e,t)},_checkAuth:function(t){this._isConnected?null!==this._socket?this._socket.emit("getVersion",function(e){t&&t(e)}):console.log("socket.io not initialized"):console.log("No connection!")},readFile:function(i,r,e){if(!r)throw"No callback set";if("local"===this._type)try{var t=storage.get(i);r(null,t?JSON.parse(storage.get(i)):null)}catch(e){r(e,null)}else{if(!this._checkConnection("readFile",arguments))return;if(e||"undefined"==typeof app){var n=this.namespace;if("/"===i[0]){var o=i.split("/");n=o[1],o.splice(0,2),i=o.join("/")}this._socket.emit("readFile",n,i,function(e,t,n){setTimeout(function(){r(e,t,i,n)},0)})}else app.readLocalFile(i.replace(/^\/vis\.0\//,""),r)}},getMimeType:function(e){return-1!==e.indexOf(".")&&(e=e.toLowerCase().match(/\.[^.]+$/)),".css"===e?"text/css":".bmp"===e?"image/bmp":".png"===e?"image/png":".jpg"===e?"image/jpeg":".jpeg"===e?"image/jpeg":".gif"===e?"image/gif":".tif"===e?"image/tiff":".js"===e?"application/javascript":".html"===e?"text/html":".htm"===e?"text/html":".json"===e?"application/json":".xml"===e?"text/xml":".svg"===e?"image/svg+xml":".eot"===e?"application/vnd.ms-fontobject":".ttf"===e?"application/font-sfnt":".woff"===e?"application/font-woff":".wav"===e?"audio/wav":".mp3"===e?"audio/mpeg3":"text/javascript"},readFile64:function(i,r,e){var o=this;if(!r)throw"No callback set";if(this._checkConnection("readFile",arguments))if(e||"undefined"==typeof app){var t=this.namespace;if("/"===i[0]){var n=i.split("/");t=n[1],n.splice(0,2),i=n.join("/")}this._socket.emit("readFile64",t,i,function(e,t,n){setTimeout(function(){r(e,t?{mime:n||o.getMimeType(i),data:t}:{mime:n||o.getMimeType(i)},i)},0)})}else app.readLocalFile(i.replace(/^\/vis\.0\//,""),function(e,t,n){setTimeout(function(){t?r(e,{mime:n||o.getMimeType(i),data:btoa(t)},i):r(e,i)},0)})},writeFile:function(e,t,n,i){if("function"==typeof n&&(i=n,n=null),"local"===this._type)storage.set(e,JSON.stringify(t)),i&&i();else{if(!this._checkConnection("writeFile",arguments))return;"object"==typeof t&&(t=JSON.stringify(t,null,2));var r=e.split("/"),o=r[1];r.splice(0,2),"vis"===o?this._socket.emit("writeFile",o,r.join("/"),t,n?{mode:this._defaultMode}:{},i):this._socket.emit("writeFile",this.namespace,e,t,n?{mode:this._defaultMode}:{},i)}},writeFile64:function(e,t,n){if(this._checkConnection("writeFile64",arguments)){var i=e.split("/"),r=i[1];i.splice(0,2),this._socket.emit("writeFile",r,i.join("/"),atob(t),{mode:this._defaultMode},n)}},readDir:function(e,n){if(null!==this._socket){e||(e="/");var t=e.split("/"),i=t[1];t.splice(0,2),this._socket.emit("readDir",i,t.join("/"),{filter:!0},function(e,t){n&&n(e,t)})}else console.log("socket.io not initialized")},mkdir:function(e,t){var n=e.split("/"),i=n[1];n.splice(0,2),this._socket.emit("mkdir",i,n.join("/"),function(e){t&&t(e)})},unlink:function(e,t){var n=e.split("/"),i=n[1];n.splice(0,2),this._socket.emit("unlink",i,n.join("/"),function(e){t&&t(e)})},renameFile:function(e,t,n){var i=e.split("/"),r=i[1];i.splice(0,2);var o=t.split("/");o.splice(0,2),this._socket.emit("rename",r,i.join("/"),o.join("/"),function(e){n&&n(e)})},setState:function(e,t,n){null!==this._socket&&this._socket.emit("setState",e,t,n)},getStates:function(e,n){if("function"==typeof e&&(n=e,e=null),"local"===this._type)return n(null,[]);if(this._checkConnection("getStates",arguments)){this.gettingStates=this.gettingStates||0,this.gettingStates++,1<this.gettingStates&&(console.log("Trying to get empty list, because the whole list could not be loaded"),e=[]);var i=this;this._socket.emit("getStates",e,function(e,t){i.gettingStates--,e||!t?n&&n(e||"Authentication required"):n&&n(null,t)})}},_fillChildren:function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);t.sort();for(var i=0;i<t.length;i++)if(e[t[i]].common){for(var r=i+1,o=[],a=t[i].length+1,s=t[i]+".";r<t.length&&t[r].substring(0,a)===s;)o.push(t[r++]);e[t[i]].children=o}},getObjects:function(e,o){if("function"==typeof e&&(o=e,e=!1),this._useStorage&&e)if("undefined"!=typeof storage){var t=this._objects||storage.get("objects");if(t)return o(null,t)}else if(this._objects)return o(null,this._objects);if(this._checkConnection("getObjects",arguments)){var a=this;this._socket.emit("getObjects",function(e,r){a._socket.emit("getObjectView","system","enum",{startkey:"enum.",endkey:"enum.香"},function(e,t){if(e)o(e);else{for(var i={},n=0;n<t.rows.length;n++)r[t.rows[n].id]=t.rows[n].value,i[t.rows[n].id]=t.rows[n].value;a._socket.emit("getObjectView","system","instance",{startkey:"system.adapter.",endkey:"system.adapter.香"},function(e,t){if(e)o(e);else{for(var n=0;n<t.rows.length;n++)r[t.rows[n].id]=t.rows[n].value;r["system.adapter."+a.namespace]&&r["system.adapter."+a.namespace].native&&r["system.adapter."+a.namespace].native.defaultFileMode&&(a._defaultMode=r["system.adapter."+a.namespace].native.defaultFileMode),a._socket.emit("getObjectView","system","channel",{startkey:"",endkey:"香"},function(e,t){if(e)o(e);else{for(var n=0;n<t.rows.length;n++)r[t.rows[n].id]=t.rows[n].value;a._socket.emit("getObjectView","system","device",{startkey:"",endkey:"香"},function(e,t){if(e)o(e);else{for(var n=0;n<t.rows.length;n++)r[t.rows[n].id]=t.rows[n].value;a._useStorage&&(a._fillChildren(r),a._objects=r,a._enums=i,"undefined"!=typeof storage&&(storage.set("objects",r),storage.set("enums",i),storage.set("timeSync",(new Date).getTime()))),o&&o(e,r)}})}})}})}})})}},getChildren:function(f,e,g){if(this._checkConnection("getChildren",arguments)){if("function"==typeof f&&(g=f,f=null,e=!1),"boolean"==typeof f&&(g=e,e=f,f=null),"function"==typeof e&&(g=e,e=!1),!f)return g("getChildren: no id given");var b=this,y=[];if(this._useStorage&&e)if("undefined"!=typeof storage){var t=storage.get("objects");if(t&&t[f]&&t[f].children)return g(null,t[f].children)}else if(this._objects&&this._objects[f]&&this._objects[f].children)return g(null,this._objects[f].children);b._socket.emit("getObjectView","system","device",{startkey:f+".",endkey:f+".香"},function(e,t){if(e)g(e);else{for(var n=0;n<t.rows.length;n++)y[t.rows[n].id]=t.rows[n].value;b._socket.emit("getObjectView","system","channel",{startkey:f+".",endkey:f+".香"},function(e,t){if(e)g(e);else{for(var n=0;n<t.rows.length;n++)y[t.rows[n].id]=t.rows[n].value;b._socket.emit("getObjectView","system","state",{startkey:f+".",endkey:f+".香"},function(e,t){if(e)g(e);else{for(var n=0;n<t.rows.length;n++)y[t.rows[n].id]=t.rows[n].value;var i=[],r=f.split(".").length;for(var o in y){r+1===o.split(".").length&&i.push(o)}if(i.sort(),b._useStorage&&"undefined"!=typeof storage){var a=storage.get("objects")||{};for(var s in y)a[s]=y[s];a[f]&&a[f].common&&(a[f].children=i);var c=[];for(var l in y)c.push(l);c.sort();for(var u=0;u<c.length;u++)if(a[c[u]].common){for(var d=u+1,m=[],h=c[u].length+1,p=c[u]+".";d<c.length&&c[d].substring(0,h)===p;)m.push(c[d++]);a[c[u]].children=m}storage.set("objects",a)}g&&g(e,i)}})}})}})}},getObject:function(i,e,r){if("function"==typeof i&&(r=i,i=null,e=!1),"boolean"==typeof i&&(r=e,e=i,i=null),"function"==typeof e&&(r=e,e=!1),!i)return r("no id given");if(this._useStorage&&e&&"undefined"!=typeof storage)if("undefined"!=typeof storage){var t=this._objects||storage.get("objects");if(t&&t[i])return r(null,t[i])}else if(this._enums)return r(null,this._enums);var o=this;this._socket.emit("getObject",i,function(e,t){if(!e){if(o._useStorage&&"undefined"!=typeof storage){var n=storage.get("objects")||{};n[i]=t,storage.set("objects",n)}return r(null,t)}r(e)})},getGroups:function(e,t,o){if("function"==typeof e&&(o=e,e=null,t=!1),"boolean"==typeof e&&(o=t,t=e,e=null),"function"==typeof t&&(o=t,t=!1),e=e||"",this._useStorage&&t)if("undefined"!=typeof storage){var n=this._groups||storage.get("groups");if(n)return o(null,n)}else if(this._groups)return o(null,this._groups);if("local"===this._type)return o(null,[]);var a=this;this._socket.emit("getObjectView","system","group",{startkey:"system.group."+e,endkey:"system.group."+e+"香"},function(e,t){if(e)o(e);else{for(var n={},i=0;i<t.rows.length;i++){var r=t.rows[i].value;n[r._id]=r}a._useStorage&&(a._groups=n,"undefined"!=typeof storage&&storage.set("groups",n)),o(null,n)}})},getEnums:function(e,t,o){if("function"==typeof e&&(o=e,e=null,t=!1),"boolean"==typeof e&&(o=t,t=e,e=null),"function"==typeof t&&(o=t,t=!1),this._useStorage&&t)if("undefined"!=typeof storage){var n=this._enums||storage.get("enums");if(n)return o(null,n)}else if(this._enums)return o(null,this._enums);if("local"===this._type)return o(null,[]);e=e?e+".":"";var a=this;this._socket.emit("getObjectView","system","enum",{startkey:"enum."+e,endkey:"enum."+e+"香"},function(e,t){if(e)o(e);else{for(var n={},i=0;i<t.rows.length;i++){var r=t.rows[i].value;n[r._id]=r}a._useStorage&&"undefined"!=typeof storage&&storage.set("enums",n),o(null,n)}})},getSyncTime:function(){if(this._useStorage&&"undefined"!=typeof storage){var e=storage.get("timeSync");if(e)return new Date(e)}return null},addObject:function(e,t,n){this._isConnected?null===this._socket&&console.log("socket.io not initialized"):console.log("No connection!")},delObject:function(e){this._checkConnection("delObject",arguments)&&this._socket.emit("delObject",e)},httpGet:function(e,t){this._isConnected?null!==this._socket?this._socket.emit("httpGet",e,function(e){t&&t(e)}):console.log("socket.io not initialized"):console.log("No connection!")},logError:function(e){console.log("Error: "+e),this._isConnected&&(null!==this._socket?this._socket.emit("log","error","Addon DashUI "+e):console.log("socket.io not initialized"))},_queueCmdIfRequired:function(e,t){var r=this;return!this._isAuthDone&&(this._cmdQueue.push({func:e,args:t}),this._authRunning||(this._authRunning=!0,this._checkAuth(function(e){if(r._authRunning=!1,e){r._isAuthDone=!0;var t=r._cmdQueue;r._cmdQueue=null,r._cmdQueue=[];for(var n=0,i=t.length;n<i;n++)r[t[n].func].apply(r,t[n].args)}else r._isAuthRequired=!0})),!0)},authenticate:function(e,t,n){this._authRunning=!0,void 0!==e&&(this._authInfo={user:e,hash:t+n,salt:n}),this._isConnected?this._authInfo||console.log("No credentials!"):console.log("No connection!")},getConfig:function(e,i){if(this._checkConnection("getConfig",arguments)){if("function"==typeof e&&(i=e,e=!1),this._useStorage&&e)if("undefined"!=typeof storage){var t=storage.get("objects");if(t&&t["system.config"])return i(null,t["system.config"].common)}else if(this._objects&&this._objects["system.config"])return i(null,this._objects["system.config"].common);var r=this;this._socket.emit("getObject","system.config",function(e,t){if(i&&t&&t.common){if(r._useStorage&&"undefined"!=typeof storage){var n=storage.get("objects")||{};n["system.config"]=t,storage.set("objects",n)}i(null,t.common)}else i("Cannot read language")})}},sendCommand:function(e,t,n,i){this.setState(this.namespace+".control.instance",{val:e||"notdefined",ack:!0}),this.setState(this.namespace+".control.data",{val:n,ack:!0}),this.setState(this.namespace+".control.command",{val:t,ack:void 0===i||i})},_detectViews:function(i,r){this.readDir("/"+this.namespace+"/"+i,function(e,t){for(var n=0;n<t.length;n++)if("vis-views.json"===t[n].file&&(!t[n].acl||t[n].acl.read))return r(e,{name:i,readOnly:t[n].acl&&!t[n].acl.write,mode:t[n].acl?t[n].acl.permissions:0});r(e)})},readProjects:function(o){var a=this;this.readDir("/"+this.namespace,function(n,e){for(var i=[],r=0,t=0;t<e.length;t++)e[t].isDir&&(r++,a._detectViews(e[t].file,function(e,t){t&&i.push(t),n=n||e,--r||o(n,i)}))})},chmodProject:function(e,t,n){null!==this._socket?this._socket.emit("chmodFile",this.namespace,e+"*",{mode:t},function(e,t){n&&n(e,t)}):console.log("socket.io not initialized")},clearCache:function(){"undefined"!=typeof storage&&storage.empty()},getHistory:function(e,t,n){if(this._checkConnection("getHistory",arguments)){t||(t={}),t.timeout||(t.timeout=2e3);var i=setTimeout(function(){i=null,n("timeout")},t.timeout);this._socket.emit("getHistory",e,t,function(e,t){i&&(clearTimeout(i),i=null),n(e,t)})}},getLiveHost:function(r){var o=this;this._socket.emit("getObjectView","system","host",{startkey:"system.host.",endkey:"system.host.香"},function(e,t){for(var n=[],i=0;i<t.rows.length;i++)n.push(t.rows[i].id+".alive");n.length?o.getStates(n,function(e,t){for(var n in t)if(t.hasOwnProperty(n)&&("true"===t[n].val||!0===t[n].val))return void r(n.substring(0,n.length-".alive".length));r("")}):r("")})},readDirAsZip:function(t,n,i){if(i||(i=n,n=void 0),this._isConnected)if(null!==this._socket){t.match(/\/$/)&&(t=t.substring(0,t.length-1));var r=this;this.getLiveHost(function(e){e?r._socket.emit("sendToHost",e,"readDirAsZip",{id:r.namespace,name:t||"main",options:{settings:n}},function(e){e.error&&console.error(e.error),i&&i(e.error,e.data)}):window.alert("No active host found")})}else console.log("socket.io not initialized");else console.log("No connection!")},writeDirAsZip:function(t,n,i){if(this._isConnected)if(null!==this._socket){t.match(/\/$/)&&(t=t.substring(0,t.length-1));var r=this;this.getLiveHost(function(e){e?r._socket.emit("sendToHost",e,"writeDirAsZip",{id:r.namespace,name:t||"main",data:n},function(e){e.error&&console.error(e.error),i&&i(e.error)}):window.alert("No active host found")})}else console.log("socket.io not initialized");else console.log("No connection!")}},Types={unknown:"unknown",blind:"blind",button:"button",camera:"camera",url:"url",image:"image",dimmer:"dimmer",door:"door",fireAlarm:"fireAlarm",floodAlarm:"floodAlarm",gate:"gate",humidity:"humidity",info:"info",instance:"instance",light:"light",lock:"lock",media:"media",motion:"motion",rgb:"rgb",rgbSingle:"rgbSingle",hue:"hue",slider:"slider",socket:"socket",temperature:"temperature",thermostat:"thermostat",valve:"valve",volume:"volume",volumeGroup:"volumeGroup",window:"window",windowTilt:"windowTilt",weatherCurrent:"weatherCurrent",weatherForecast:"weatherForecast",warning:"warning"};function ChannelDetector(){if(!(this instanceof ChannelDetector))return new ChannelDetector;var e={role:/^indicator\.working$/,indicator:!0,name:"WORKING",required:!1},t={role:/^indicator(\.maintenance)?\.unreach$/,indicator:!0,type:"boolean",name:"UNREACH",required:!1},n={role:/^indicator(\.maintenance)?\.lowbat$|^indicator(\.maintenance)?\.battery/,indicator:!0,type:"boolean",name:"LOWBAT",required:!1},i={role:/^indicator\.maintenance$/,indicator:!0,type:"boolean",name:"MAINTAIN",required:!1},r={role:/^indicator\.error$/,indicator:!0,name:"ERROR",required:!1},o={role:/^indicator\.direction$/,indicator:!0,name:"DIRECTION",required:!1},_={mediaPlayer:{states:[{role:/^media.state(\..*)?$/,indicator:!1,type:["boolean","number"],name:"STATE",required:!0},{role:/^button.play(\..*)?$|^action.play(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"PLAY",required:!1,noSubscribe:!0},{role:/^button.pause(\..*)?$|^action.pause(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"PAUSE",required:!1,noSubscribe:!0},{role:/^button.stop(\..*)?$|^action.stop(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"STOP",required:!1,noSubscribe:!0},{role:/^button.next(\..*)?$|^action.next(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"NEXT",required:!1,noSubscribe:!0},{role:/^button.prev(\..*)?$|^action.prev(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"PREV",required:!1,noSubscribe:!0},{role:/^media.mode.shuffle(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"SHUFFLE",required:!1,noSubscribe:!0},{role:/^media.mode.repeat(\..*)?$/,indicator:!1,write:!0,type:"number",name:"REPEAT",required:!1,noSubscribe:!0},{role:/^media.artist(\..*)?$/,indicator:!1,write:!1,type:"string",name:"ARTIST",required:!1},{role:/^media.album(\..*)?$/,indicator:!1,write:!1,type:"string",name:"ALBUM",required:!1},{role:/^media.title(\..*)?$/,indicator:!1,write:!1,type:"string",name:"TITLE",required:!1},[{role:/^media.cover$|^media.cover.big$/,indicator:!1,write:!1,type:"string",name:"COVER",required:!1,notSingle:!0},{role:/^media.cover(\..*)$/,indicator:!1,write:!1,type:"string",name:"COVER",required:!1,notSingle:!0}],{role:/^media.duration(\..*)?$/,indicator:!1,write:!1,type:"number",name:"DURATION",required:!1,noSubscribe:!0},{role:/^media.elapsed(\..*)?$/,indicator:!1,type:"number",name:"ELAPSED",required:!1,noSubscribe:!0},{role:/^media.season(\..*)?$/,indicator:!1,write:!0,type:"number",name:"SEEK",required:!1,noSubscribe:!0},{role:/^media.seek(\..*)?$/,indicator:!1,write:!0,type:"number",name:"SEEK",required:!1,noSubscribe:!0},{role:/^media.track(\..*)?$/,indicator:!1,type:"string",name:"TRACK",required:!1,noSubscribe:!0},{role:/^media.episode(\..*)?$/,indicator:!1,type:"string",name:"EPISODE",required:!1,noSubscribe:!0},{role:/^media.season(\..*)?$/,indicator:!1,type:"string",name:"SEASON",required:!1,noSubscribe:!0},{role:/^level.volume?$/,indicator:!1,type:"number",min:"number",max:"number",write:!0,name:"VOLUME",required:!1,notSingle:!0,noSubscribe:!0},{role:/^value.volume?$/,indicator:!1,type:"number",min:"number",max:"number",write:!1,name:"VOLUME_ACTUAL",required:!1,notSingle:!0,noSubscribe:!0},{role:/^media.mute?$/,indicator:!1,type:"boolean",write:!0,name:"MUTE",required:!1,notSingle:!0,noSubscribe:!0},{stateName:/\.paused$|\.playerState$/,indicator:!1,name:"IGNORE",required:!1,multiple:!0,noSubscribe:!0},{role:/^indicator\.reachable$/,indicator:!0,type:"boolean",name:"CONNECTED",required:!1,inverted:!0},n,i,r],type:Types.media},weatherForecast:{states:[{role:/^weather.icon$|^weather.icon.forecast.0$/,indicator:!1,type:"string",name:"ICON",required:!0},{role:/^value.temperature.min.forecast.0$/,indicator:!1,type:"number",name:"TEMP_MIN",required:!0},{role:/^value.temperature.max.forecast.0$/,indicator:!1,type:"number",name:"TEMP_MAX",required:!0},{role:/^value.precipitation$|^value.precipitation.forecast.0$/,indicator:!1,type:"number",name:"PRECIPITATION_CHANCE",unit:"%",required:!1},{role:/^date$|^date.forecast.0$/,indicator:!1,type:"string",name:"DATE",required:!1},{role:/^dayofweek$|^dayofweek.forecast.0$/,indicator:!1,type:"string",name:"DOW",required:!1},{role:/^weather.state$|^weather.state.forecast.0$/,indicator:!1,type:"string",name:"STATE",required:!1},{role:/^value.temperature$|^value.temperature.forecast.0$/,indicator:!1,type:"number",name:"TEMP",required:!1},{role:/^value.pressure$/,indicator:!1,type:"number",name:"PRESSURE",required:!1},{role:/^value.humidity$|value.humidity.forecast.0$/,indicator:!1,type:"number",name:"HUMIDITY",required:!1},{role:/^value.temperature.windchill$|^value.temperature.windchill.forecast.0$/,indicator:!1,type:"number",name:"WIND_CHILL",required:!1},{role:/^value.temperature.feelslike$|^value.temperature.feelslike$.forecast.0$/,indicator:!1,type:"number",name:"FEELS_LIKE",required:!1},{role:/^value.speed.wind$|^value.speed.wind.forecast.0$/,indicator:!1,type:"number",name:"WIND_SPEED",required:!1},{role:/^value.direction.wind$|^value.direction.wind.forecast.0$/,indicator:!1,type:"number",name:"WIND_DIRECTION",required:!1},{role:/^weather.direction.wind$|^weather.direction.wind.forecast.0$/,indicator:!1,type:"string",name:"WIND_DIRECTION_STR",required:!1},{role:/^weather.icon.wind$|^weather.icon.wind.forecast.0$/,indicator:!1,type:"string",name:"WIND_ICON",required:!1},{role:/^weather.chart.url$/,indicator:!1,type:"string",name:"HISTORY_CHART",required:!1,noSubscribe:!0},{role:/^weather.chart.url.forecast$/,indicator:!1,type:"string",name:"FORECAST_CHART",required:!1,noSubscribe:!0},{role:/^location$/,indicator:!1,type:"string",name:"LOCATION",required:!1,multiple:!0},{role:/^weather.icon.forecast.(\d)$/,indicator:!1,type:"string",name:"ICON%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0,notSingle:!0},{role:/^value.temperature.min.forecast.(\d)$/,indicator:!1,type:"number",name:"TEMP_MIN%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.temperature.max.forecast.(\d)$/,indicator:!1,type:"number",name:"TEMP_MAX%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^date.forecast.(\d)$/,indicator:!1,type:"string",name:"DATE%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^dayofweek.forecast.(\d)$/,indicator:!1,type:"string",name:"DOW%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^weather.state.forecast.(\d)$/,indicator:!1,type:"string",name:"STATE%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.temperature.forecast.(\d)$/,indicator:!1,type:"number",name:"TEMP%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.humidity.forecast.(\d)$/,indicator:!1,type:"number",name:"HUMIDITY%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.humidity.max.forecast.(\d)$/,indicator:!1,type:"number",name:"HUMIDITY_MAX%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.precipitation.forecast.(\d)$/,indicator:!1,type:"number",unit:"%",name:"PRECIPITATION_CHANCE%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.speed.wind.forecast.(\d)$/,indicator:!1,type:"number",name:"WIND_SPEED%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.direction.wind.forecast.(\d)$/,indicator:!1,type:"number",name:"WIND_DIRECTION%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^weather.direction.wind.forecast.(\d)$/,indicator:!1,type:"string",name:"WIND_DIRECTION_STR%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^weather.icon.wind.forecast.(\d)$/,indicator:!1,type:"string",name:"WIND_ICON%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0}],type:Types.weatherForecast},rgb:{states:[{role:/^level\.color\.red$/,indicator:!1,type:"number",write:!0,name:"RED",required:!0},{role:/^level\.color\.green$/,indicator:!1,type:"number",write:!0,name:"GREEN",required:!0},{role:/^level\.color\.blue$/,indicator:!1,type:"number",write:!0,name:"BLUE",required:!0},{role:/^level\.dimmer$/,indicator:!1,type:"number",write:!0,name:"DIMMER",required:!1},{role:/^level\.brightness$/,indicator:!1,type:"number",write:!0,name:"BRIGHTNESS",required:!1},{role:/^level\.color\.saturation$/,indicator:!1,type:"number",write:!0,name:"SATURATION",required:!1},{role:/^level\.color\.temperature$/,indicator:!1,type:"number",write:!0,name:"TEMPERATURE",required:!1},{role:/^switch\.light$/,indicator:!1,type:"boolean",write:!0,name:"ON_LIGHT",required:!1},{role:/^switch$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},e,t,n,i,r],type:Types.rgb},rgbOld:{states:[{role:/^level\.color\.r$/,indicator:!1,type:"number",write:!0,name:"RED",required:!0},{role:/^level\.color\.g$/,indicator:!1,type:"number",write:!0,name:"GREEN",required:!0},{role:/^level\.color\.b$/,indicator:!1,type:"number",write:!0,name:"BLUE",required:!0},{role:/^level\.dimmer$/,indicator:!1,type:"number",write:!0,name:"DIMMER",required:!1},{role:/^level\.brightness$/,indicator:!1,type:"number",write:!0,name:"BRIGHTNESS",required:!1},{role:/^level\.color\.saturation$/,indicator:!1,type:"number",write:!0,name:"SATURATION",required:!1},{role:/^level\.color\.temperature$/,indicator:!1,type:"number",write:!0,name:"TEMPERATURE",required:!1},{role:/^switch\.light$/,indicator:!1,type:"boolean",write:!0,name:"ON_LIGHT",required:!1},{role:/^switch$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},e,t,n,i,r],type:Types.rgb},rgbSingle:{states:[{role:/^level\.color\.rgb$/,indicator:!1,type:"string",write:!0,name:"RGB",required:!0},{role:/^level\.dimmer$/,indicator:!1,type:"number",write:!0,name:"DIMMER",required:!1},{role:/^level\.brightness$/,indicator:!1,type:"number",write:!0,name:"BRIGHTNESS",required:!1},{role:/^level\.color\.saturation$/,indicator:!1,type:"number",write:!0,name:"SATURATION",required:!1},{role:/^level\.color\.temperature$/,indicator:!1,type:"number",write:!0,name:"TEMPERATURE",required:!1},{role:/^switch\.light$/,indicator:!1,type:"boolean",write:!0,name:"ON_LIGHT",required:!1},{role:/^switch$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},e,t,n,i,r],type:Types.rgbSingle},hue:{states:[{role:/^level\.color\.hue$/,indicator:!1,type:"number",write:!0,name:"HUE",required:!0},{role:/^level\.dimmer$/,indicator:!1,type:"number",write:!0,name:"DIMMER",required:!1,searchInParent:!0},{role:/^level\.brightness$/,indicator:!1,type:"number",write:!0,name:"BRIGHTNESS",required:!1},{role:/^level\.color\.saturation$/,indicator:!1,type:"number",write:!0,name:"SATURATION",required:!1},{role:/^level\.color\.temperature$/,indicator:!1,type:"number",write:!0,name:"TEMPERATURE",required:!1},{role:/^switch.light$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},{role:/^switch$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},e,t,n,i,r],type:Types.hue},warning:{states:[{role:/^value\.warning$/,indicator:!1,name:"LEVEL",required:!0},{role:/^weather\.title\.short$/,indicator:!1,type:"string",name:"TITLE",required:!1},{role:/^weather\.title$/,indicator:!1,type:"string",name:"INFO",required:!1},{role:/^date\.start$/,indicator:!1,type:"string",name:"START",required:!1},{role:/^date\.end$/,indicator:!1,type:"string",name:"END",required:!1},{role:/^date$/,indicator:!1,type:"string",name:"START",required:!1},{role:/^weather\.chart\.url/,indicator:!1,type:"string",name:"ICON",required:!1},{role:/^weather\.state$/,indicator:!1,type:"string",name:"DESC",required:!1,noSubscribe:!0}],type:Types.warning},thermostat:{states:[{role:/temperature(\..*)?$/,indicator:!1,write:!0,type:"number",name:"SET",required:!0},{role:/temperature(\..*)?$/,indicator:!1,write:!1,type:"number",searchInParent:!0,name:"ACTUAL",required:!1},{role:/humidity(\..*)?$/,indicator:!1,write:!1,type:"number",searchInParent:!0,name:"HUMIDITY",required:!1},{role:/^switch\.boost(\..*)?$/,indicator:!1,write:!0,type:"number",searchInParent:!0,name:"BOOST",required:!1},e,t,n,i,r],type:Types.thermostat},blinds:{states:[{role:/^level(\.blind)?$/,indicator:!1,type:"number",write:!0,enums:m,name:"SET",required:!0},{role:/^value(\.blind)?$/,indicator:!1,type:"number",enums:m,name:"ACTUAL",required:!1},{role:/^button\.stop$|^action\.stop$/,indicator:!1,type:"boolean",write:!0,enums:m,name:"STOP",required:!1,noSubscribe:!0},o,e,t,n,i,r],type:Types.blind},lock:{states:[{role:/^switch\.lock$/,indicator:!1,type:"boolean",write:!0,name:"SET",required:!0},{role:/^state$/,indicator:!1,type:"boolean",write:!1,name:"ACTUAL",required:!1},{indicator:!1,type:"boolean",write:!0,read:!1,name:"OPEN",required:!1,noSubscribe:!0},o,e,t,n,i,r],type:Types.lock},motion:{states:[{role:/^state\.motion$|^sensor\.motion$/,indicator:!1,type:"boolean",name:"ACTUAL",required:!0},{role:/brightness$/,indicator:!1,type:"number",name:"SECOND",required:!1},t,n,i,r],type:Types.motion},window:{states:[{role:/^state(\.window)?$|^sensor(\.window)?/,indicator:!1,type:"boolean",enums:p,name:"ACTUAL",required:!0},t,n,i,r],type:Types.window},windowTilt:{states:[{role:/^state?$|^value(\.window)?$/,indicator:!1,type:"number",enums:p,name:"ACTUAL",required:!0},t,n,i,r],type:Types.windowTilt},fireAlarm:{states:[{role:/^state?$|^sensor(\.alarm)?\.fire/,indicator:!1,type:"boolean",name:"ACTUAL",required:!0,channelRole:/^sensor(\.alarm)?\.fire$/},t,n,i,r],type:Types.fireAlarm},door:{states:[{role:/^state?$|^state(\.door)?$|^sensor(\.door)?/,indicator:!1,type:"boolean",write:!1,enums:function(e,t){return a(e,t,b,g)},name:"ACTUAL",required:!0},t,n,i,r],type:Types.door},dimmer:{states:[{role:/^level(\.dimmer)?|^level\.brightness$/,indicator:!1,type:"number",write:!0,enums:l,name:"SET",required:!0},{role:/^value(\.dimmer)?$/,indicator:!1,type:"number",write:!1,enums:l,name:"ACTUAL",required:!1},{role:/^switch(\.light)?$|^state$/,indicator:!1,type:"boolean",write:!0,enums:l,name:"ON_SET",required:!1},{role:/^switch(\.light)?$|^state$/,indicator:!1,type:"boolean",write:!1,enums:l,name:"ON_ACTUAL",required:!1},e,t,n,i,r],type:Types.dimmer},light:{states:[{role:/^switch(\.light)?$|^state$/,indicator:!1,type:"boolean",write:!0,enums:l,name:"SET",required:!0},{role:/^switch(\.light)?$|^state$/,indicator:!1,type:"boolean",write:!1,enums:l,name:"ACTUAL",required:!1},e,t,n,i,r],type:Types.light},volume:{states:[{role:/^level\.volume$/,indicator:!1,type:"number",min:"number",max:"number",write:!0,name:"SET",required:!0},{role:/^value\.volume$/,indicator:!1,type:"number",min:"number",max:"number",write:!1,name:"ACTUAL",required:!1},{role:/^media\.mute$/,indicator:!1,type:"boolean",write:!0,name:"MUTE",required:!1},e,t,n,i,r],type:Types.volume},volumeGroup:{states:[{role:/^level\.volume\.group?$/,indicator:!1,type:"number",min:"number",max:"number",write:!0,name:"SET",required:!0},{role:/^value\.volume\.group$/,indicator:!1,type:"number",min:"number",max:"number",write:!1,name:"ACTUAL",required:!1},{role:/^media\.mute\.group$/,indicator:!1,type:"boolean",write:!0,name:"MUTE",required:!1},e,t,n,i,r],type:Types.volumeGroup},levelSlider:{states:[{role:/^level(\..*)?$/,indicator:!1,type:"number",min:"number",max:"number",write:!0,name:"SET",required:!0},{role:/^value(\..*)?$/,indicator:!1,type:"number",min:"number",max:"number",write:!1,name:"ACTUAL",required:!1},e,t,n,i,r],type:Types.slider},socket:{states:[{role:/^switch$|^state$|^switch\.active$/,indicator:!1,type:"boolean",write:!0,name:"SET",required:!0},{role:/^state$|^state\.active$/,indicator:!1,type:"boolean",write:!1,name:"ACTUAL",required:!1},e,t,n,i,r],type:Types.socket},button:{states:[{role:/^button(\.[.\w]+)?$|^action(\.[.\w]+)?$/,indicator:!1,type:"boolean",read:!1,write:!0,name:"SET",required:!0,noSubscribe:!0},t,n,i,r],type:Types.button},temperature:{states:[{role:/temperature$/,indicator:!1,write:!1,type:"number",name:"ACTUAL",required:!0},{role:/humidity$/,indicator:!1,write:!1,type:"number",name:"SECOND",required:!1},t,n,i,r],type:Types.temperature},info:{states:[{indicator:!1,name:"ACTUAL",required:!0,multiple:!0,noDeviceDetection:!0,ignoreRole:/\.inhibit$/},e,t,n,i,r],type:Types.info}};function a(e,t,n,i){return!(!n||-1===n.indexOf(e.common.role))||(o=i,a=!1,(r=t)&&r.forEach(function(t){var e=t.lastIndexOf(".");for(var n in-1!==e&&(t=t.substring(e+1)),o)if(o.hasOwnProperty(n)&&o[n].find(function(e){return e.test(t)}))return!(a=!0)}),a);var r,o,a}var s={en:[/lights?/i,/lamps?/i,/ceilings?/i],de:[/licht(er)?/i,/lampen?/i,/beleuchtung(en)?/i],ru:[/свет/i,/ламп[аы]/i,/торшеры?/,/подсветк[аи]/i,/лампочк[аи]/i,/светильники?/i]},c=["switch.light","dimmer","value.dimmer","level.dimmer","sensor.light","state.light"];function l(e,t){return a(e,t,c,s)}var u={en:[/blinds?/i,/windows?/i,/shutters?/i],de:[/rollladen?/i,/fenstern?/i,/beschattung(en)?/i],ru:[/ставни/i,/рольставни/i,/окна|окно/,/жалюзи/i]},d=["blind","level.blind","value.blind","action.stop","button.stop"];function m(e,t){return a(e,t,d,u)}var h=["window","state.window","sensor.window","value.window"];function p(e,t){return a(e,t,h,u)}var f,g={en:[/doors?/i,/gates?/i,/wickets?/i,/entry|entries/i],de:[/türe?/i,/tuere?/i,/tore?/i,/einfahrt(en)?/i,/pforten?/i],ru:[/двери|дверь/i,/ворота/i,/калитка|калитки/,/въезды?/i,/входы?/i]},b=["door","state.door","sensor.door"];function w(e,t){var n=[],i=new RegExp("^"+t.replace(/\./g,"\\.")+"\\.[^.]+\\.[^.]+$");return e.forEach(function(e){i.test(e)&&n.push(e)}),n}function k(e){var t=e.lastIndexOf(".");return-1!==t?e.substring(0,t):e}function y(e,t){if(t||(t=JSON.parse(JSON.stringify(e))),t instanceof Array)for(var n=0;n<t.length;n++)t[n].original=e[n].original||e[n],e[n].enums&&(t[n].enums=e[n].enums),e[n].role&&(t[n].role=e[n].role),e[n].channelRole&&(t[n].channelRole=e[n].channelRole),e[n].icon&&(t[n].icon=e[n].icon);else t.original=e.original||e,e.enums&&(t.enums=e.enums),e.role&&(t.role=e.role),e.channelRole&&(t.channelRole=e.channelRole),e.icon&&(t.icon=e.icon);return t}return this._applyPattern=function(e,t,n){if(e[t]&&e[t].common){var i=null;if(n.role&&(i=n.role.test(e[t].common.role||""))&&n.channelRole){var r=k(t);i=!(!e[r]||"channel"!==e[r].type&&"device"!==e[r].type)&&n.channelRole.test(e[r].common.role)}if(!1===i)return;if(n.stateName&&!n.stateName.test(t))return!1;if(n.unit&&n.unit!==e[t].common.unit)return!1;if(n.ignoreRole&&n.ignoreRole.test(e[t].common.role))return;if(!1===n.indicator&&(e[t].common.role||"").match(/^indicator(\.[.\w]+)?$/))return;if(n.state&&!n.state.test(t.split(".").pop()))return;if(void 0!==n.write&&n.write!==(e[t].common.write||!1))return;if("number"===n.min&&"number"!=typeof e[t].common.min)return;if("number"===n.max&&"number"!=typeof e[t].common.max)return;if(void 0!==n.read&&n.read!==(void 0===e[t].common.read||e[t].common.read))return;if(n.type)if("string"==typeof n.type){if(n.type!==e[t].common.type)return}else{for(var o=!0,a=0;a<n.type.length;a++)if(n.type[a]===e[t].common.type){o=!1;break}if(o)return}if(n.enums&&"function"==typeof n.enums){var s=this._getEnumsForId(e,t);if(!n.enums(e[t],s))return}return!0}return!1},this._getEnumsForId=function(t,n){this.enums=this.enums||function(e){var t=[],n=/^enum\.functions\./;for(var i in e)e.hasOwnProperty(i)&&n.test(i)&&e[i]&&"enum"===e[i].type&&e[i].common&&e[i].common.members&&e[i].common.members.length&&t.push(i);return t}(t);var i=[];if(this.enums.forEach(function(e){-1!==t[e].common.members.indexOf(n)&&i.push(e)}),!i.length&&t[n]&&"state"===t[n].type){var r=k(n);!t[r]||"channel"!==t[r].type&&"device"!==t[r].type||this.enums.forEach(function(e){-1!==t[e].common.members.indexOf(r)&&i.push(e)})}return i.length?i:null},this._testOneState=function(o){var a=o.objects,s=o.pattern,c=o.state,l=o.channelStates,u=o.usedIds,d=o._usedIds,m=o.ignoreIndicators,h=o.result,p=!1;return l.forEach(function(n){if((c.indicator||-1===u.indexOf(n)&&(c.notSingle||-1===d.indexOf(n)))&&this._applyPattern(a,n,c)){if(c.indicator&&m){var e=n.split(".");if(-1!==m.indexOf(e.pop()))return void console.log(n+" ignored")}if(c.indicator||c.notSingle||d.push(n),h||(o.result=h=JSON.parse(JSON.stringify(_[s])),h.states.forEach(function(e,t){y(_[s].states[t],e)})),h.type,!h.states.find(function(e){return e.id===n})){for(var t=!1,i=0;i<h.states.length;i++)if(h.states[i]instanceof Array){for(var r=0;r<h.states[i].length;r++)if(h.states[i][r].name===c.name&&h.states[i][r].role===c.role){h.states[i]=h.states[i][r],h.states[i].id=n,t=!0;break}if(t)break}else if(h.states[i].name===c.name){h.states[i].id=n,t=!0;break}t||console.error("Cannot find state for "+n)}return p=!0,c.multiple&&1<l.length&&l.forEach(function(e){if(e!==n&&(c.indicator||-1===u.indexOf(e)&&(c.notSingle||-1===d.indexOf(e)))&&this._applyPattern(a,e,c)){c.indicator||c.notSingle||d.push(e);var t=y(c);t.id=e,h.states.push(t)}}.bind(this)),!1}}.bind(this)),p},this._detectNext=function(e){var t,n,i,r=e.objects,o=e.id,a=e._keysOptional,s=e._usedIdsOptional,c=e.ignoreIndicators,l=e.allowedTypes;if(s||(s=[],e._usedIdsOptional=s),r[o]&&r[o].common){var u;u="state"===r[o].type?[o]:"device"===r[o].type?w(a,o):(t=a,n=[],i=new RegExp("^"+o.replace(/\./g,"\\.")+"\\.[^.]+$"),t.forEach(function(e){i.test(e)&&n.push(e)}),n),-1!==o.indexOf("javascript.0.devices.valueSimple")&&console.log("aaa");var d={objects:r,channelStates:u,usedIds:s,ignoreIndicators:c};for(var m in _)if(_.hasOwnProperty(m)&&(!l||-1!==l.indexOf(_[m].type))){d.result=null,"hue"===m&&-1!==o.indexOf("yeelight-2.0")&&console.log(m);var h=[];d.pattern=m,d._usedIds=h,_[m].states.forEach(function(e){var t=!1;if(e.name,e instanceof Array){for(var n=0;n<e.length;n++)if(d.state=e[n],this._testOneState(d)){t=!0;break}if(!t)return d.result=null,!1}else if(d.state=e,this._testOneState(d)&&(t=!0),e.required&&!t)return d.result=null,!1}.bind(this));var p=!0;if(d.result){for(var f=0;f<d.result.states.length;f++)if(d.result.states[f]instanceof Array){for(var g=!1,b=0;b<d.result.states[f].length;b++)if(d.result.states[f][b].required&&d.result.states[f].id){g=!0;break}if(!g){p=!1;break}}else if(d.result.states[f].required&&!d.result.states[f].id){p=!1;break}}else p=!1;if(p){var y;if(h.forEach(function(e){s.push(e)}),"device"!==r[o].type){var v=k(o);!r[v]||"channel"!==r[v].type&&"device"!==r[v].type||(y=w(a,v))&&y.forEach(function(n){d.result.states.forEach(function(e,t){e.id||!e.indicator&&!e.searchInParent||e.noDeviceDetection||this._applyPattern(r,n,e.original)&&(d.result.states[t].id=n)}.bind(this))}.bind(this))}return d.result.states.forEach(function(e){if(-1!==e.name.indexOf("%d")&&e.role&&e.id){var t=e.role.exec(d.objects[e.id].common.role);t&&(e.name=e.name.replace("%d",t[1]))}e.role&&delete e.role,e.enums&&delete e.enums,e.original&&(e.original.icon&&(e.icon=e.original.icon),delete e.original)}),d.result}}}return null},this.detect=function(e){var t=e.objects,n=e.id,i=e._keysOptional,r=e._usedIdsOptional;e.ignoreIndicators,e.allowedTypes;if(void 0!==this.cache[n])return this.cache[n];i||((i=Object.keys(t)).sort(),e._keysOptional=i);var o,a=[];for(r&&(r=[],e._usedIdsOptional=r);o=this._detectNext(e);)a.push(o);return this.cache[n]=a.length?a:null,this.cache[n]},(f=this).enums=null,f.cache={},this}"undefined"!=typeof module&&module.parent&&(module.exports={Types:Types,ChannelDetector:ChannelDetector});
|
|
//# sourceMappingURL=vendor.js.map
|