text: var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(c,g,d){c!=Array.prototype&&c!=Object.prototype&&(c[g]=d.value)};$jscomp.getGlobal=function(c){return"undefined"!=typeof window&&window===c?c:"undefined"!=typeof global&&null!=global?global:c};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
  $jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.Symbol=function(){var c=0;return function(g){return $jscomp.SYMBOL_PREFIX+(g||"")+c++}}();
  $jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var c=$jscomp.global.Symbol.iterator;c||(c=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[c]&&$jscomp.defineProperty(Array.prototype,c,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(c){var g=0;return $jscomp.iteratorPrototype(function(){return g<c.length?{done:!1,value:c[g++]}:{done:!0}})};
  $jscomp.iteratorPrototype=function(c){$jscomp.initSymbolIterator();c={next:c};c[$jscomp.global.Symbol.iterator]=function(){return this};return c};$jscomp.iteratorFromArray=function(c,g){$jscomp.initSymbolIterator();c instanceof String&&(c+="");var d=0,f={next:function(){if(d<c.length){var h=d++;return{value:g(h,c[h]),done:!1}}f.next=function(){return{done:!0,value:void 0}};return f.next()}};f[Symbol.iterator]=function(){return f};return f};
  $jscomp.polyfill=function(c,g,d,f){if(g){d=$jscomp.global;c=c.split(".");for(f=0;f<c.length-1;f++){var h=c[f];h in d||(d[h]={});d=d[h]}c=c[c.length-1];f=d[c];g=g(f);g!=f&&null!=g&&$jscomp.defineProperty(d,c,{configurable:!0,writable:!0,value:g})}};$jscomp.polyfill("Array.prototype.keys",function(c){return c?c:function(){return $jscomp.iteratorFromArray(this,function(c){return c})}},"es6","es3");
  var HARDWARE_VERSION="A1",FIRMWARE_VERSION="2.4.6",TASKMANAGER_VERSION="2.4.6",PLATFORM="CCU3",hasLocalStorage=!0;if("undefined"==typeof localStorage||null==localStorage)hasLocalStorage=!1,localStorage={};require("x.core.js");console.log((new Date).toString()+" ===========> started");
  var os=require("os"),fs=require("fs"),path=require("path"),async=require("async"),ls=require("node-localstorage").LocalStorage,xhub=require("x.hub.js"),v5=require("x.hub.v5.js"),miot=require("xnm.aio.m10T.js"),xnm=xnm||{};xnm.aio=xnm.aio||{};xnm.aio.xhub=xnm.aio.xhub||{};global.HARDWARE_VERSION="EA";global.FIRMWARE_VERSION="development";global.TASKMANAGER_VERSION="2.4.2";global.PLATFORM=null;global.NAME=null;global.VID=null;global.CLOUD_URL="https://webservice.mediola.com";global.CONTROL_SERVER="v5ws.mediola.com";
  global.LOAD_MODULES=null;global.DATA_FOLDER=null;global.APP_FOLDER=null;global.LOG_ROOT=null;global.LOG_LEVEL=null;global.WEB_SERVER_PORT=80;global.STM=null;global.HM_CHIP=null;global.HM_CHIP_USERNAME=null;global.HM_CHIP_PASSWORD=null;global.HM_LOCAL_PORT=9099;global.ENOCEAN_PORT=null;global.ZWAVE2_URL=null;global.ZWAVE2_PORT=null;global.ZIGBEE_URL=null;global.SAFE_MODE=!1;
  function _loadCompilerConfig(){"undefined"!=typeof HARDWARE_VERSION&&HARDWARE_VERSION&&(global.HARDWARE_VERSION=HARDWARE_VERSION);"undefined"!=typeof FIRMWARE_VERSION&&FIRMWARE_VERSION&&(global.FIRMWARE_VERSION=FIRMWARE_VERSION);"undefined"!=typeof TASKMANAGER_VERSION&&TASKMANAGER_VERSION&&(global.TASKMANAGER_VERSION=TASKMANAGER_VERSION);"undefined"!=typeof PLATFORM&&PLATFORM&&(global.PLATFORM=PLATFORM);"undefined"!=typeof NAME&&NAME&&(global.NAME=NAME);"undefined"!=typeof VID&&VID&&(global.VID=VID);
  "undefined"!=typeof CLOUD_URL&&CLOUD_URL&&(global.CLOUD_URL=CLOUD_URL);"undefined"!=typeof CONTROL_SERVER&&CONTROL_SERVER&&(global.CONTROL_SERVER=CONTROL_SERVER);"undefined"!=typeof LOAD_MODULES&&LOAD_MODULES&&(global.LOAD_MODULES=LOAD_MODULES)}
  function _loadProgrammEnv(){process&&process.env&&(process.env.HARDWARE_VERSION&&(global.HARDWARE_VERSION=process.env.HARDWARE_VERSION),process.env.FIRMWARE_VERSION&&(global.FIRMWARE_VERSION=process.env.FIRMWARE_VERSION),process.env.TASKMANAGER_VERSION&&(global.TASKMANAGER_VERSION=process.env.TASKMANAGER_VERSION),process.env.PLATFORM&&(global.PLATFORM=process.env.PLATFORM),process.env.NAME&&(global.NAME=process.env.NAME),process.env.VID&&(global.VID=process.env.VID))}
  function _loadConfigFile(){function c(c){if(c)for(var d in c)c.hasOwnProperty(d)&&(global[d]="DATA_FOLDER"==d||"APP_FOLDER"==d||"LOG_ROOT"==d?path.isAbsolute(c[d])?c[d]:path.resolve(__dirname,c[d]):c[d])}function g(){try{var d=require("./package.json");d&&c(d.config)}catch(h){}}function d(){try{var d=require("./config.json");c(d)}catch(h){}}switch(global.HARDWARE_VERSION){case "A1":g();break;case "EA":d()}}
  function _loadRuntimeConfig(){switch(global.HARDWARE_VERSION){case "A1":if(null==global.PLATFORM)switch(os.platform()){case "darwin":global.PLATFORM="MAC";break;case "win32":global.PLATFORM="WIN";break;default:global.PLATFORM="LINUX"}null==global.NAME&&(global.NAME="NEO Server");null==global.VID&&(global.VID=null);null==global.CLOUD_URL&&(global.CLOUD_URL="https://webservice.mediola.com");null==global.CONTROL_SERVER&&(global.CONTROL_SERVER="v5ws.mediola.com");null==global.LOAD_MODULES&&(global.LOAD_MODULES=
  ["knx","sonos"]);null==global.DATA_FOLDER&&(global.DATA_FOLDER=null);null==global.APP_FOLDER&&(global.APP_FOLDER=null);null==global.LOG_ROOT&&(global.LOG_ROOT=null);null==global.LOG_LEVEL&&(global.LOG_LEVEL="fatal");null==global.WEB_SERVER_PORT&&(global.WEB_SERVER_PORT=8088);null==global.HM_CHIP&&(global.HM_CHIP=null);null==global.HM_LOCAL_PORT&&(global.HM_LOCAL_PORT=9099);null==global.ENOCEAN_PORT&&(global.ENOCEAN_PORT=null);null==global.ZWAVE2_URL&&(global.ZWAVE2_URL=null);null==global.ZWAVE2_PORT&&
  (global.ZWAVE2_PORT=null);null==global.ZIGBEE_URL&&(global.ZIGBEE_URL=null);null==global.STM&&(global.STM=null);break;case "EA":if(null==global.PLATFORM&&(global.PLATFORM="A20"),null==global.NAME&&(global.NAME="AIO GATEWAY V5+"),null==global.VID&&(global.VID=null),null==global.CLOUD_URL&&(global.CLOUD_URL="https://webservice.mediola.com"),null==global.CONTROL_SERVER&&(global.CONTROL_SERVER="v5ws.mediola.com"),null==global.LOAD_MODULES&&(global.LOAD_MODULES=["enocean","zway","knx","zigbee","sonos"]),
  null==global.DATA_FOLDER&&(global.DATA_FOLDER=path.resolve(__dirname,"./data")),null==global.APP_FOLDER&&(global.APP_FOLDER=path.resolve(__dirname,"./data")),null==global.LOG_ROOT&&(global.LOG_ROOT="/var/log"),null==global.LOG_LEVEL&&(global.LOG_LEVEL="fatal"),null==global.WEB_SERVER_PORT&&(global.WEB_SERVER_PORT=80),null==global.HM_CHIP&&(global.HM_CHIP="127.0.0.1"),null==global.HM_LOCAL_PORT&&(global.HM_LOCAL_PORT=9099),null==global.ENOCEAN_PORT&&(global.ENOCEAN_PORT=null),null==global.ZWAVE2_URL&&
  (global.ZWAVE2_URL="127.0.0.1"),null==global.ZWAVE2_PORT&&(global.ZWAVE2_PORT=9E3),null==global.ZIGBEE_URL&&(global.ZIGBEE_URL="127.0.0.1"),!global.STM)switch(global.PLATFORM){case "MAC":global.STM=null;break;case "WIN":global.STM=null;break;case "A20":global.STM="/dev/ttyS2";break;case "PI2":global.STM="/dev/spidev0.1";break;default:global.STM="/dev/ttyACM0"}}"undefined"!=typeof global.CONTROL_SERVER&&global.CONTROL_SERVER&&(require("x.hub.v5.js").CloudConnect.prototype.CLOUD_SERVER=global.CONTROL_SERVER);
  "undefined"!=typeof global.CLOUD_URL&&global.CLOUD_URL&&(require("x.hub.taskman.js").Cloud.prototype.URL=global.CLOUD_URL);"undefined"!=typeof global.TASKMANAGER_VERSION&&global.TASKMANAGER_VERSION&&(require("x.hub.taskman.js").TaskManager.NS_VERSION=global.TASKMANAGER_VERSION)}
  function _setupServer(){var c=null;switch(global.PLATFORM){case "MAC":c=new xhub.Server(global.STM);break;case "WIN":c=new xhub.Server(global.STM);break;case "A20":c=new xhub.Server(global.STM);break;case "PI2":c=new xhub.Server(global.STM,null,"gpio26");break;default:c=new xhub.Server(global.STM)}c.hostType=global.PLATFORM;xhub.server=c;v5.server=c;c.HWV=global.HARDWARE_VERSION;c.VERSION=global.FIRMWARE_VERSION;c.DEFAULT_NAME=global.NAME;var g=null,d=Date.now();c.on("serialevent",function(a,b){require("x.logger.js").getLogger("x.hub.m.gateway.Serial").log("trace",
  "SERIAL EVENT: "+a);var e=g,n=Date.now()-d;d=Date.now();g=a;if(!(e==a&&1E3>n)){e=null;try{e=JSON.parse(a)}catch(k){}e&&(require("x.hub.eventbus.js").emit("gatewayevent",e,{address:"ST"},b),"EVT"!=b&&"STA"!=b||c.sendUDPMessage(b+":"+JSON.stringify(e)+"\r\n"))}});var f=require("x.hub.v6.js");f._centralUnit=new f.CentralUnit(c);f._centralUnit.init();c.setCmdFunc("refreshhm",function(a,b){b(JSON.stringify({XC_SUC:{}}))});c.setCmdFunc("resethm",function(a,b){require("x.hub.m.hm.js").resetChip(function(a){a.error?
  b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("addSensor",function(a,b){a.query.type&&"ENOCEAN"==a.query.type.toUpperCase()?require("x.hub.m.enocean.js").addSensor(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):b(null)});c.setCmdFunc("LearnSC",function(a,b){if(a.query.type&&"HM"==a.query.type.toUpperCase()){var e=require("x.hub.m.hm.js");a.query.key&&a.query.sgtin?
  e.learnIPDevice(null,a.query.sgtin,a.query.key,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{devices:a.data}}))}):a.query.qrkey?e.learnIPDeviceQR(null,a.query.qrkey,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{devices:a.data}}))}):a.query.adr?e.learnRFDeviceSN(null,a.query.adr,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{devices:a.data}}))}):
  e.learnRFDevice(null,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{devices:a.data}}))})}else a.query.type&&"ENOCEAN"==a.query.type.toUpperCase()?require("x.hub.m.enocean.js").learnDevice(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:a.data}))}):a.query.type&&"ZIGBEE"==a.query.type.toUpperCase()?require("x.hub.m.zigbee.js").learnDevice(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",
  msg:a.error.message}})):b(JSON.stringify({XC_SUC:a.data}))}):b(null)});c.setCmdFunc("SendSC",function(a,b){a.query.type&&"HM"==a.query.type.toUpperCase()?a.query.address&&a.query.data?require("x.hub.m.hm.js").executeCommandLegacy(null,a.query.address,a.query.data,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):b(JSON.stringify({XC_ERR:{code:"001000",msg:"address or data invalid"}})):a.query.type&&"ENOCEAN"==a.query.type.toUpperCase()?
  a.query.address&&a.query.data?require("x.hub.m.enocean.js").executeCommandLegacy(null,a.query.address,a.query.data,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):b(JSON.stringify({XC_ERR:{code:"001000",msg:"address or data invalid"}})):a.query.type&&"ZWAVE"==a.query.type.toUpperCase()?a.query.address&&a.query.data&&a.query.devicetype?require("x.hub.m.zwave.js").executeCommandLegacy(null,a.query.address,a.query.devicetype,a.query.data,
  function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):b(JSON.stringify({XC_ERR:{code:"001000",msg:"address or data or devicetype invalid"}})):a.query.type&&"ZWAVE2"==a.query.type.toUpperCase()?require("x.hub.m.zway.js").executeCommandLegacy(a.query.address,a.query.data,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):a.query.type&&"KNX"==a.query.type.toUpperCase()?require("x.hub.m.knx.js").executeCommandLegacy(a.query.address,
  a.query.data,function(a){a.error?b(JSON.stringify({XC_ERR:{code:a.error.code?a.error.code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):a.query.type&&"ZIGBEE"==a.query.type.toUpperCase()?require("x.hub.m.zigbee.js").executeCommandLegacy(a.query.address,a.query.data,function(a){a.error?b(JSON.stringify({XC_ERR:{code:a.error.code?a.error.code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):"PI2"==c.hostType&&"RGB"==a.query.type&&a.query.data&&8==a.query.data.length?
  (v5&&v5.setRGBColor(a.query.data.substr(2)),b(JSON.stringify({XC_SUC:{}}))):b(null)});c.setCmdFunc("delSensor",function(a,b){a.query.type&&"HM"==a.query.type.toUpperCase()?a.query.adr?require("x.hub.m.hm.js").deleteDevice(null,a.query.adr,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):b(JSON.stringify({XC_ERR:{code:"001000",msg:"adr invalid"}})):a.query.type&&"ENOCEAN"==a.query.type.toUpperCase()?require("x.hub.m.enocean.js").delSensor(a.query.address,
  function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):a.query.type&&"ZIGBEE"==a.query.type.toUpperCase()?require("x.hub.m.zigbee.js").removeDevice(a.query.address,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):b(null)});c.setCmdFunc("gethmconfig",function(a,b){a.query.address?require("x.hub.m.hm.js").getConfig({address:a.query.address},function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",
  msg:a.error.message}})):b(JSON.stringify({XC_SUC:{config:a.data}}))}):b(null)});c.setCmdFunc("sethmconfig",function(a,b){a.query.address&&a.query.config?require("x.hub.m.hm.js").setConfig({address:a.query.address},a.query.config,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):b(null)});c.setCmdFunc("setVar",function(a,b){require("x.hub.sysvarman.js").setVar(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):
  b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("delVar",function(a,b){require("x.hub.sysvarman.js").delVar(a.query.id,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))})});var h=[],l=null;c.setCmdFunc("getStates",function(a,b){var e=function(a,b){var e=h;h=[];a?e.forEach(function(b){b(JSON.stringify({XC_ERR:{code:"001000",msg:a.message}}))}):0<b.length?e.forEach(function(a){a(JSON.stringify({XC_SUC:b}))}):e.forEach(function(a){a(JSON.stringify({XC_SUC:{}}))})},
  c=[],k=[],d=[],m=h.length,f=(new Date).getTime();0!=m&&18E4<f-l&&(e(Error("get states dead lock")),m=h.length);-1==h.indexOf(b)&&h.push(b);0==m&&(l=(new Date).getTime(),async.parallel([function(a){if("A20"!=global.PLATFORM&&"PI2"!=global.PLATFORM)a();else if(localStorage&&"true"==localStorage.getItem("x.hub.Server.DISABLE_ST_STATES"))a();else{var b=setTimeout(function(){k.push({type:"ST_ERROR",state:"st timeout"});a&&(a(),a=null)},1E4);xhub.server._doSTMCommandRequest("/cmd?XC_FNC=getStates",!1,function(e){b&&
  (clearTimeout(b),b=null);if(a){try{var c=JSON.parse(e);c.XC_SUC?Array.isArray(c.XC_SUC)?k=k.concat(c.XC_SUC):0<Object.keys(c.XC_SUC).length&&(k=k.push(c.XC_SUC)):k.push({type:"ST_ERROR",state:"st return:"+e});a()}catch(r){k.push({type:"ST_ERROR",state:"st return invalid json"}),a()}a=null}})}},function(a){require("x.hub.m.hm.js").getAllStatesLegacy(function(b){b.error?c.push({type:"HM_ERROR",state:b.error}):c=c.concat(b.data);a()})},function(b){-1==global.LOAD_MODULES.indexOf("enocean")?b():require("x.hub.m.enocean.js").getAllStatesLegacy(function(a){a.error?
  c.push({type:"ENOCEAN_ERROR",state:a.error}):c=c.concat(a.data);b()},a.query)},function(a){-1==global.LOAD_MODULES.indexOf("zwave")?a():require("x.hub.m.zwave.js").getAllStatesLegacy(function(b){b.error?c.push({type:"ZWAVE_ERROR",state:b.error}):c=c.concat(b.data);a()})},function(a){require("x.hub.m.zway.js").getAllStatesLegacy(function(b){b.error?c.push({type:"ZWAVE2_ERROR",state:b.error}):c=c.concat(b.data);a()})},function(a){-1==global.LOAD_MODULES.indexOf("knx")?a():require("x.hub.m.knx.js").getAllStatesLegacy(function(b){b.error?
  c.push({type:"KNX_ERROR",state:b.error}):c=c.concat(b.data);a()})},function(a){-1==global.LOAD_MODULES.indexOf("zigbee")?a():require("x.hub.m.zigbee.js").getAllStatesLegacy(function(b){b.error?c.push({type:"ZIGBEE_ERROR",state:b.error}):c=c.concat(b.data);a()})},function(a){require("x.hub.taskman.js").readAllTasks(function(b){if(b.error)c.push({type:"TASK_ERROR",state:b.error});else{var e=[];b.data.forEach(function(a){a&&e.push({type:"TASK",id:a.id,active:a.active})});c=c.concat(e)}a()})},function(a){require("x.hub.sysvarman.js").getSysvarStates(function(b){b.error?
  c.push({type:"SYSVAR_ERROR",state:b.error}):d=d.concat(b.data);a()})}],function(a){a?e(a,c):k&&0<k.length?require("x.hub.sysvarman.js").processSysvarST(xhub.server,k,function(b){b&&!b.error&&b.data&&0<b.data.length&&(c=c.concat(b.data));e(a,c)}):(d&&0<d.length&&(c=c.concat(d)),e(a,c))}))});c.setCmdFunc("getSI",function(a,b){c.doSTMCommand("XC_FNC=GetSI",function(a){a&&a.XC_SUC&&(a.XC_SUC.HWV=c.HWV,!err&&tz&&(a.XC_SUC.TZ=tz+""));b(JSON.stringify(a))})});c.setCmdFunc("GetSI",function(a,b){c.getTimeZoneCompatiable(function(a,
  d){c.doSTMCommand("XC_FNC=GetSI",function(e){e&&e.XC_SUC&&(e.XC_SUC.HWV=c.HWV,!a&&d&&(e.XC_SUC.TZ=d+""));b(JSON.stringify(e))})})});c.setCommandFunc("GetSI",function(a,b){c.getTimeZoneCompatiable(function(a,d){c.doSTMCommand("XC_FNC=GetSI",function(e){e&&e.XC_SUC?(e.XC_SUC.HWV=c.HWV,!a&&d&&(e.XC_SUC.TZ=d+""),b.send("{XC_SUC}"+JSON.stringify(e.XC_SUC))):b.send("{XC_ERR}")})})});c.setCommandFunc("setTZ",function(a,b){c.setTimeZoneCompatiable(a.query.data,function(a){a?b.send("{XC_ERR}"):b.send("{XC_SUC}")})});
  c.setCmdFunc("setTZ",function(a,b){c.setTimeZoneCompatiable(a.query.data,function(a){a?b(JSON.stringify({XC_ERR:{}})):b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("SendM",function(a,b){if(a.query&&a.query.m&&a.query.cmd){var e=a.query.m,c=a.query.cmd;delete a.query.XC_FNC;delete a.query.m;delete a.query.cmd;var d=null;try{d=require("x.hub.m."+e+".js")}catch(p){}d&&d.executeCommand?d.executeCommand(a.query,c,function(){b('{"XC_SUC":{}}')}):b('{"XC_ERR":{"code":"000000","msg":"internal error"}}')}else b('{"XC_ERR":{"code":"000001", "msg":"invalid request"}}')});
  c.setCmdFunc("GetM",function(a,b){if(a.query&&a.query.m){var e=a.query.m;delete a.query.XC_FNC;delete a.query.m;var c=null;try{c=require("x.hub.m."+e+".js")}catch(k){}c&&c.updateStates?c.updateStates(a.query,function(a){a?b('{"XC_SUC":'+JSON.stringify(a)+"}"):b('{"XC_SUC":{}}')}):b('{"XC_ERR":{"code":"000000","msg":"internal error"}}')}else b('{"XC_ERR":{"code":"000001", "msg":"invalid request"}}')});c.setCmdFunc("SendRM",function(a,b){require("x.logger.js").getLogger("CloudRemoteAccess").log("trace",
  "execute command:"+JSON.stringify(a.query));a.query?require("x.hub.commandman.js").commandHandler2.executeCommandWithIdx(a.query.device,a.query.gateway,a.query.command,function(a){a.error?b('{"XC_ERR":{"code":"000000","msg":"'+a.error.message+'"}}'):b('{"XC_SUC":{}}')}):b('{"XC_ERR":{"code":"000001", "msg":"invalid request"}}')});c.setCmdFunc("GetRM",function(a,b){require("x.logger.js").getLogger("CloudRemoteAccess").log("trace","get states:"+JSON.stringify(a.query));a.query?require("x.hub.commandman.js").commandHandler2.getStateWithIdx(a.query.device,
  a.query.gateway,a.query.status,function(a){a.error?b('{"XC_ERR":{"code":"000000","msg":"'+a.error.message+'"}}'):b('{"XC_SUC":'+JSON.stringify(a.data)+"}")}):b('{"XC_ERR":{"code":"000001", "msg":"invalid request"}}')});c.setCmdFunc("DoMacroRM",function(a,b){require("x.logger.js").getLogger("CloudRemoteAccess").log("trace","execute macro:"+JSON.stringify(a.query));a.query?require("x.hub.macroman.js").executeWithIdx2(a.query.groupIdx,a.query.macroIdx,function(a){a.error?b('{"XC_ERR":{"code":"000000","msg":"'+
  a.error.message+'"}}'):b('{"XC_SUC":{}}')}):b('{"XC_ERR":{"code":"000001", "msg":"invalid request"}}')});c.setCmdFunc("GetTask",function(a,b){require("x.hub.taskman.js").doWebRequest("Read",a,b)});c.setCmdFunc("CreateTask",function(a,b){require("x.hub.taskman.js").doWebRequest("Create",a,b)});c.setCmdFunc("UpdateTask",function(a,b){require("x.hub.taskman.js").doWebRequest("Update",a,b)});c.setCmdFunc("DeleteTask",function(a,b){require("x.hub.taskman.js").doWebRequest("Delete",a,b)});c.setCmdFunc("DoTask",
  function(a,b){require("x.hub.taskman.js").doWebRequest("Do",a,b)});c.setCmdFunc("CancelTask",function(a,b){require("x.hub.taskman.js").doWebRequest("Cancel",a,b)});c.setCmdFunc("IsTaskRunning",function(a,b){require("x.hub.taskman.js").doWebRequest("isRunning",a,b)});c.setCmdFunc("SetTaskActive",function(a,b){require("x.hub.taskman.js").doWebRequest("SetTaskActive",a,b)});c.setCmdFunc("ToggleTaskActive",function(a,b){require("x.hub.taskman.js").doWebRequest("ToggleTaskActive",a,b)});c.setCmdFunc("SetAlarmActive",
  function(a,b){require("x.hub.taskman.js").doWebRequest("SetAlarmActive",a,b)});c.setCmdFunc("SetAlarmDelay",function(a,b){require("x.hub.taskman.js").doWebRequest("SetAlarmDelay",a,b)});c.setCmdFunc("GetAlarmInfo",function(a,b){require("x.hub.taskman.js").doWebRequest("GetAlarmInfo",a,b)});c.setCmdFunc("SelectAlarmTask",function(a,b){require("x.hub.taskman.js").doWebRequest("SelectAlarmTask",a,b)});c.setCmdFunc("SetAlarmPin",function(a,b){require("x.hub.taskman.js").doWebRequest("SetAlarmPin",a,b)});
  c.setCmdFunc("GetCloudServer",function(a,b){require("x.hub.taskman.js").doWebRequest("GetCloudServer",a,b)});c.setCmdFunc("SetCloudServer",function(a,b){require("x.hub.taskman.js").doWebRequest("SetCloudServer",a,b)});c.setCmdFunc("GetCloudDeviceTriggerGateway",function(a,b){require("x.hub.taskman.js").doWebRequest("GetCloudDeviceTriggerGateway",a,b)});c.setCmdFunc("RehauPinChallenge",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauPinChallenge",a,b)});c.setCmdFunc("RehauGetAlarmInfo",
  function(a,b){require("x.hub.taskman.js").doWebRequest("RehauGetAlarmInfo",a,b)});c.setCmdFunc("RehauSetAlarmDelay",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauSetAlarmDelay",a,b)});c.setCmdFunc("RehauSetDoorAlarmDelay",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauSetDoorAlarmDelay",a,b)});c.setCmdFunc("RehauSetNewPin",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauSetNewPin",a,b)});c.setCmdFunc("RehauSelectAssociateTaskAlarm",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauSelectAssociateTaskAlarm",
  a,b)});c.setCmdFunc("RehauSelectAssociateTaskPreAlarm",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauSelectAssociateTaskPreAlarm",a,b)});c.setCmdFunc("RehauSetAlarmActive",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauSetAlarmActive",a,b)});c.setCmdFunc("RehauAddAlarmKey",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauAddAlarmKey",a,b)});c.setCmdFunc("RehauUpdateAlarmKey",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauUpdateAlarmKey",a,b)});
  c.setCmdFunc("RehauDeleteAlarmKey",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauDeleteAlarmKey",a,b)});c.setCmdFunc("RehauAddAlarmDoor",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauAddAlarmDoor",a,b)});c.setCmdFunc("RehauUpdateAlarmDoor",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauUpdateAlarmDoor",a,b)});c.setCmdFunc("RehauDeleteAlarmDoor",function(a,b){require("x.hub.taskman.js").doWebRequest("RehauDeleteAlarmDoor",a,b)});c.setCmdFunc("RehauSetAlarmConfirmation",
  function(a,b){require("x.hub.taskman.js").doWebRequest("RehauSetAlarmConfirmation",a,b)});c.setCmdFunc("AddEventListener",function(a,b){if((a=a.query.data)&&a.sys){var e=require("x.hub.moduleman.js").modulemanager.getModule(a.sys);e?e.addStateDevice(a,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"000000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}):b(JSON.stringify({XC_ERR:{code:"000000",msg:"no module for sys:"+a.sys}}))}else b(JSON.stringify({XC_ERR:{code:"000000",msg:"device format invalid"}}))});
  c.setCmdFunc("GetMetaInfo",function(a,b){a=require("x.hub.taskman.js").taskManager;var e={XC_SUC:{version:String(a.version),deploy:{time:localStorage.getItem("x.hub.hubsyncman.SyncManager.TIMESTAMP"),userid:localStorage.getItem("x.hub.hubsyncman.SyncManager.USERID"),appid:localStorage.getItem("x.hub.hubsyncman.SyncManager.APPID")}}};"A1"==global.HARDWARE_VERSION&&(e.XC_SUC.trial=0!=a._mode%31);b(JSON.stringify(e))});c.setCmdFunc("ConfigSiegeniaWindow",function(a,b){require("x.hub.m.enocean.js").configSiegeniaWindow(null,
  null,function(a){a.error?b(JSON.stringify({XC_ERR:{message:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("AddEnoceanVirtualDevice",function(a,b){require("x.hub.m.enocean.js").generateVirtualDevice(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("AddEnoceanDevice",function(a,b){require("x.hub.m.enocean.js").addSensor(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,
  code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("UpdateEnoceanDevice",function(a,b){require("x.hub.m.enocean.js").updateSensor(a.query.address,a.query.device,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("TeachinEnocean",function(a,b){require("x.hub.m.enocean.js").teachinDevice(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});
  c.setCmdFunc("GetUSBDevices",function(a,b){require("x.hub.peripheralman.js").getUSBDevices(function(a){a.error?b(JSON.stringify({XC_ERR:{message:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("SetLogger",function(a,b){a.query.level?require("x.hub.logman.js").setLoggger(a.query.tag,a.query.level,function(){b(JSON.stringify({XC_SUC:{}}))}):b(JSON.stringify({XC_ERR:{message:"parameter invalid",code:"010001"}}))});c.setCmdFunc("GetLogger",function(a,b){a=require("x.logger.js").getAll();
  b(JSON.stringify({XC_SUC:a}))});c.setCmdFunc("DummyEvent",function(a,b){a=a.query.data;require("x.hub.eventbus.js").emit("status",a);b(JSON.stringify({XC_SUC:{}}))});c.setCmdFunc("DummyTaskmanEvent",function(a,b){var e=a.query.event;a=a.query.meta;require("x.hub.taskman.js").onStatusEvt(e,a);b(JSON.stringify({XC_SUC:{}}))});c.setCmdFunc("GetZwaveStates",function(a,b){a=a.query.devices;require("x.hub.m.zwave.js").__getStates(a,function(a){a.error?b(JSON.stringify({XC_ERROR:{message:a.error.message,
  code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("DirectEvent",function(a,b){var c=a.query.event;a=a.query.tag;require("x.hub.m.gateway.js")._onEvent(c,{address:"http call"},a);b(JSON.stringify({XC_SUC:{}}))});c.setCmdFunc("GetHmMonitors",function(a,b){require("x.hub.m.hm.js").getMonitorStates(function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("GetHmDevices",function(a,b){require("x.hub.m.hm.js").getAllDevices(function(a){a.error?
  b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("EnOceanSDK",function(a,b){require("x.hub.m.enocean.js")._doSDK(a.query.data,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ResetEnOceanSenderID",function(a,b){require("x.hub.m.enocean.js").resetDefaultSenderID(function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):
  b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("SetRehauInoventHumidityAccessory",function(a,b){require("x.hub.m.enocean.js").setInoventHumidityAccessory(a.query.inoventID,a.query.humiditySensorID,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("SetRehauInoventCo2Accessory",function(a,b){require("x.hub.m.enocean.js").setInoventCo2Accessory(a.query.inoventID,a.query.co2SensorID,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,
  code:a.error.code}})):b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("GetRehauInoventAccessories",function(a,b){require("x.hub.m.enocean.js").getInoventAccessories(a.query.inoventID,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("RawEnoceanPacket",function(a,b){a=a.query.data;require("x.hub.m.enocean.js").__simulateRawEnoceanPacket(a,function(a){b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("SendESPFrame",
  function(a,b){var c=a.query.type,d=a.query.data,k=a.query.optData;a=a.query.requireResponse;require("x.hub.m.enocean.js").__sendEspFrame(c,d,k,a,function(a){a.error?b(JSON.stringify({XC_ERROR:{message:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ZWaveInclusion",function(a,b){require("x.hub.m.zway.js").learnDevice(a.query,function(a,b,c){console.log("learn zwave procedure",a,b,c)},function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):
  b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ZWaveExclusion",function(a,b){require("x.hub.m.zway.js").removeDevice(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ZWaveListDevices",function(a,b){require("x.hub.m.zway.js").listDevices(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ZWaveListInterviewResults",
  function(a,b){require("x.hub.m.zway.js").listInterviewResults(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ZWaveResetController",function(a,b){require("x.hub.m.zway.js").resetController(function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ZWaveSetDeviceSetting",function(a,b){require("x.hub.m.zway.js").setDeviceSetting(a.query.deviceID,
  a.query.setting,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ZWaveGetDeviceSetting",function(a,b){require("x.hub.m.zway.js").getDeviceSetting(a.query.deviceID,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ZWaveForcePollDevices",function(a,b){var c=require("x.hub.m.zway.js");a.query.deviceIDs?(a=a.query.deviceIDs.split(","),
  c.forcePoll(a,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})):b(JSON.stringify({XC_ERR:{msg:"no device id list",code:"000000"}}))});c.setCmdFunc("GetKnxIpGateways",function(a,b){require("x.hub.m.knx.js").getIPGateways(function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("AddKnxIpGateway",function(a,b){a=a.query.data;require("x.hub.m.knx.js").addIPGateway(a,
  function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("UptateKnxIpGateway",function(a,b){a=a.query.data;require("x.hub.m.knx.js").updateIPGateway(a,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("DeleteKnxIpGateway",function(a,b){a=a.query.data;require("x.hub.m.knx.js").deleteIPGateway(a,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,
  code:a.error.code}})):b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("GetKnxDevices",function(a,b){require("x.hub.m.knx.js").getDevices(function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("AddKnxDevice",function(a,b){a=a.query.data;require("x.hub.m.knx.js").addDevice(a,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("UptateKnxDevice",
  function(a,b){a=a.query.data;require("x.hub.m.knx.js").updateDevice(a,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("DeleteKnxDevice",function(a,b){a=a.query.data;require("x.hub.m.knx.js").deleteDevice(a,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:{}}))})});c.setCmdFunc("ListKnxMonitors",function(a,b){require("x.hub.m.knx.js").listMonitors(function(a){a.error?
  b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("SearchKnxIpGateways",function(a,b){require("x.hub.m.knx.js").searchKNXGateway(function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("DoZigbeeNativeCommandRaw",function(a,b){require("x.hub.m.zigbee.js").executeCommandNativeRaw(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,
  code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCmdFunc("ListZigbeeDevices",function(a,b){require("x.hub.m.zigbee.js").listDevices(a.query,function(a){a.error?b(JSON.stringify({XC_ERR:{msg:a.error.message,code:a.error.code}})):b(JSON.stringify({XC_SUC:a.data}))})});c.setCommandFunc("AddGroup",function(a,b){b.send("{XC_SUC}")});c.setCommandFunc("setTaskDeviceAddress",function(a,b){var c=a.query.device;a=a.query.address;c&&a&&devices[c]&&(devices[c].address=a,localStorage&&localStorage.setItem("xnm.aio.xhub.siegenia."+
  c,a));b.send("{XC_SUC}")});c.setCommandFunc("getTaskDeviceAddress",function(a,b){var c="{XC_ERR}";(a=a.query.device)&&devices[a]&&(c='{XC_SUC}{"address":"'+devices[a].address+'"}');b.send(c)});c.setCommandFunc("setAlarmGroup",function(a,b){for(var c in taskmanager._tasks)80<=c&&(taskmanager._tasks[c].active="1"==a.query.active?!0:!1);b.send("{XC_SUC}")});c.setCommandFunc("DelGroup",function(a,b){var c="{XC_ERR}",d=parseInt(a.query.id),k=parseInt(a.query.nid);taskmanager._tasks[d]&&a.query.nid&&(taskmanager._tasks[k]=
  taskmanager._tasks[d],delete taskmanager._tasks[d],c="{XC_SUC}");b.send(c)});c.setCommandFunc("saveGroup",function(a,b){var c="{XC_ERR}",d=parseInt(a.query.id);taskmanager._tasks[d]&&(taskmanager._tasks[d].active="1"==a.query.active?!0:!1,c="{XC_SUC}");b.send(c)});c.setCommandFunc("GetAll",function(a,b){a="";var c=1,d=1,k;for(k in taskmanager._tasks){var f=taskmanager._tasks[k],m="0";f.active&&(m="1");var g="",h="",l;for(l=0;l<f.trigger.length;l++)h+=XC.getHexVal(c,2),""!=a&&(a+=","),a+='{"sys":"EVENT","id":"'+
  XC.getHexVal(c++,2)+'","code":""}';for(l=0;l<f.action.length;l++)g+=XC.getHexVal(d,2),""!=a&&(a+=","),a+='{"sys":"ACTION","id":"'+XC.getHexVal(d++,2)+'","code":""}';""!=a&&(a+=",");a+='{"sys":"GROUP","id":"'+XC.getHexVal(k,2)+'","name":"'+f.name+'","active":"'+m+'","triggerids":"'+h+'","actionids":"'+g+'"}'}b.send("{XC_SUC}["+a+"]")});return c}
  function _setupAutomationManagerMode(c){function g(a){var b=require("crypto"),c=new Buffer("fO4gAeDjh4HwO0D8+/9Bfw==","base64"),d=new Buffer("+ubtPBJR9uejkjXiN6c1Bg==","base64");b=b.createDecipheriv("aes-128-cbc",c,d);b.setAutoPadding(!0);a=[b.update(new Buffer(a,"base64"))];a.push(b.final());return Buffer.concat(a).toString("utf8")}function d(a){if(!a)return 31*f(23,76)+2;try{var b=g(a);if(10>b.length||"t"!=b.charAt(0)||"a"!=b.charAt(2)||"k"!=b.charAt(9))return 31*f(23,76)+2;var c=b.charAt(1)+""+
  b.charAt(5)+""+b.charAt(6);return 31*parseInt(c)}catch(n){return 31*f(23,76)+2}}function f(a,b){a=Math.ceil(a);b=Math.floor(b);return Math.floor(Math.random()*(b-a))+a}var h=require("x.hub.taskman.js"),l=localStorage.getItem("info");h.taskManager.version=global.TASKMANAGER_VERSION;h.taskManager._mode=l?d(l):d();l=require("body-parser");c._app.use("/xhub/activate/do",l.text({limit:"100kb"}));c._app.post("/xhub/activate/req",function(a,b){global.TMP_TOKEN=f(1,5E3);setTimeout(function(){global.TMP_TOKEN=
  null},3E4);b.json({status:"success",data:global.TMP_TOKEN})});c._app.post("/xhub/activate/do",function(a,b){if(global.TMP_TOKEN)if(a.body)try{var c=g(a.body),f=""+global.TMP_TOKEN,k=c.substr(c.length-f.length);c.length<f.length||k!=f?b.json({status:"fail",message:"invalid token",code:0}):(localStorage.setItem("info",a.body),h.taskManager._mode=d(a.body),b.json({status:"success"}))}catch(p){b.json({status:"fail",message:"invalid request body",code:0})}else b.json({status:"fail",message:"no request body",
  code:0});else b.json({status:"fail",message:"token expired",code:0})})}
  function _setupDebugSite(c){var g=require("x.hub.fileman.js"),d=g.fileManager,f=require("express"),h=require("path"),l=require("ws").Server,a=h.join(__dirname,"site");c._app.use("/debug",f.static(a+"/debug"));c._app.use("/js",f.static(a+"/js"));this._wss=new l({server:c._httpserver,path:"/debug/tracker/ws"});this._wss.on("error",function(a){console.log("web socket server error:"+a.stack)}.bind(this));this._wss.on("connection",function(a){a.__watchDog=setTimeout(function(){a.close()},6E4);a.on("error",
  function(b){console.log("web socket error:"+b.stack);a.close()}.bind(this));a.on("close",function(){if(a.__tags){var b=require("x.logger.js");a.__tags.forEach(function(c){b.removeLogTracker(c,a.__tracker)})}a.__tail&&a.__tail.unwatch()});a.on("message",function(b,c){try{var e=JSON.parse(b);if("main"==e.system){var f=new (require("tail").Tail)(h.resolve(d.getUserLogPath(),"v5plus_daemon"));a.__tail=f;f.on("line",function(b){a.send(b+"\r\n")});f.on("error",function(a){console.log("ERROR: ",a)})}else{b=
  [];switch(e.system){case "homematic":b=["x.hub.m.hm","xnm.aio.hm"];break;case "knx":b=["x.hub.m.knx","xnm.aio.knx"];break;case "zwave":b=["x.hub.m.zway"];break;case "enocean":b=["x.hub.m.enocean"];break;case "zigbee":b=["x.hub.m.zigbee"];break;case "aio":b=["x.hub.m.gateway"];break;case "taskmanager":b=["x.hub.taskman"];break;case "script":b=["x.hub.scriptman"];break;case "rf":b=["x.hub.v5.USBSerial"]}if(0<b.length){a.__watchDog&&(clearTimeout(a.__watchDog),a.__watchDog=null);a.__tags=b;a.__tracker=
  function(b){a.send(b+"\r\n")};var m=require("x.logger.js");b.forEach(function(b){m.setLogTracker(b,a.__tracker)})}}}catch(q){a.send(JSON.stringify({error:q.message})),a.close()}}.bind(this))}.bind(this));c._app.get("/debug/tracker/log",function(a,c){switch(a.query.system){case "taskmanager":var b="v5p_taskmanager.log";break;case "homematic":b="v5p_homematic.log";break;case "knx":b="v5p_knx.log";break;case "zigbee":b="v5p_zigbee.log";break;case "zwave":b="v5p_zwave.log";break;case "enocean":b="v5p_enocean.log";
  break;case "aio":b="v5p_aiogateway.log";break;case "rf":b="v5p_rf_st.log";break;case "main":b="v5plus_daemon";break;default:c.status(404).send("system unknow")}a=h.join(g.fileManager.getUserLogPath(),b);c.sendFile(a)});a=h.join(__dirname,"site/debug/enocean");c._app.use("/debug/enocean/tracker",f.static(a));a=h.join(__dirname,"resources");c._app.use("/resources",f.static(a));this._wss=new l({server:c._httpserver,path:"/debug/enocean/ws"});this._wss.on("error",function(a){console.log("web socket server error:"+
  a.stack)}.bind(this));this._wss.on("connection",function(a){console.log("web socket connected");var b={onFrame:function(b,c){a.send("+++++++++++++++++++++++++++++++++\r\n");a.send("EnOcean Frame:");a.send(c+"\r\n");a.send(JSON.stringify(b.toJSON())+"\r\n");a.send("+++++++++++++++++++++++++++++++++\r\n")},onTelegram:function(b){a.send("########################################################\r\n");a.send("EnOcean Telegram:\r\n");a.send(JSON.stringify(b.toJSON())+"\r\n");a.send("########################################################\r\n")},
  onResolveEvents:function(b,c){a.send("===============================\r\n");a.send("Resolved Events from:"+b+"\r\n");c.forEach(function(b){a.send(JSON.stringify(b)+"\r\n")});a.send("===============================\r\n")}},c=require("x.hub.m.enocean.js");c.__addTelegramTracker(b);a.on("error",function(b){console.log("web socket error:"+b.stack);a.close()}.bind(this));a.on("close",function(){c.__removeTelegramTracker(b)});a.on("message",function(a,b){}.bind(this))}.bind(this));this._wss2=new l({server:c._httpserver,
  path:"/siegenia/enocean/windowconfig"});this._wss2.on("error",function(a){console.log("web socket server error:"+a.stack)}.bind(this));this._wss2.on("connection",function(a){var b=require("x.hub.m.enocean.js");a.__watchDog=setTimeout(function(){a.close()},3E5);a.on("error",function(c){console.log("web socket error:"+c.stack);b._siegeniaHandler.stopCalibateWindow();a.close()}.bind(this));a.on("close",function(){clearTimeout(a.__watchDog);b._siegeniaHandler.stopCalibateWindow()});a.on("message",function(c,
  d){try{var e=JSON.parse(c);"start"==e.command&&(b._siegeniaHandler.startCalibateWindow(e.windowID,function(b,c,d){b?a.send(JSON.stringify({error:b.message})):a.send(JSON.stringify({windowID:c,message:d}))}),b._siegeniaHandler.configWindow(e.params,e.windowID,function(b){b&&a.send(JSON.stringify({error:b.message,code:b.code}))}))}catch(m){a.send(JSON.stringify({error:m.message}))}}.bind(this))}.bind(this));this._wss3=new l({server:c._httpserver,path:"/zwave2/inclusion"});this._wss3.on("error",function(a){console.log("web socket server zwaveinclusion error:"+
  a.stack)}.bind(this));this._wss3.on("connection",function(a){var b=require("x.hub.m.zway.js");a.__watchDog=setTimeout(function(){a.close()},3E5);a.on("error",function(b){console.log("web socket error:"+b.stack);a.close()}.bind(this));a.on("close",function(){clearTimeout(a.__watchDog)});a.on("message",function(c,d){try{var e=JSON.parse(c);"start"==e.command?b.learnDevice(null,function(b,c,d){a.send(JSON.stringify({progress:b,subprogress:c,message:d}))},function(b){b.error?a.send(JSON.stringify({finish:!0,
  error:b.error.message,code:b.error.code,device:b.data})):a.send(JSON.stringify({finish:!0,device:b.data}));a.close()}):"updateInterview"==e.command&&(e.address?b.updateInterview(e.address,e.instanceID,e.commandClassID,function(b,c,d){a.send(JSON.stringify({progress:b,subprogress:c,message:d}))},function(b){b.error?a.send(JSON.stringify({finish:!0,error:b.error.message,code:b.error.code,device:b.data})):a.send(JSON.stringify({finish:!0,device:b.data}));a.close()}):a.send(JSON.stringify({finish:!0,
  error:"no address parameter",code:"08999"})))}catch(m){a.send(JSON.stringify({error:m.message}))}}.bind(this))}.bind(this));this._wss4=new l({server:c._httpserver,path:"/taskman/tracker"});this._wss4.on("error",function(a){console.log("web socket server error:"+a.stack)}.bind(this));this._wss4.on("connection",function(a){var b=require("url").parse(a.upgradeReq.url);b=require("querystring").parse(b.query);b.taskID||a.close();a.__taskID=b.taskID;a.__watchDog=setTimeout(function(){a.close()},6E4);a.__tmListener=
  function(b){a.send(b+"\r\n")};var c=require("x.hub.taskman.js");c.startTaskTrace(a.__taskID,a.__tmListener,function(b){b&&b.error&&(a.send(JSON.stringify({error:b.error.message})),a.close())});a.on("error",function(b){console.log("web socket error:"+b.stack);a.close()}.bind(this));a.on("close",function(){a.__taskID&&a.__tmListener&&c.stopTaskTrace(a.__taskID,a.__tmListener)});a.on("message",function(b,c){try{JSON.parse(b).alive&&(a.__watchDog&&(clearTimeout(a.__watchDog),a.__watchDog=null),a.__watchDog=
  setTimeout(function(){a.close()},6E4))}catch(m){a.send(JSON.stringify({error:m.message})),a.close()}}.bind(this))}.bind(this))}_loadCompilerConfig();_loadProgrammEnv();_loadConfigFile();_loadRuntimeConfig();var fm=require("x.hub.fileman.js");
  fm.init("A1"==global.HARDWARE_VERSION?"NEO Server":"v5plus",function(){var c=fm.fileManager,g=require("node-localstorage").LocalStorage;if("EA"==global.HARDWARE_VERSION)fs.existsSync("./data")||fs.mkdirSync("./data"),localStorage=new g("./data/localstorage"),fs.existsSync("./localstorage")&&fs.rmdirRecursiveSync("./localstorage");else if("A1"==global.HARDWARE_VERSION&&!hasLocalStorage)try{localStorage=new g(c.getUserRootDataPath()+path.sep+"localstorage")}catch(d){}require("x.hub.logman.js").init(c,
  function(){var d=_setupServer();_setupDebugSite(d);if("EA"==global.HARDWARE_VERSION&&"A20"==global.PLATFORM){console.log((new Date).toString()+" ===========> LED Start Sequence");var f=new miot.STMUpdater;f.hostType=d.hostType;f.resetST();setTimeout(function(){d.startSTM(function(c){d.doSTMCommand("XC_FNC=SendSC&type=RGB&data=040305")})},500);0==v5.Native.checkResetPin()&&(console.log((new Date).toString()+" ===========> reset button pressed, start safe mode"),global.SAFE_MODE=!0)}require("x.hub.resource.js").init(d._app,
  c);require("x.hub.deviceman.js").init(d._app,c,function(){require("x.hub.macroman.js").init(d._app,c);require("x.hub.scriptman.js").init(d._app,d._httpserver);require("x.hub.commandman.js").init(d._app);var f=require("x.hub.taskman.js");global.SAFE_MODE&&(console.log("!!! run task manager in safe mode"),f.lock());f.init();require("x.hub.sysvarman.js").init(d._app,c);"A1"==global.HARDWARE_VERSION&&_setupAutomationManagerMode(d);d.startWebserver(global.WEB_SERVER_PORT,function(){"EA"==global.HARDWARE_VERSION&&
  "A20"==global.PLATFORM&&d.doSTMCommand("XC_FNC=SendSC&type=RGB&data=0400")});d.enableCloudConnect(new v5.CloudConnect);"A20"==global.PLATFORM&&"EA"==global.HARDWARE_VERSION&&v5.Native.watchResetPin(d,function(a){XC.debugf("RESET: "+a);"reboot"==a?d.restart(0):"network"==a?v5.Native.resetNetwork(function(){d.restart(0)}):"passwords"==a?v5.reset(d,a,function(){d.restart(0)}):"factory"==a&&v5.reset(d,a,function(){v5.Native.resetHM(function(){v5.Native.resetZway(function(){v5.Native.resetZigbee(function(){v5.Native.resetNetwork(function(){d.restart(0)})})})})})})});
  "A20"==global.PLATFORM&&"EA"==global.HARDWARE_VERSION&&require("x.hub.datastore.js").init(c);require("x.hub.peripheralman.js").init(d._app,d._httpserver);require("x.hub.hubsyncman.js").init(d._app,c);var g=require("x.hub.moduleman.js");global.LOAD_MODULES.forEach(function(c){g.Modules.push(c)});g.init();g.initModules();f=require("xnm.aio.gateway.js");f._autoSearchInterval&&clearInterval(f._autoSearchInterval)})});process.on("uncaughtException",function(c){console.error(c.stack)});
  process.on("SIGINT",function(){console.log("Got SIGINT.");-1!=global.LOAD_MODULES.indexOf("knx")?require("x.hub.m.knx.js").clean(function(){console.log("SIGINT callback.");process.exit(1)}):process.exit(1)});process.on("SIGTERM",function(){console.log("Got SIGTERM.");-1!=global.LOAD_MODULES.indexOf("knx")?require("x.hub.m.knx.js").clean(function(){console.log("SIGINT callback.");process.exit(1)}):process.exit(1)});
  