text: var m=m||{};m.aio=m.aio||{};m.aio.smartwidget=m.aio.smartwidget||{};
  m.aio.smartwidget.Handler=function(){this.supportSmartWidget=function(d,c){if(!d||!d.sys)return!1;if("hm"==d.sys){var a=require("xnm.aio.hm.js");a=a.devicemanager;return a.supportSmartWidget(d)}if("hue"==d.sys)return a=require("xnm.aio.hue.js"),a=a.devicemanager,a.supportSmartWidget(d);a=require("m.aio.modulemanager.js").getModule(d.sys);return(a=a.devicemanager)?a.toGeneralDevice&&a.toGeneralDevice(d)?!0:a.supportSmartWidget?a.supportSmartWidget(d,c):!1:!1};this.applySmartWidgetFilter=function(d,
  c,a,b){if(!d||!d.sys)return!1;if("hm"==d.sys){var f=require("xnm.aio.hm.js");f=f.devicemanager;return f.applySmartWidgetFilter(d,a,b)}if("hue"==d.sys)return f=require("xnm.aio.hue.js"),f=f.devicemanager,f.applySmartWidgetFilter(d,a,b);f=require("m.aio.modulemanager.js").getModule(d.sys);f=f.devicemanager;if(!f)return!1;var p;if(f.toGeneralDevice){var h=f.toGeneralDevice(d,null,null,c);if(h){var l=this._getSupportWidgetTypes(h);var g=this._getCommandMap(h),n=this._getStatusMap(h);h=this._getIconMap(h);
  l=this._injectToSmartWidgetTemplate(a,l,b,g,n,h)}}f.applySmartWidgetFilter&&(p=f.applySmartWidgetFilter(this,d,c,a,b));if(!l)return p;if(!p)return l;d=l;c=0;for(a=p.length;c<a;c++){b=p[c];h=!1;for(g=0;g<l.length;g++)if(f=l[g],b.meta&&f.meta&&b.meta.id==f.meta.id){h=!0;break}!h&&b&&d.push(b)}return d};this._getSupportWidgetTypes=function(d){var c=[];switch(d.type){case "switch":case "light":c.push("switch");break;case "dimmer":c.push("switch");c.push("dimmer");d.commands&&(d.commands.color||d.commands.colorTemperature)&&
  c.push("rgb");break;case "blind":d.commands&&(d.commands.rotation||d.commands.lamellaUp||d.commands.lamellaDown)&&c.push("blind");c.push("shutter");break;case "motion":c.push("motion");break;case "smoke":c.push("smoke");break;case "door":c.push("contact");break;case "powermeter":c.push("powermeter");break;case "temperature":c.push("climate");break;case "weatherstation":c.push("weather_station");c.push("climate");break;case "powerswitch":c.push("switch");c.push("powermeter");break;case "heater":c.push("thermostat");
  break;case "water":c.push("sensor_water");break;case "window":c.push("window");break;case "co2":c.push("sensor_co2");break;case "rain":c.push("rain");break;case "brightness":c.push("generic_state")}return c};this._getCommandMap=function(d){var c={},a=d.details?d.details.commands:null;if(!a)return null;switch(d.type){case "switch":case "light":case "powerswitch":a.on&&(c["%on%"]=a.on);a.off&&(c["%off%"]=a.off);a.toggle&&(c["%toggle%"]=a.toggle);break;case "dimmer":a.on&&(c["%on%"]=a.on,c["%dimOn%"]=
  a.on);a.off&&(c["%dimOff%"]=a.off,c["%off%"]=a.off);a.toggle&&(c["%toggle%"]=a.toggle);a.up&&(c["%dimUp%"]=a.up);a.down&&(c["%dimDown%"]=a.down);a.brightness&&(c["%dimTo%"]=a.brightness);a.color&&(c["%rgb%"]=a.color);a.white&&(c["%white%"]=a.white);a.colorTemperature&&(c["%colorTemp%"]=a.colorTemperature);break;case "blind":a.up&&(c["%moveUp%"]=a.up);a.down&&(c["%moveDown%"]=a.down);a.stop&&(c["%stop%"]=a.stop);a.position&&(c["%moveTo%"]=a.position);a.lamellaUp&&(c["%lamellaUp%"]=a.lamellaUp);a.lamellaDown&&
  (c["%lamellaDown%"]=a.lamellaDown);a.rotation&&(c["%lamellaTo%"]=a.rotation);break;case "heater":a.auto&&(c["%thermoAuto%"]=a.auto),a.manu&&(c["%thermoManu%"]=a.manu),a.boost&&(c["%thermoBoost%"]=a.boost),a.up&&(c["%thermoTempUp%"]=a.up),a.down&&(c["%thermoTempDown%"]=a.down),a.tempTo&&(c["%thermoTempTo%"]=a.tempTo)}return c};this._getStatusMap=function(d){var c=function(a,b){if(a&&!b)return a;if(!a&&b)return b;if(!a&&!b)return null;var c={},d;for(d in a){var f=a[d];f&&b[f]&&(c[d]=b[f])}return c},
  a={},b=d.details?d.details.states:null;if(!b)return null;switch(d.type){case "switch":case "light":b.state&&(a["%switchState%"]=b.state,a["%switchState%"].conv_s=c(b.state.conv_s,null));break;case "dimmer":b.state&&(a["%switchState%"]=b.state,a["%switchState%"].conv_s=c(b.state.conv_s,null));b.brightness&&(a["%dimmerState%"]=b.brightness,a["%dimmerState%"].conv_s=c(b.brightness.conv_s,null));b.colorTemperature&&(a["%colorTempState%"]=b.colorTemperature,a["%colorTempState%"].conv_s=c(b.colorTemperature.conv_s,
  null));break;case "blind":b.position&&(a["%blindState%"]=b.position,a["%shutterState%"]=b.position);b.rotation&&(a["%lamellaState%"]=b.rotation);break;case "heater":b.setpoint&&(a["%thermoSetTemp%"]=b.setpoint);b.temperature&&(a["%thermoCurrentTemp%"]=b.temperature);b.humidity&&(a["%thermoHum%"]=b.humidity);b.mode&&(a["%thermoMode%"]=b.mode,d.states&&d.states.mode&&d.states.mode.values&&-1!=d.states.mode.values.indexOf("boost")&&(a["%thermoBoostMode%"]=JSON.parse(JSON.stringify(b.mode)),a["%thermoBoostMode%"].conv_s=
  c(b.mode.conv_s,{auto:"off",manu:"off",boost:"on"})));b.boostMode&&(a["%thermoBoostMode%"]=b.boostMode,a["%thermoBoostMode%"].conv_s=c(b.boostMode.conv_s,null));break;case "motion":b.motion&&(a["%motionState%"]=b.motion,a["%motionState%"].conv_s=c(b.motion.conv_s,{on:"true",off:"false"}));break;case "smoke":b.smoke&&(a["%smokeState%"]=b.smoke,a["%smokeState%"].conv_s=c(b.smoke.conv_s,{on:"true",off:"false"}));break;case "rain":b.rain&&(a["%rainState%"]=b.rain,a["%rainState%"].conv_s=c(b.rain.conv_s,
  {on:"true",off:"false"}));break;case "water":b.water&&(a["%waterState%"]=b.water,a["%waterState%"].conv_s=c(b.water.conv_s,{on:"water",off:"dry"}));break;case "contact":case "door":b.state&&(a["%contactState%"]=b.state,a["%contactState%"].conv_s=c(b.state.conv_s,null));break;case "powermeter":case "powerswitch":b.state&&(a["%switchState%"]=b.state,a["%switchState%"].conv_s=c(b.state.conv_s,null));b.consumption&&(a["%meterEnergyCounter%"]=b.consumption,a["%meterEnergyCounter%"].conv_s=c(b.consumption.conv_s,
  null));b.power&&(a["%meterPower%"]=b.power,a["%meterPower%"].conv_s=c(b.power.conv_s,null));b.voltage&&(a["%meterVoltage%"]=b.voltage,a["%meterVoltage%"].conv_s=c(b.voltage.conv_s,null));break;case "temperature":b.temperature&&(a["%tempState%"]=b.temperature);b.humidity&&(a["%humState%"]=b.humidity);break;case "weatherstation":b.temperature&&(a["%tempState%"]=b.temperature);b.humidity&&(a["%humState%"]=b.humidity);b.brightness&&(a["%brightnessState%"]=b.brightness);b.windSpeed&&(a["%windspeedState%"]=
  b.windSpeed);b.windDirection&&(a["%windDirection%"]=b.windDirection,a["%windDirection%"].conv_i=b.windDirection.conv_i);b.rain&&(a["%rainingState%"]=b.rain,a["%rainingState%"].conv_s=c(b.rain.conv_s,null));b.rainCount&&(a["%rainingCounterState%"]=b.rainCount);b.sunshine&&(a["%sunshineState%"]=b.sunshine);break;case "window":b.state&&(a["%windowState%"]=b.state,a["%windowState%"].conv_s=c(b.state.conv_s,null));break;case "co2":b.co2&&(a["%co2State%"]=b.co2,a["%co2State%"].conv_s=c(b.co2.conv_s,{normal:"normal",
  medium:"added",high:"added_strong"}));break;case "brightness":b.brightness&&(a["%state%"]=b.brightness)}return a};this._getIconMap=function(d){var c={};if(!d.details||!d.details.states)return null;switch(d.type){case "brightness":c["%icon%"]="sun"}return c};this._injectToSmartWidgetTemplate=function(d,c,a,b,f,p){var h=[];if(!c)return h;d||(d={});b||(b={});f||(f={});console.log("support widgets",c);for(var l=0;l<d.length;l++){var g=d[l];if(g.meta&&-1!=c.indexOf(g.meta.type)&&g.elements){g=JSON.parse(JSON.stringify(g));
  console.log("check widget",g.meta.id,g.meta.type);var n=!1,t=!1,q;for(q in g.elements){var r=g.elements[q];if(r&&Array.isArray(r))for(var u=0;u<r.length;u++){var e=r[u];if(e){if(e.action&&"command"==e.action.type&&e.action.ref&&e.action.ref.value){var k=e.action.ref.ext;b[e.action.ref.value]?(e.action.ref=JSON.parse(JSON.stringify(b[e.action.ref.value])),"undefined"!=typeof k&&null!=k&&(e.action.ref.ext=k),e.action.device=a,"sliders"!=q&&"roundsliders"!=q||!e.action.ref.extMeta||(k=e.action.ref.extMeta.indexOf("-",
  1),-1!=k&&(n=e.action.ref.extMeta.substr(0,k),n=parseFloat(n),k=e.action.ref.extMeta.substr(k+1),k=parseFloat(k),isNaN(n)||(e.min=n),isNaN(k)||(e.max=k))),n=!0):(console.log("no match action",e.action),t=!0,e.action=null)}e.status&&e.status.ref&&e.status.ref.value&&(f[e.status.ref.value]?(e.status.ref=JSON.parse(JSON.stringify(f[e.status.ref.value])),e.status.device=a,n=!0):(console.log("no match status",e.status),t=!0,e.status=null));e.widget&&"%icon%"==e.widget.key_img&&p&&(e.widget.key_img=p["%icon%"])}}}n&&
  !t&&(console.log("find match widget",g.meta.id,g.meta.type),h.push(g))}}return h}};"undefined"!=typeof module&&null!=module&&(module.exports=new m.aio.smartwidget.Handler);
  