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(f,c,a){f!=Array.prototype&&f!=Object.prototype&&(f[c]=a.value)};$jscomp.getGlobal=function(f){return"undefined"!=typeof window&&window===f?f:"undefined"!=typeof global&&null!=global?global:f};$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 f=0;return function(c){return $jscomp.SYMBOL_PREFIX+(c||"")+f++}}();
  $jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var f=$jscomp.global.Symbol.iterator;f||(f=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[f]&&$jscomp.defineProperty(Array.prototype,f,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(f){var c=0;return $jscomp.iteratorPrototype(function(){return c<f.length?{done:!1,value:f[c++]}:{done:!0}})};
  $jscomp.iteratorPrototype=function(f){$jscomp.initSymbolIterator();f={next:f};f[$jscomp.global.Symbol.iterator]=function(){return this};return f};$jscomp.iteratorFromArray=function(f,c){$jscomp.initSymbolIterator();f instanceof String&&(f+="");var a=0,b={next:function(){if(a<f.length){var g=a++;return{value:c(g,f[g]),done:!1}}b.next=function(){return{done:!0,value:void 0}};return b.next()}};b[Symbol.iterator]=function(){return b};return b};
  $jscomp.polyfill=function(f,c,a,b){if(c){a=$jscomp.global;f=f.split(".");for(b=0;b<f.length-1;b++){var g=f[b];g in a||(a[g]={});a=a[g]}f=f[f.length-1];b=a[f];c=c(b);c!=b&&null!=c&&$jscomp.defineProperty(a,f,{configurable:!0,writable:!0,value:c})}};$jscomp.polyfill("Array.prototype.keys",function(f){return f?f:function(){return $jscomp.iteratorFromArray(this,function(c){return c})}},"es6","es3");var x=x||{};x.hub=x.hub||{};x.hub.commandman=x.hub.commandman||{};
  x.hub.commandman.MacroExecutor=function(){var f=function(c,a,b){this._id=-1;this._commandHandler=c;this._callback=b;this._commands=[];this._currentCommand=0;this._canceling=!1;this._cancelCB=null;this._pause=250;if(a&&a.commands){"undefined"!=typeof a.pause&&null!==a.pause&&!isNaN(a.pause)&&0<=a.pause&&(this._pause=Math.max(Math.round(a.pause),1));this._commands=a.commands;c=[];for(a=this._commands.length-1;0<=a;a--)this._commands[a].removed||c.push(this._commands[a]);this._commands=c;window&&window.XCHost&&
  window.XCHost.getType&&"iOS"==window.XCHost.getType()&&XC.callHost("SYSTEM","startBGThread");this._executeNextCommand(!0)}};f.prototype.cancel=function(c){this._canceling=!0;this._cancelCB=c};f.prototype._executeNextCommand=function(c){if(this._canceling){this._canceling=!1;var a=this._cancelCB;this._cancelCB=null;c=this._callback;this._callback=null;a&&a();c&&c(Error("canceld"))}else if(this._commandHandler&&0<this._commands.length){a=this._commands.pop();var b=this;if("command"==a.classid){var g=
  {cmd:a.action.ref,device:a.action.device};g.cmd||(g.cmd={value:a.action.value});g.cmd&&null!==a.action.ext&&"undefined"!=typeof a.action.ext&&(g.cmd.ext=a.action.ext);a.action.path&&(g.cmd.path=a.action.path);"http_request"==a.action.type?this._commandHandler._doHTTPRequest(a.action.value,function(){b._executeNextCommand()}):c?this._commandHandler._executeCommand(g,function(){b._executeNextCommand()}):setTimeout(function(){b._commandHandler._executeCommand(g,function(){b._executeNextCommand()})},
  b._pause)}else"navigate"==a.classid?(c={type:null},1===a.history?c.type="page_next":-1===a.history?c.type="page_prev":a.page?(c.type="navigate",c.data=a.page):c.type="refresh",b._commandHandler._doAction(c),setTimeout(function(){b._executeNextCommand(!0)},b._pause)):"sleep"==a.classid&&setTimeout(function(){b._executeNextCommand(!0)},a.time)}else this._callback&&this._callback()};return f}();
  x.hub.commandman.CommandHandler=function(){var f=function(a){try{var b=JSON.parse(JSON.stringify(a));"undefined"!=typeof b.username&&null!=b.username&&(b.username="xxxxxx");"undefined"!=typeof b.password&&null!=b.password&&(b.password="xxxxxx");return b}catch(g){return a}},c=function(a,b){this._logger=require("x.logger.js").getLogger("x.hub.commandman.CommandHandler");this._id=b;this._commandHandler=require("m.aio.commandhandler.js").CentralHandler;this._deviceManager=a;this._deviceManager||(this._deviceManager=
  require("./x.hub.deviceman.js").deviceManager);this._macroExecutors=[]};c.prototype.init=function(a,b){this._logger.log("info","init command manager");b&&b()};c.prototype.executeCommandWithRef=function(a,b,g,d,e){var h,q=this._deviceManager;if(a&&b){var c=q.findDevice(a,b);if(!c){e&&e({error:Error("device not found")});return}c.info&&c.info.gateway&&(h=q.findGatewayWithIndex(c.info.gateway))}else if(g){if(h=q.findGateway(g),!h){e&&e({error:Error("gateway not found")});return}}else{e&&e({error:Error("device/gateway reference invalid")});
  return}if(c&&c.info){var f=JSON.parse(JSON.stringify(c.info));f.deviceName=b}if(h&&h.info){var m=JSON.parse(JSON.stringify(h.info));m.gatewayName=g;m.__neoInfo={db:this._id,index:h.index}}this.executeCommand(f,m,d,e)};c.prototype.getStateWithRef=function(a,b,g,d,e){var h,c=this._deviceManager;if(a&&b){var f=c.findDevice(a,b);if(!f){e&&e({error:Error("device not found")});return}f.info&&f.info.gateway&&(h=c.findGatewayWithIndex(f.info.gateway))}else if(g){if(h=c.findGateway(g),!h){e&&e({error:Error("gateway not found")});
  return}}else{e&&e({error:Error("device/gateway reference invalid")});return}if(f&&f.info){var l=JSON.parse(JSON.stringify(f.info));l.deviceName=b}if(h&&h.info){var m=JSON.parse(JSON.stringify(h.info));m.gatewayName=g;m.__neoInfo={db:this._id,index:h.index}}this.getState(l,m,d,e)};c.prototype.executeCommandWithIdx=function(a,b,g,d){var e,h=this._deviceManager;if(a){var c=h.findDeviceWithIndex(a);if(!c){d&&d({error:Error("device not found")});return}c.info&&c.info.gateway&&(e=h.findGatewayWithIndex(c.info.gateway))}else if(b){if(e=
  h.findGatewayWithIndex(b),!e){d&&d({error:Error("gateway not found")});return}}else{d&&d({error:Error("device/gateway reference invalid")});return}if(c&&c.info){var f=JSON.parse(JSON.stringify(c.info));f.deviceName=c.name}if(e&&e.info){var l=JSON.parse(JSON.stringify(e.info));l.gatewayName=e.name;l.__neoInfo={db:this._id,index:e.index}}this.executeCommand(f,l,g,d)};c.prototype.getStateWithIdx=function(a,b,c,d,e){if(c&&Array.isArray(c))this.getStatesWithIdx(a,b,c,d,e);else{var h;e=this._deviceManager;
  if(a){var g=e.findDeviceWithIndex(a);if(!g){d&&d({error:Error("device not found")});return}g.info&&g.info.gateway&&(h=e.findGatewayWithIndex(g.info.gateway))}else if(b){if(h=e.findGatewayWithIndex(b),!h){d&&d({error:Error("gateway not found")});return}}else{d&&d({error:Error("device/gateway reference invalid")});return}if(g&&g.info){var f=JSON.parse(JSON.stringify(g.info));f.deviceName=g.name}if(h&&h.info){var l=JSON.parse(JSON.stringify(h.info));l.gatewayName=h.name;l.__neoInfo={db:this._id,index:h.index}}this.getState(f,
  l,c,d)}};c.prototype.getStatesWithIdx=function(a,b,c,d,e){var g;e=this._deviceManager;if(a){var f=e.findDeviceWithIndex(a);if(!f){d&&d({error:Error("device not found")});return}f.info&&f.info.gateway&&(g=e.findGatewayWithIndex(f.info.gateway))}else if(b){if(g=e.findGatewayWithIndex(b),!g){d&&d({error:Error("gateway not found")});return}}else{d&&d({error:Error("device/gateway reference invalid")});return}if(f&&f.info){var k=JSON.parse(JSON.stringify(f.info));k.deviceName=f.name}if(g&&g.info){var l=
  JSON.parse(JSON.stringify(g.info));l.gatewayName=g.name;l.__neoInfo={db:this._id,index:g.index}}a=[];for(b=0;b<c.length;b++)e=c[b],e.id&&e.value&&a.push({id:e.id,device:k,status:e});this.getMultiStatesLegacy(k,l,a,function(a){if(a.error)d&&d(a);else{var b={data:{}};a.data&&a.data.forEach(function(a){a&&a.id&&(b.data[a.id]=a.status)});d&&d(b)}})};c.prototype.executeCommand=function(a,b,c,d){if(a||b)if(c){var e=null;b&&b.sys&&(e=b.sys);!e&&a&&a.sys&&(e=a.sys);if(e){if(("aio"==e||"neoserver"==e)&&c&&
  "cfOn"==c.value||"cfOff"==c.value){if(!b||!b.__neoInfo||!b.__neoInfo.index){d&&d({});return}if(this._deviceManager.getOwnIdx()==b.__neoInfo.index){d&&d({});return}}if((e=require("x.hub.moduleman.js").modulemanager.getModule(e))&&e.executeCommand){var g={};a&&(g=JSON.parse(JSON.stringify(a)));b&&(g.gateway=JSON.parse(JSON.stringify(b)));this._logger.log("trace","do command:"+f(a));b&&this._logger.log("trace","do command:"+f(a));this._logger.log("trace","command:"+JSON.stringify(c));e.executeCommand(g,
  c,d)}else this.executeCommandLegacy(a,b,c,d)}else d&&d({error:Error("no sys parameter")})}else d&&d({error:Error("no command")});else d&&d({error:Error("no device or gateway")})};c.prototype.getState=function(a,b,c,d){if(!c||Array.isArray(c))this.getStates(a,b,c,d);else if(a||b)if(c){var e=null;b&&b.sys&&(e=b.sys);!e&&a&&a.sys&&(e=a.sys);if(e)if((e=require("x.hub.moduleman.js").modulemanager.getModule(e))&&e.getState){var g={};a&&(g=JSON.parse(JSON.stringify(a)));b&&(g.gateway=JSON.parse(JSON.stringify(b)));
  e.getState(g,c.value,function(a){d&&d(a)})}else this.getStateLegacy(a,b,c,d);else d&&d({error:Error("no sys parameter")})}else d&&d({error:Error("no command")});else d&&d({error:Error("no device or gateway")})};c.prototype.executeCommandLegacy=function(a,b,c,d){if(a||b)if(c){var e=null;b&&b.sys&&(e=b.sys);!e&&a&&a.sys&&(e=a.sys);if(e){var g=require("m.aio.modulemanager.js").getModule(e);if(g){var f;b&&(f=g.resolveGateway(b));b=null;var k=this._deviceManager;k&&(b=k.getDeviceInfo());!f&&a&&(f=g.resolveDevice(a,
  b));f?this._commandHandler.executeCommand(e,f,a,c,function(b,e){if(a&&"cam"==a.sys&&c&&"snapshot"==c.value&&!b&&e)try{require("x.hub.camman.js").saveSnapshot(a,e,function(){})}catch(n){}d&&d({error:b,data:e})}):d&&d(Error("can not generate host"))}else d&&d({error:Error("no module can handle sys:"+e)})}else d&&d({error:Error("no sys parameter")})}else d&&d({error:Error("no command")});else d&&d({error:Error("no device or gateway")})};c.prototype.getStateLegacy=function(a,b,c,d){if(a||b)if(c){var e=
  null;b&&b.sys&&(e=b.sys);!e&&a&&a.sys&&(e=a.sys);if(e){var g=require("m.aio.modulemanager.js").getModule(e);if(g){var f;b&&(f=g.resolveGateway(b));b=null;var k=this._deviceManager;k&&(b=k.getDeviceInfo());!f&&a&&(f=g.resolveDevice(a,b));f?this._commandHandler.getStates(e,f,[{id:"alias",device:a,status:c}],function(a,b){a?d&&d(a):(a=null,b[0]&&(a=b[0].status),d&&d({data:{value:a}}))}):d&&d({error:Error("can not generate host")})}else d&&d({error:Error("no module can handle sys:"+e)})}else d&&d({error:Error("no sys parameter")})}else d&&
  d({error:Error("no status")});else d&&d({error:Error("no device or gateway")})};c.prototype.getStates=function(a,b,c,d){if(a||b){var e=null;b&&b.sys&&(e=b.sys);!e&&a&&a.sys&&(e=a.sys);if(e)if((e=require("x.hub.moduleman.js").modulemanager.getModule(e))&&e.updateStates){var g={};a&&(g=JSON.parse(JSON.stringify(a)));b&&(g.gateway=JSON.parse(JSON.stringify(b)));e.updateStates(g,function(a){d&&d(a)},c)}else this.getStatesLegacy(a,b,c,d);else d&&d({error:Error("no sys parameter")})}else d&&d({error:Error("no device or gateway")})};
  c.prototype.getStatesLegacy=function(a,b,c,d){if(a||b){var e=null;b&&b.sys&&(e=b.sys);!e&&a&&a.sys&&(e=a.sys);if(e){var g=require("m.aio.modulemanager.js").getModule(e);if(g){var f;b&&(f=g.resolveGateway(b));b=null;var k=this._deviceManager;k&&(b=k.getDeviceInfo());!f&&a&&(f=g.resolveDevice(a,b));f?this._commandHandler.getStatesForSingleDevice(e,f,a,c,function(a,b){a?d&&d(a):d&&d({data:b})}):d&&d({error:Error("can not generate host")})}else d&&d({error:Error("no module can handle sys:"+e)})}else d&&
  d({error:Error("no sys parameter")})}else d&&d({error:Error("no device or gateway")})};c.prototype.getMultiStatesLegacy=function(a,b,c,d){if(a||b)if(c){var e=null;b&&b.sys&&(e=b.sys);!e&&a&&a.sys&&(e=a.sys);if(e){var g=require("m.aio.modulemanager.js").getModule(e);if(g){var f;b&&(f=g.resolveGateway(b));b=null;var k=this._deviceManager;k&&(b=k.getDeviceInfo());!f&&a&&(f=g.resolveDevice(a,b));f?this._commandHandler.getStates(e,f,c,function(a,b){a?d&&d(a):d&&d({data:b})}):d&&d({error:Error("can not generate host")})}else d&&
  d({error:Error("no module can handle sys:"+e)})}else d&&d({error:Error("no sys parameter")})}else d&&d({error:Error("no device list")});else d&&d({error:Error("no device or gateway")})};c.prototype.execute=function(a,b,c,d,e){this._handler.execute(a,b,c,d,e)};c.prototype._executeCommand=function(a,b){a&&a.device&&a.cmd?a.device.name&&a.device.room?this.executeCommandWithRef(a.device.room,a.device.name,null,a.cmd,b):a.device.name?this.executeCommandWithRef(null,null,a.device.name,a.cmd,b):b&&b({error:Error("cmd object has no valid device")}):
  b&&b({error:Error("cmd object format invalid")})};c.prototype._doAction=function(a,b){b&&b({})};c.prototype._doHTTPRequest=function(a,b){var c=String(a).toLowerCase();0===c.indexOf("http:")||0===c.indexOf("https:")?(a=require("url").parse(a),a=("https:"==a.protocol?require("https"):require("http")).request({host:a.hostname,method:"GET",path:a.path,port:a.port,protocol:a.protocol},function(a){b&&b()}),a.on("error",function(a){XC.debugf(a);b&&b()}),a.end()):(0<a.indexOf("://")&&window.XC&&window.XC.callHost&&
  window.XC.callHost("SYSTEM","startApp",{scheme:a}),b&&b())};c.prototype.executeMacro=function(a,b,c){var d=this,e=new x.hub.commandman.MacroExecutor(this,a,function(a){for(var c=-1,f=0;f<d._macroExecutors.length;f++)if(d._macroExecutors[f]==e){c=1;break}-1!=c&&d._macroExecutors.slice(c,1);b&&b({error:a})});e._id=this._macroExecutors.length+1;this._macroExecutors.push(e);c&&c({id:e._id})};c.prototype.cancelMacro=function(a,b){for(var c=null,d=-1,e=0;e<this._macroExecutors.length;e++){var f=this._macroExecutors[e];
  if(f&&f._id==a){d=e;c=f;break}}c?(-1!=d&&this._macroExecutors.slice(d,1),c.cancel(function(){b&&b({})})):b&&b()};c.prototype.updateGeneralDeviceStates=function(a,b){var c=this;a||(a=1E4);this._deviceManager.getAllGeneralDevice(function(d,e){if(d)b&&b(d);else if(e&&0!=e.length){var f={};d=[];for(var g=0;g<e.length;g++){var k=e[g];if(k._origin&&k._origin.info&&k.details&&k.details.states){var l=k._origin;l.states=k.details.states;k._origin.info.gateway?(k=k._origin.info.gateway,f[k]||(f[k]=[]),f[k].push(l)):
  d.push(l)}}var m=b,n={};e=Object.keys(f);var p=0,r=e.length+d.length;setTimeout(function(){m&&(m(null,n),m=null)},a);e.forEach(function(a){c._updateGeneralGatewayDeviceStates(a,f[a],function(a,b){if(!a&&b)for(var d in b)n[d]=b[d];p++;p==r&&m&&(m(null,n),m=null)})});d.forEach(function(a){c._updateGeneralIPDeviceStats(a,function(a,b,d){!a&&d&&(n[b]=d);p++;p==r&&m&&(m(null,n),m=null)})})}else b&&b(null,{})})};c.prototype._updateGeneralGatewayDeviceStates=function(a,b,c){var d=this._deviceManager.findGatewayWithIndex(a);
  if(d)if(d.info){d=JSON.parse(JSON.stringify(d.info));d.__neoInfo={db:this._id,index:a};a=[];for(var e=0;e<b.length;e++){var f=b[e];if(f&&f.info&&f.states)for(var g in f.states)a.push({id:f.index+":"+g,device:f.info,status:f.states[g]})}this._updateGeneralStates(null,d,a,function(a,b){if(a)c&&c(a);else{a={};if(b)for(var d=0;d<b.length;d++){var e=b[d];if(e.id){var f=e.id.indexOf(":");if(-1!=f){var g=parseInt(e.id.substr(0,f));if(f=e.id.substr(f+1))a[g]||(a[g]={}),a[g][f]=e.status}}}c&&c(null,a)}})}else c&&
  c(Error("invalid gateway json"));else c&&c(Error("no such gateway"))};c.prototype._updateGeneralStates=function(a,b,c,d){if(a||b)if(c){var e=null;b&&b.sys&&(e=b.sys);!e&&a&&a.sys&&(e=a.sys);if(e){var f=require("x.hub.moduleman.js").modulemanager.getModule(e);if(f&&f.updateGeneralStates)e={},a&&(e=JSON.parse(JSON.stringify(a))),b&&(e.gateway=JSON.parse(JSON.stringify(b))),f.updateGeneralStates(deviceJSON,gatewayJSON,c,function(a){d&&d(a)});else if(f=require("m.aio.modulemanager.js").getModule(e)){var g;
  b&&(g=f.resolveGateway(b));b=null;var k=this._deviceManager;k&&(b=k.getDeviceInfo());!g&&a&&(g=f.resolveDevice(a,b));g?this._commandHandler.getStates(e,g,c,function(a,b){d&&d(a,b)}):d&&d({error:Error("can not generate host")})}else d&&d({error:Error("no module can handle sys:"+e)})}else d&&d({error:Error("no sys parameter")})}else d&&d({error:Error("no device list")});else d&&d({error:Error("no device or gateway")})};return c}();
  x.hub.commandman.CommandHandlerV6=function(){var f=function(){this._logger=require("x.logger.js").getLogger("x.hub.commandman.CommandHandlerV6")};f.prototype.executeCommand=function(c,a,b){if(c)if(a){var f=null,d=null,e=null,h=!1;c.device&&(f=c.device.sys,d=c.device.address);"undefined"!=typeof a.value&&null!=a.value&&(e=a.value);a=a.command;c="";if("HM"==f&&""!=d){if("A20"==global.PLATFORM||"MAC"==global.PLATFORM)c=a,"temperature"==a&&(c="tempTo"+e),a=require("x.hub.m.hm.js"),h=!0,a.executeCommandLegacy(null,
  d,c,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))})}else"ENOCEAN"!=f||""==d||"A20"!=global.PLATFORM&&"MAC"!=global.PLATFORM||(c=a,"temperature"==a&&(c="tempTo"+e),h=!0,require("x.hub.m.enocean.js").executeCommandLegacy(null,d,c,function(a){a.error?b(JSON.stringify({XC_ERR:{code:"001000",msg:a.error.message}})):b(JSON.stringify({XC_SUC:{}}))}));h||b(JSON.stringify({XC_ERR:{code:"001000",msg:"do support this command"}}))}else b&&b(Error("invalid command json"));
  else b&&b(Error("invalid device json"))};return f}();
  x.hub.commandman.Handler=function(){var f=function(){this.commandHandler=new x.hub.commandman.CommandHandler(require("./x.hub.deviceman.js").deviceManager,1);this.commandHandler2=new x.hub.commandman.CommandHandler(require("./x.hub.deviceman.js").deviceManager2,2);this.commandHandlerV6=new x.hub.commandman.CommandHandlerV6};f.prototype.CommandHandler=x.hub.commandman.CommandHandler;f.prototype.init=function(c,a){this._config(c);this.commandHandler.init(a)};f.prototype._config=function(c){var a=require("body-parser");
  c.use("/xhub/commandman",a.json({limit:"50mb"}));c.post("/xhub/commandman/executeCommand",function(a,c){this.commandHandler.executeCommand(a.body.device,a.body.gateway,a.body.command,function(a){c.json(this._toRestfulResponse(a.error,"ok"))}.bind(this))}.bind(this));c.post("/xhub/commandman/getState",function(a,c){this.commandHandler.getState(a.body.device,a.body.gateway,a.body.status,function(a){c.json(this._toRestfulResponse(a.error,a.data))}.bind(this))}.bind(this))};f.prototype._toRestfulResponse=
  function(c,a){return c?{status:"fail",message:c.message,code:c.code?c.code:0}:{status:"success",data:a}};return f}();module.exports=new x.hub.commandman.Handler;
  