text: var xnm=xnm||{};xnm.aio=xnm.aio||{};xnm.aio.moehlenhoff=xnm.aio.moehlenhoff||{};xnm.aio.moehlenhoff.Alpha2Device=function(){var d=function(a){this._address=a.address;this._name=a.name};d.prototype.toJSON=function(){return{sys:xnm.aio.moehlenhoff.Alpha2.DM.SYS,address:this._address,name:this._name,dpt:"DEVICE"}};return d}();
  xnm.aio.moehlenhoff.Alpha2HeatArea=function(){var d=function(a){this._address=a.address;this._dpt=a.dpt;this._name=a.name;this._number=a.number;this._iodevice=a.iodevice};d.prototype.toJSON=function(){return{sys:xnm.aio.moehlenhoff.Alpha2.DM.SYS,address:this._address,dpt:this._dpt,name:this._name,number:this._number,iodevice:this._iodevice}};return d}();
  xnm.aio.moehlenhoff.Alpha2=function(){var d=function(a,c){this._logger="undefined"==typeof require||null==require?{log:function(){}}:require("x.logger.js").getLogger("xnm.aio.moehlenhoff.Alpha2");this._ip=a;this._port=c;if(!this._port||0>this._port)this._port=80};d.prototype.executeCommand=function(a,c,b){var e=a.address.split(":");a=2<=e.length?{id:a.id,type:a.type,address:e[0],dpt:a.data,number:e[1]}:null;this._executeCommand(a,c,b)};d.prototype.getStates=function(a,c,b){var e=function(a,b){if(!b||
  !b.Devices)return null;if(b.Devices.Device)return b.Devices.Device.ID==a?b.Devices.Device:null;if(b.Devices.Devices)for(var c=b.Devices.Devices,e=0;e<c.length;e++){var f=c[e];if(f.ID==a)return f}return null},f=this;c=function(a){for(var b=[],c=0;c<a.length;c++){var e=a[c],f=e.address.split(":");2<=f.length&&b.push({id:e.id,type:e.type,address:f[0],dpt:e.data,number:f[1]})}return b}(c);this._getInfo(function(d,g){if(d)b&&b("Error");else{var h,l;if(c&&a.setState)for(var m=0;m<c.length;m++){var n=c[m];
  if(h=e(n.address,g))switch(n.dpt){case "HEATAREA":var p;a:{if(h&&h.HEATAREAs)for(p=0;p<h.HEATAREAs.length;p++){var q=h.HEATAREAs[p];if(q.NUMBER==n.number){p=q;break a}}p=null}if(p)for(l in h=f._getStateValues(n,p,h),h)h.hasOwnProperty(l)&&a.setState(n.id+":"+l,h[l])}}b&&b("OK")}})};d.prototype._executeCommand=function(a,c,b){if(a)if(a.address)if(c){var e='<?xml version="1.0" encoding="UTF-8"?><Devices><Device><ID>'+a.address+"</ID>%subdev</Device></Devices>";"vac_off"==c&&(e=e.replace("%subdev","<VACATION><VACATION_STATE>0</VACATION_STATE><START_DATE>2000-00-00</START_DATE><END_DATE>2000-00-00</END_DATE></VACATION>"));
  switch(a.dpt){case "HEATAREA":if(null==a.number||"undefined"==typeof a.number){b&&b(Error("device number invalid"));return}a='<HEATAREA nr="'+a.number+'">%cmd</HEATAREA>';e=e.replace("%subdev",a);switch(c){case "auto":c="<HEATAREA_MODE>0</HEATAREA_MODE>";break;case "day":c="<HEATAREA_MODE>1</HEATAREA_MODE>";break;case "night":c="<HEATAREA_MODE>2</HEATAREA_MODE>";break;default:if("string"==typeof c&&c.match(/^w_p/)){c="<PROGRAM_WEEK>"+c.replace("w_p","")+"</PROGRAM_WEEK>";break}if("string"==typeof c&&
  c.match(/^we_p/)){c="<PROGRAM_WEEKEND>"+c.replace("we_p","")+"</PROGRAM_WEEKEND>";break}var f;"number"==typeof c?f=c/5:c.match(/^[-+]?[0-9]*\.?[0-9]+$/)?f=parseFloat(c/5):b&&b(Error("no such command"));5>f&&(f=5);30<f&&(f=30);c="<T_TARGET>"+f+"</T_TARGET>"}c&&(e=e.replace("%cmd",c))}this._doRequest({path:"/data/changes.xml",method:"POST"},e,function(a){b&&b(a)})}else b&&b(Error("command invalid"));else b&&b(Error("device address invalid"));else b&&b(Error("device address format invalid"))};d.prototype._getStates=
  function(a){var c=this;this._getInfo(function(b,e){if(b)a&&a("Error");else{var f=c._resolveInfo(e);a&&a(null,f)}})};d.prototype._resolveInfo=function(a){if(!a||!a.Devices)return null;var c,b=[];a.Devices.Device&&(c=this._resolveDevice(a.Devices.Device))&&b.push(c);if(a.Devices.Devices){a=a.Devices.Devices;for(var e=0;e<a.length;e++)(c=this._resolveDevice(a[e]))&&b.push(c)}return b};d.prototype._resolveDevice=function(a){if(!a)return null;var c=this._getStateValues(null,null,a);if(!c)return null;c.id=
  a.ID;c.heatAreas=[];if(a.HEATAREAs)for(var b=0;b<a.HEATAREAs.length;b++){var e=a.HEATAREAs[b],f=this._getStateValues(null,e,a);f&&(f.number=e.NUMBER,c.heatAreas.push(f))}return c};d.prototype.getDevices=function(a){this._getDevices(function(c,b){if(c)a&&a(c);else if(b){for(var e in b)if(b.hasOwnProperty(e))for(var f=b[e],d=0;d<f.length;d++)delete f[d]._deviceName;a&&a(null,b)}else a&&a(null,{})})};d.prototype._getDevices=function(a){this._getInfo(function(c,b){if(c)a&&a(c);else{var e={};if(b.Devices&&
  b.Devices.Devices){for(var f=b.Devices.Devices,d=0;d<f.length;d++){var g=f[d];if(g.ID){e[g.ID]=[];var h=g.NAME,l={};if(g.IODEVICEs)for(var m=0;m<g.IODEVICEs.length;m++){var n=g.IODEVICEs[m];n.HEATAREA_NR&&(l[n.HEATAREA_NR]=n)}if(g.HEATAREAs)for(m=0;m<g.HEATAREAs.length;m++)if(n=g.HEATAREAs[m],n.NUMBER){if(l[n.NUMBER]){var p=l[n.NUMBER].IODEVICE_TYPE;switch(p){case "1":case "3":case "4":p="analog";break;default:p="digital"}}e[g.ID].push({type:"alpha2",address:g.ID,dpt:"HEATAREA",name:n.HEATAREA_NAME,
  number:n.NUMBER,iodevice:p,_deviceName:h})}}}a&&a(null,e)}else a&&a(Error("info format invalid"))}})};d.prototype._getStateValues=function(a,c,b){a={};var e="\u00b0C",f={};if(b){if(b.VACATION){switch(b.VACATION.VACATION_STATE){case "0":a.vacation="off";break;default:a.vacation="on"}b.VACATION.START_DATE&&(a.vacation_start_date=b.VACATION.START_DATE);b.VACATION.START_TIME&&(a.vacation_start_time=b.VACATION.START_TIME);b.VACATION.END_DATE&&(a.vacation_end_date=b.VACATION.END_DATE);b.VACATION.END_TIME&&
  (a.vacation_end_time=b.VACATION.END_TIME)}b.TEMPERATUREUNIT&&"0"!=b.TEMPERATUREUNIT&&(e="\u00b0F");if(b.PROGRAM&&b.PROGRAM.SHIFT_PROGRAMs)for(var d=b.PROGRAM.SHIFT_PROGRAMs,g=0;g<d.length;g++){var h=d[g],l=h.NUMBER,m=h.START,h=h.END;l&&m&&h&&(a["prog_"+l]=a["prog_"+l]?a["prog_"+l]+(","+m+"-"+h):m+"-"+h)}if(b.IODEVICEs)for(d=0;d<b.IODEVICEs.length;d++)g=b.IODEVICEs[d],g.HEATAREA_NR&&(f[g.HEATAREA_NR]=g)}if(c){switch(c.HEATAREA_MODE){case "0":a.mode="auto";break;case "1":a.mode="day";break;case "2":a.mode=
  "night"}c.T_ACTUAL&&(a.actual_temp=parseFloat(c.T_ACTUAL),a.actual_temp_text=parseFloat(c.T_ACTUAL)+e);c.T_TARGET&&(a.target_temp=parseFloat(5*c.T_TARGET),a.target_temp_text=parseFloat(c.T_TARGET)+e);c.PROGRAM_WEEK&&(a.prog_week_0="inactive",a.prog_week_1="inactive",a.prog_week_2="inactive",a.prog_week_3="inactive",a["prog_week_"+parseInt(c.PROGRAM_WEEK)]="active");c.PROGRAM_WEEKEND&&(a.prog_weekend_0="inactive",a.prog_weekend_1="inactive",a.prog_weekend_2="inactive",a.prog_weekend_3="inactive",a["prog_weekend_"+
  parseInt(c.PROGRAM_WEEKEND)]="active");if(f&&f[c.NUMBER])switch(f[c.NUMBER].IODEVICE_TYPE){case "1":case "3":case "4":a.iodevice="analog";break;default:a.iodevice="digital"}}return a};d.prototype._getInfo=function(a){var c=this;this._doRequest({path:"/data/static.xml",method:"GET"},null,function(b,e){if(b)a&&a(b);else try{var f=$($.parseXML(e)),d=c._xml2json(f);a&&a(null,d)}catch(g){a&&a(g)}})};d.prototype._xml2json=function(a){var c=a.children();if(c&&0<c.length){a={};for(var b=0;b<c.length;b++){var e=
  $(c[b]),f=e.prop("tagName"),d=this._xml2json(e),g;if("HEATAREA"==f||"HEATCTRL"==f||"IODEVICE"==f)g=e.attr("nr"),null!=g&&"undefined"!=typeof g&&(d.NUMBER=g);"SHIFT_PROGRAM"==f&&(g=e.attr("nr"),e=e.attr("shiftingtime"),null!=g&&"undefined"!=typeof g&&(d.NUMBER=g),null!=e&&"undefined"!=typeof e&&(d.SHIFINGTIME=e));"Device"==f||"HEATAREA"==f||"HEATCTRL"==f||"IODEVICE"==f?(a[f+"s"]||(a[f+"s"]=[]),a[f+"s"].push(d)):a[f]&&!a[f+"s"]?(a[f+"s"]=[],a[f+"s"].push(a[f]),a[f+"s"].push(d),delete a[f]):!a[f]&&a[f+
  "s"]?a[f+"s"].push(d):a[f]=d}return a}return a.text()};d.prototype._doRequest=function(a,c,b){var e=b;a.host=this._ip;a.port=this._port;a.headers={"Content-Type":'text/xml; charset="UTF-8"',"User-Agent":"mediola",Connection:"close"};"POST"==a.method&&c&&(a.headers["Content-Length"]=c.length);var d=this,k="";b=require("http").request(a,function(a){a.setEncoding("utf8");a.on("data",function(a){k+=a});a.on("end",function(){var b;200!=a.statusCode&&(d._logger.log("warn","Failed to post request to "+d._ip+
  " with status code:"+a.statusCode),b=Error("http request failed with status code:"+a.statusCode));e&&(e(b,k),e=null)})});if(b.on&&"function"==typeof b.on)b.on("error",function(a){e&&e(a);e=null});"POST"==a.method&&c&&b.write(c);b.end()};d.prototype.getDevicesCreator=function(a){this._getDevices(function(c,b){if(c)a&&a(c);else{var e={},d=[];if(b){for(var k in b)if(b.hasOwnProperty(k)){var g=b[k];if(g)for(var h=0;h<g.length;h++){var l=g[h];l&&(l.address&&!e[l.address]&&(e[l.address]=new xnm.aio.moehlenhoff.Alpha2Device(l),
  e[l.address]._name=l._deviceName,d.push(e[l.address])),l=new xnm.aio.moehlenhoff.Alpha2HeatArea(l),d.push(l))}}a&&a(null,d)}}})};d.prototype.executeCommandCreator=function(a,c,b){if(a)if(c){var e=c.value;"target_temp"==e&&(e=5*c.ext);this._executeCommand(a,e,b)}else b&&b(Error("command in null"));else b&&b(Error("device in null"))};d.prototype.getStatesCreator=function(a,c,b){var e=function(a,b,c,e){a=function(a,b){if(!b.heatAreas)return null;for(var c=0;c<b.heatAreas.length;c++)if(b.heatAreas[c]&&
  b.heatAreas[c].number==a)return b.heatAreas[c];return null};if(!b.address||!c||!c.value)return null;e=function(a,b){for(var c=0;c<b.length;c++)if(b[c]&&b[c].id==a)return b[c];return null}(b.address,e);if(!e)return null;switch(b.dpt){case "HEATAREA":b=a(b.number,e);if(!b)return null;b=b[c.value];return"target_temp"==c.value?b/5:b;case "DEVICE":return e[c.value]}};this._getStates(function(a,d){if(a)b&&b(a);else{for(var g=[],h=0;h<c.length;h++){var l=c[h],m=e(l.id,l.device,l.status,d);m&&g.push({id:l.id,
  status:m})}b&&b(null,g)}})};d.prototype.toJSON=function(){return{sys:xnm.aio.moehlenhoff.Alpha2.DM.SYS,ip:this._ip,port:this._port}};d.prototype.equalsTo=function(a){return a&&a instanceof d?this._ip==a._ip&&this._port==a._port:!1};d.parseJSON=function(a){return a&&a.ip?new d(a.ip,a.port):null};return d}();
  xnm.aio.moehlenhoff.Alpha2.DM=function(){var d=function(a,b){this.code=a;this.message=b;this.stack=Error().stack};d.prototype=Error();d.prototype.name="Alpha2DMError";d.prototype.code=0;d.ERROR_CODE={DEFAULT:0,INDEX_EXISTS:1,ID_EXISTS:2,INVALID:3,UNKNOW:4,NOT_FOUND:5,IP_EXISTS:6};var a={alpha2:{DEVICE:{command:[{type:"enum",name:"vacation off",ref:{value:"vac_off"}}],status:[{type:"enum",name:"vacation",ref:{value:"vacation",options:["off","on"]}},{type:"string",name:"vacation start date",ref:{value:"vacation_start_date"}},
  {type:"string",name:"vacation start time",ref:{value:"vacation_start_time"}},{type:"string",name:"vacation end date",ref:{value:"vacation_end_date"}},{type:"string",name:"vacation end time",ref:{value:"vacation_end_time"}},{type:"string",name:"program 1",ref:{value:"prog_1"}},{type:"string",name:"program 2",ref:{value:"prog_2"}},{type:"string",name:"program 3",ref:{value:"prog_3"}},{type:"string",name:"program 4",ref:{value:"prog_4"}}]},HEATAREA:{command:[{type:"enum",name:"auto mode",ref:{value:"auto"}},
  {type:"enum",name:"day mode",ref:{value:"day"}},{type:"enum",name:"night mode",ref:{value:"night"}},{type:"enum",name:"week program 0",ref:{value:"w_p0"}},{type:"enum",name:"week program 1",ref:{value:"w_p1"}},{type:"enum",name:"week program 2",ref:{value:"w_p2"}},{type:"enum",name:"week program 3",ref:{value:"w_p3"}},{type:"enum",name:"weekend program 0",ref:{value:"we_p0"}},{type:"enum",name:"weekend program 1",ref:{value:"we_p1"}},{type:"enum",name:"weekend program 2",ref:{value:"we_p2"}},{type:"enum",
  name:"weekend program 3",ref:{value:"we_p3"}},{type:"float",name:"target temparature",ref:{value:"target_temp",ext:"%f",extMeta:"5-30",scale:"0.2"}}],status:[{type:"enum",name:"mode",ref:{value:"mode",options:["auto","day","night"]}},{type:"float",name:"actual temparature",ref:{value:"actual_temp"}},{type:"string",name:"actual temparature with unit",ref:{value:"actual_temp_text"}},{type:"float",name:"target temparature",ref:{value:"target_temp",extMeta:"5-30",scale:"0.2"}},{type:"string",name:"target temparature with unit",
  ref:{value:"target_temp_text"}},{type:"enum",name:"week program 0",ref:{value:"prog_week_0",options:["active","inactive"]}},{type:"enum",name:"week program 1",ref:{value:"prog_week_1",options:["active","inactive"]}},{type:"enum",name:"week program 2",ref:{value:"prog_week_2",options:["active","inactive"]}},{type:"enum",name:"week program 3",ref:{value:"prog_week_3",options:["active","inactive"]}},{type:"enum",name:"weekend program 0",ref:{value:"prog_weekend_0",options:["active","inactive"]}},{type:"enum",
  name:"weekend program 1",ref:{value:"prog_weekend_1",options:["active","inactive"]}},{type:"enum",name:"weekend program 2",ref:{value:"prog_weekend_2",options:["active","inactive"]}},{type:"enum",name:"weekend program 3",ref:{value:"prog_weekend_3",options:["active","inactive"]}}]}}};return{SYS:"alpha2",NEA_SMART_SYS:"neasmart",hasSys:function(a){return a==this.SYS||a==this.NEA_SMART_SYS},registModule:function(a){a.register(this.SYS,"moehlenhoff");a.register(this.NEA_SMART_SYS,"moehlenhoff")},getGatewayType:function(){return[{sys:this.SYS,
  name:"M\u00f6hlenhoff Alpha2",port:80},{sys:this.NEA_SMART_SYS,name:"REHAU Nea Smart",port:80}]},createGateway:function(a,b,e){b=d.ERROR_CODE;a?a.ip?e(null,a):e(new d(b.INVALID,"ip is invalid")):e(new d(b.INVALID,"info is invalid"))},updateGateway:function(a,b,e,f){a=d.ERROR_CODE;b?b.ip?f(null,b):f(new d(a.INVALID,"ip is invalid")):f(new d(a.INVALID,"update is invalid"))},deleteGateway:function(a,b,e){e()},createDevice:function(a,b,e){var f=d.ERROR_CODE;if(a.gateway)if(b.data&&b.data.gateways&&0!==
  b.data.gateways.length){b=b.data.gateways;var k,g;for(k=0;k<b.length;k++)if(b[k].index===a.gateway){g=b[k];break}g?e(null,a):e(new d(f.NOT_FOUND,"gateway with index "+a.gateway+" not exists"))}else e(new d(f.NOT_FOUND,"gateway with index "+a.gateway+" not exists"));else e(new d(f.INVALID,"gateway is invalid"))},updateDevice:function(a,b,e){var f=d.ERROR_CODE;if(a)if(a.gateway){b=b.data.gateways;var k,g;for(k=0;k<b.length;k++)if(b[k].index===a.gateway){g=b[k];break}g?e(null,a):e(new d(f.NOT_FOUND,
  "gateway with index "+a.gateway+" not exists"))}else e(new d(f.INVALID,"gateway is invalid"));else e(new d(f.INVALID,"info is invalid"))},deleteDevice:function(a,b,e){e()},getCommandStatusMap:function(c){if(!c||!c.sys||!c.dpt)return null;var b=c.sys;b==this.NEA_SMART_SYS&&(b=this.SYS);b=a[b];if(!b)return null;b=b[c.dpt];if("analog"==c.iodevice){c={command:[],status:b.status};for(var e=0;e<b.command.length;e++){var d=b.command[e];"target_temp"!=d.ref.value&&c.command.push(d)}b=c}return b}}}();
  xnm.aio.rehau=xnm.aio.rehau||{};xnm.aio.rehau.NeaSmartDevice=function(){var d=function(a){this._address=a.address;this._name=a.name};d.prototype.toJSON=function(){return{sys:xnm.aio.rehau.NeaSmart.DM.SYS,address:this._address,name:this._name,dpt:"DEVICE"}};return d}();
  xnm.aio.rehau.NeaSmartHeatArea=function(){var d=function(a){this._address=a.address;this._dpt=a.dpt;this._name=a.name;this._number=a.number;this._iodevice=a.iodevice};d.prototype.toJSON=function(){return{sys:xnm.aio.rehau.NeaSmart.DM.SYS,address:this._address,dpt:this._dpt,name:this._name,number:this._number,iodevice:this._iodevice}};return d}();xnm.aio.rehau.NeaSmart=function(d,a){xnm.aio.moehlenhoff.Alpha2.call(this,d,a);this._logger=require("x.logger.js").getLogger("xnm.aio.rehau.NeaSmart")};
  xnm.aio.rehau.NeaSmart.prototype=new xnm.aio.moehlenhoff.Alpha2;xnm.aio.rehau.NeaSmart.prototype.constructor=xnm.aio.rehau.NeaSmart;xnm.aio.rehau.NeaSmart.prototype.toJSON=function(){return{sys:xnm.aio.rehau.NeaSmart.DM.SYS,ip:this._ip,port:this._port}};xnm.aio.rehau.NeaSmart.prototype.equalsTo=function(d){return d&&d instanceof xnm.aio.rehau.NeaSmart?this._ip==d._ip&&this._port==d._port:!1};xnm.aio.rehau.NeaSmart.parseJSON=function(d){return d&&d.ip?new xnm.aio.rehau.NeaSmart(d.ip,d.port):null};
  xnm.aio.rehau.NeaSmart.prototype.getDevicesCreator=function(d){this._getDevices(function(a,c){if(a)d&&d(a);else{var b={},e=[];if(c){for(var f in c)if(c.hasOwnProperty(f)){var k=c[f];if(k)for(var g=0;g<k.length;g++){var h=k[g];h&&(h.address&&!b[h.address]&&(b[h.address]=new xnm.aio.rehau.NeaSmartDevice(h),b[h.address]._name=h._deviceName,e.push(b[h.address])),h=new xnm.aio.rehau.NeaSmartHeatArea(h),e.push(h))}}d&&d(null,e)}}})};xnm.aio.rehau.NeaSmart.DM={SYS:xnm.aio.moehlenhoff.Alpha2.DM.NEA_SMART_SYS};
  xnm.aio.moehlenhoff.DM=function(){var d=function(a,c){this.code=a;this.message=c;this.stack=Error().stack};d.prototype=Error();d.prototype.name="MoehlenhoffDMError";d.prototype.code=0;d.ERROR_CODE={DEFAULT:0,INDEX_EXISTS:1,ID_EXISTS:2,INVALID:3,UNKNOW:4,NOT_FOUND:5,IP_EXISTS:6};return{getGatewayType:function(a){var c=[],b;for(b in xnm.aio.moehlenhoff)if(xnm.aio.moehlenhoff.hasOwnProperty(b)){var e=xnm.aio.moehlenhoff[b];e&&e.DM&&e.DM.getGatewayType&&((e=e.DM.getGatewayType(a))&&Array.isArray(e)?c=
  c.concat(e):c.push(e))}return c},_getSystem:function(a){for(var c in xnm.aio.moehlenhoff)if(xnm.aio.moehlenhoff.hasOwnProperty(c)){var b=xnm.aio.moehlenhoff[c];if(b&&b.DM&&b.DM.SYS&&b.DM.SYS==a||b&&b.DM&&b.DM.hasSys&&b.DM.hasSys(a))return b}return null},createGateway:function(a,c,b){var e=d.ERROR_CODE;if(a)if(a.sys){var f=this._getSystem(a.sys);f&&f.DM&&f.DM.createGateway?f.DM.createGateway(a,c,b):b&&b(new d(e.INVALID,"no such sys:"+a.sys))}else b&&b(new d(e.INVALID,"sys is invalid"));else b&&b(new d(e.INVALID,
  "info is invalid"))},updateGateway:function(a,c,b,e){var f=d.ERROR_CODE;if(c)if(c.sys){var k=this._getSystem(c.sys);k&&k.DM&&k.DM.updateGateway?k.DM.updateGateway(a,c,b,e):e&&e(new d(f.INVALID,"no such sys:"+c.sys))}else e&&e(new d(f.INVALID,"sys is invalid"));else e&&e(new d(f.INVALID,"update is invalid"))},deleteGateway:function(a,c,b){var e=d.ERROR_CODE;if(a)if(a.sys){var f=this._getSystem(a.sys);f&&f.DM&&f.DM.deleteGateway?f.DM.deleteGateway(a,c,b):b&&b(new d(e.INVALID,"no such sys:"+a.sys))}else b&&
  b(new d(e.INVALID,"sys is invalid"));else b&&b()},createDevice:function(a,c,b){var e=d.ERROR_CODE;if(a)if(a.sys){var f=this._getSystem(a.sys);f&&f.DM&&f.DM.createDevice?f.DM.createDevice(a,c,b):b&&b(new d(e.INVALID,"no such sys:"+a.sys))}else b&&b(new d(e.INVALID,"sys is invalid"));else b&&b(new d(e.INVALID,"info is invalid"))},updateDevice:function(a,c,b){var e=d.ERROR_CODE;if(a)if(a.sys){var f=this._getSystem(a.sys);f&&f.DM&&f.DM.updateDevice?f.DM.updateDevice(a,c,b):b&&b(new d(e.INVALID,"no such sys:"+
  a.sys))}else b&&b(new d(e.INVALID,"sys is invalid"));else b&&b(new d(e.INVALID,"info is invalid"))},deleteDevice:function(a,c,b){var e=d.ERROR_CODE;if(a)if(a.sys){var f=this._getSystem(a.sys);f&&f.DM&&f.DM.deleteDevice?f.DM.deleteDevice(a,c,b):b&&b(new d(e.INVALID,"no such sys:"+a.sys))}else b&&b(new d(e.INVALID,"sys is invalid"));else b&&b()},applyUIFilter:function(a,c){var b=function(a,b){if("*"==a)return!0;for(var c=!1,e=0;e<a.length;e++)if(a[e]==b){c=!0;break}return c},e=function(a,c,e){var d=
  [];switch(e.catagory){case "command":a.command&&a.command.forEach(function(a){b(e.elems,a.type)&&(a=JSON.parse(JSON.stringify(a)),d.push(a))});break;case "status":a.status&&a.status.forEach(function(a){b(e.elems,a.type)&&(a=JSON.parse(JSON.stringify(a)),d.push(a))})}return d},d=function(a,b){var c=[],d=null,f;a.sys&&(d=this._getSystem(a.sys))&&d.DM&&d.DM.getCommandStatusMap&&(f=d.DM.getCommandStatusMap(a));f&&(d=e(f,a,b),c=c.concat(d));return c};if(!a.sys)return null;var k=JSON.parse(JSON.stringify(a)),
  g=null;switch(c.catagory){case "command":g=d.call(this,a,c);k.command=g;break;case "status":g=d.call(this,a,c);k.status=g;break;default:return null}return g&&0!=g.length?k:null}}}();
  xnm.aio.moehlenhoff.Handler=function(){var d=function(){var a=require("x.logger.js");xnm.aio.moehlenhoff.DM._logger=a?a.getLogger("xnm.aio.moehlenhoff.DM"):{log:function(){}}};d.prototype.Alpha2=xnm.aio.moehlenhoff.Alpha2;d.prototype.NeaSmart=xnm.aio.rehau.NeaSmart;d.prototype.getDeviceCommandList=function(a,c){var b=[];if("analog"==a.data||"digital"==a.data)b.push({id:window.XC_Text.auto,cmd:"auto"}),b.push({id:window.XC_Text.day,cmd:"day"}),b.push({id:window.XC_Text.night,cmd:"night"}),b.push({id:window.XC_Text.w_p0,
  cmd:"w_p0"}),b.push({id:window.XC_Text.w_p1,cmd:"w_p1"}),b.push({id:window.XC_Text.w_p2,cmd:"w_p2"}),b.push({id:window.XC_Text.w_p3,cmd:"w_p3"}),b.push({id:window.XC_Text.we_p0,cmd:"we_p0"}),b.push({id:window.XC_Text.we_p1,cmd:"we_p1"}),b.push({id:window.XC_Text.we_p2,cmd:"we_p2"}),b.push({id:window.XC_Text.we_p3,cmd:"we_p3"});if("digital"==a.data){var e=this.getDeviceCommandListDigital();b.push.apply(b,e)}return b};d.prototype.getDeviceCommandListDigital=function(){for(var a=[],c=4.8,b=24,e=0;126>
  e;e++)c+=.2,b++,a.push({id:window.XC_Text.target_temp+c.toFixed(1),cmd:b});return a};d.prototype.devicemanager=xnm.aio.moehlenhoff.DM;d.prototype.registModule=function(a){for(var c in xnm.aio.moehlenhoff)if(xnm.aio.moehlenhoff.hasOwnProperty(c)){var b=xnm.aio.moehlenhoff[c];b&&b.DM&&b.DM.registModule&&b.DM.registModule(a)}};d.prototype.resolveGateway=function(a){if(!a)return null;switch(a.sys){case xnm.aio.moehlenhoff.Alpha2.DM.SYS:return xnm.aio.moehlenhoff.Alpha2.parseJSON(a);case xnm.aio.moehlenhoff.Alpha2.DM.NEA_SMART_SYS:return xnm.aio.rehau.NeaSmart.parseJSON(a);
  default:return null}};d.prototype.getDeviceCommands=function(a,c){var b=xnm.aio.moehlenhoff.DM.applyUIFilter(a,{catagory:"command",elems:"*"}),b=b?b.command:[];c&&c(null,b)};d.prototype.getDeviceStatus=function(a,c){var b=xnm.aio.moehlenhoff.DM.applyUIFilter(a,{catagory:"status",elems:"*"}),b=b?b.status:[];c&&c(null,b)};d.prototype.getDevices=function(a,c){if(a){var b=this.resolveGateway(a);b?b.getDevicesCreator?b.getDevicesCreator(function(a,b){c&&c(a,b)}):c&&c(Error("gateway do not have getDevicesCreator function")):
  c&&c(Error("gatewayJSON invalid"))}else c&&c(Error("gatewayJSON is empty"))};d.prototype.doCommand=function(a,c,b,e){a?(a=this.resolveGateway(a))?a.executeCommandCreator(c,b,function(a){e&&e(a)}):e&&e(Error("gatewayJSON invalid")):e&&e(Error("gatewayJSON is empty"))};d.prototype.doStatus=function(a,c,b,e,d){c?(c=this.resolveGateway(c))?c.getStatesCreator(null,[{id:a,device:b,status:e}],function(a,b){a?d&&d(a):d&&d(null,b[0])}):d&&d(Error("gatewayJSON invalid")):d&&d(Error("gatewayJSON is empty"))};
  return d}();"undefined"!=typeof module&&null!=module&&(module.exports=new xnm.aio.moehlenhoff.Handler);
  