3 lines
24 KiB
JavaScript
3 lines
24 KiB
JavaScript
"use strict";var Types={unknown:"unknown",blind:"blind",button:"button",camera:"camera",url:"url",image:"image",dimmer:"dimmer",door:"door",fireAlarm:"fireAlarm",floodAlarm:"floodAlarm",gate:"gate",humidity:"humidity",info:"info",instance:"instance",light:"light",lock:"lock",media:"media",motion:"motion",rgb:"rgb",ct:"ct",rgbSingle:"rgbSingle",hue:"hue",slider:"slider",socket:"socket",temperature:"temperature",thermostat:"thermostat",valve:"valve",volume:"volume",volumeGroup:"volumeGroup",window:"window",windowTilt:"windowTilt",weatherCurrent:"weatherCurrent",weatherForecast:"weatherForecast",warning:"warning"};function ChannelDetector(){if(!(this instanceof ChannelDetector))return new ChannelDetector;var e={role:/^indicator\.working$/,indicator:!0,name:"WORKING",required:!1},r={role:/^indicator(\.maintenance)?\.unreach$/,indicator:!0,type:"boolean",name:"UNREACH",required:!1},t={role:/^indicator(\.maintenance)?\.lowbat$|^indicator(\.maintenance)?\.battery/,indicator:!0,type:"boolean",name:"LOWBAT",required:!1},i={role:/^indicator\.maintenance$/,indicator:!0,type:"boolean",name:"MAINTAIN",required:!1},n={role:/^indicator\.error$/,indicator:!0,name:"ERROR",required:!1},o={role:/^indicator\.direction$/,indicator:!0,name:"DIRECTION",required:!1},v={mediaPlayer:{states:[{role:/^media.state(\..*)?$/,indicator:!1,type:["boolean","number"],name:"STATE",required:!0},{role:/^button.play(\..*)?$|^action.play(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"PLAY",required:!1,noSubscribe:!0},{role:/^button.pause(\..*)?$|^action.pause(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"PAUSE",required:!1,noSubscribe:!0},{role:/^button.stop(\..*)?$|^action.stop(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"STOP",required:!1,noSubscribe:!0},{role:/^button.next(\..*)?$|^action.next(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"NEXT",required:!1,noSubscribe:!0},{role:/^button.prev(\..*)?$|^action.prev(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"PREV",required:!1,noSubscribe:!0},{role:/^media.mode.shuffle(\..*)?$/,indicator:!1,write:!0,type:"boolean",name:"SHUFFLE",required:!1,noSubscribe:!0},{role:/^media.mode.repeat(\..*)?$/,indicator:!1,write:!0,type:"number",name:"REPEAT",required:!1,noSubscribe:!0},{role:/^media.artist(\..*)?$/,indicator:!1,write:!1,type:"string",name:"ARTIST",required:!1},{role:/^media.album(\..*)?$/,indicator:!1,write:!1,type:"string",name:"ALBUM",required:!1},{role:/^media.title(\..*)?$/,indicator:!1,write:!1,type:"string",name:"TITLE",required:!1},[{role:/^media.cover$|^media.cover.big$/,indicator:!1,write:!1,type:"string",name:"COVER",required:!1,notSingle:!0},{role:/^media.cover(\..*)$/,indicator:!1,write:!1,type:"string",name:"COVER",required:!1,notSingle:!0}],{role:/^media.duration(\..*)?$/,indicator:!1,write:!1,type:"number",name:"DURATION",required:!1,noSubscribe:!0},{role:/^media.elapsed(\..*)?$/,indicator:!1,type:"number",name:"ELAPSED",required:!1,noSubscribe:!0},{role:/^media.season(\..*)?$/,indicator:!1,write:!0,type:"number",name:"SEEK",required:!1,noSubscribe:!0},{role:/^media.seek(\..*)?$/,indicator:!1,write:!0,type:"number",name:"SEEK",required:!1,noSubscribe:!0},{role:/^media.track(\..*)?$/,indicator:!1,type:"string",name:"TRACK",required:!1,noSubscribe:!0},{role:/^media.episode(\..*)?$/,indicator:!1,type:"string",name:"EPISODE",required:!1,noSubscribe:!0},{role:/^media.season(\..*)?$/,indicator:!1,type:"string",name:"SEASON",required:!1,noSubscribe:!0},{role:/^level.volume?$/,indicator:!1,type:"number",min:"number",max:"number",write:!0,name:"VOLUME",required:!1,notSingle:!0,noSubscribe:!0},{role:/^value.volume?$/,indicator:!1,type:"number",min:"number",max:"number",write:!1,name:"VOLUME_ACTUAL",required:!1,notSingle:!0,noSubscribe:!0},{role:/^media.mute?$/,indicator:!1,type:"boolean",write:!0,name:"MUTE",required:!1,notSingle:!0,noSubscribe:!0},{stateName:/\.paused$|\.playerState$/,indicator:!1,name:"IGNORE",required:!1,multiple:!0,noSubscribe:!0},{role:/^indicator\.reachable$/,indicator:!0,type:"boolean",name:"CONNECTED",required:!1,inverted:!0},t,i,n],type:Types.media},weatherForecast:{states:[{role:/^weather.icon$|^weather.icon.forecast.0$/,indicator:!1,type:"string",name:"ICON",required:!0},{role:/^value.temperature.min.forecast.0$/,indicator:!1,type:"number",name:"TEMP_MIN",required:!0},{role:/^value.temperature.max.forecast.0$/,indicator:!1,type:"number",name:"TEMP_MAX",required:!0},{role:/^value.precipitation$|^value.precipitation.forecast.0$/,indicator:!1,type:"number",name:"PRECIPITATION_CHANCE",unit:"%",required:!1},{role:/^date$|^date.forecast.0$/,indicator:!1,type:"string",name:"DATE",required:!1},{role:/^dayofweek$|^dayofweek.forecast.0$/,indicator:!1,type:"string",name:"DOW",required:!1},{role:/^weather.state$|^weather.state.forecast.0$/,indicator:!1,type:"string",name:"STATE",required:!1},{role:/^value.temperature$|^value.temperature.forecast.0$/,indicator:!1,type:"number",name:"TEMP",required:!1},{role:/^value.pressure$/,indicator:!1,type:"number",name:"PRESSURE",required:!1},{role:/^value.humidity$|value.humidity.forecast.0$/,indicator:!1,type:"number",name:"HUMIDITY",required:!1},{role:/^value.temperature.windchill$|^value.temperature.windchill.forecast.0$/,indicator:!1,type:"number",name:"WIND_CHILL",required:!1},{role:/^value.temperature.feelslike$|^value.temperature.feelslike$.forecast.0$/,indicator:!1,type:"number",name:"FEELS_LIKE",required:!1},{role:/^value.speed.wind$|^value.speed.wind.forecast.0$/,indicator:!1,type:"number",name:"WIND_SPEED",required:!1},{role:/^value.direction.wind$|^value.direction.wind.forecast.0$/,indicator:!1,type:"number",name:"WIND_DIRECTION",required:!1},{role:/^weather.direction.wind$|^weather.direction.wind.forecast.0$/,indicator:!1,type:"string",name:"WIND_DIRECTION_STR",required:!1},{role:/^weather.icon.wind$|^weather.icon.wind.forecast.0$/,indicator:!1,type:"string",name:"WIND_ICON",required:!1},{role:/^weather.chart.url$/,indicator:!1,type:"string",name:"HISTORY_CHART",required:!1,noSubscribe:!0},{role:/^weather.chart.url.forecast$/,indicator:!1,type:"string",name:"FORECAST_CHART",required:!1,noSubscribe:!0},{role:/^location$/,indicator:!1,type:"string",name:"LOCATION",required:!1,multiple:!0},{role:/^weather.icon.forecast.(\d)$/,indicator:!1,type:"string",name:"ICON%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0,notSingle:!0},{role:/^value.temperature.min.forecast.(\d)$/,indicator:!1,type:"number",name:"TEMP_MIN%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.temperature.max.forecast.(\d)$/,indicator:!1,type:"number",name:"TEMP_MAX%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^date.forecast.(\d)$/,indicator:!1,type:"string",name:"DATE%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^dayofweek.forecast.(\d)$/,indicator:!1,type:"string",name:"DOW%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^weather.state.forecast.(\d)$/,indicator:!1,type:"string",name:"STATE%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.temperature.forecast.(\d)$/,indicator:!1,type:"number",name:"TEMP%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.humidity.forecast.(\d)$/,indicator:!1,type:"number",name:"HUMIDITY%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.humidity.max.forecast.(\d)$/,indicator:!1,type:"number",name:"HUMIDITY_MAX%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.precipitation.forecast.(\d)$/,indicator:!1,type:"number",unit:"%",name:"PRECIPITATION_CHANCE%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.speed.wind.forecast.(\d)$/,indicator:!1,type:"number",name:"WIND_SPEED%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^value.direction.wind.forecast.(\d)$/,indicator:!1,type:"number",name:"WIND_DIRECTION%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^weather.direction.wind.forecast.(\d)$/,indicator:!1,type:"string",name:"WIND_DIRECTION_STR%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0},{role:/^weather.icon.wind.forecast.(\d)$/,indicator:!1,type:"string",name:"WIND_ICON%d",required:!1,searchInParent:!0,multiple:!0,noSubscribe:!0}],type:Types.weatherForecast},rgb:{states:[{role:/^level\.color\.red$/,indicator:!1,type:"number",write:!0,name:"RED",required:!0},{role:/^level\.color\.green$/,indicator:!1,type:"number",write:!0,name:"GREEN",required:!0},{role:/^level\.color\.blue$/,indicator:!1,type:"number",write:!0,name:"BLUE",required:!0},{role:/^level\.dimmer$/,indicator:!1,type:"number",write:!0,name:"DIMMER",required:!1},{role:/^level\.brightness$/,indicator:!1,type:"number",write:!0,name:"BRIGHTNESS",required:!1},{role:/^level\.color\.saturation$/,indicator:!1,type:"number",write:!0,name:"SATURATION",required:!1},{role:/^level\.color\.temperature$/,indicator:!1,type:"number",write:!0,name:"TEMPERATURE",required:!1},{role:/^switch\.light$/,indicator:!1,type:"boolean",write:!0,name:"ON_LIGHT",required:!1},{role:/^switch$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},e,r,t,i,n],type:Types.rgb},rgbOld:{states:[{role:/^level\.color\.r$/,indicator:!1,type:"number",write:!0,name:"RED",required:!0},{role:/^level\.color\.g$/,indicator:!1,type:"number",write:!0,name:"GREEN",required:!0},{role:/^level\.color\.b$/,indicator:!1,type:"number",write:!0,name:"BLUE",required:!0},{role:/^level\.dimmer$/,indicator:!1,type:"number",write:!0,name:"DIMMER",required:!1},{role:/^level\.brightness$/,indicator:!1,type:"number",write:!0,name:"BRIGHTNESS",required:!1},{role:/^level\.color\.saturation$/,indicator:!1,type:"number",write:!0,name:"SATURATION",required:!1},{role:/^level\.color\.temperature$/,indicator:!1,type:"number",write:!0,name:"TEMPERATURE",required:!1},{role:/^switch\.light$/,indicator:!1,type:"boolean",write:!0,name:"ON_LIGHT",required:!1},{role:/^switch$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},e,r,t,i,n],type:Types.rgb},rgbSingle:{states:[{role:/^level\.color\.rgb$/,indicator:!1,type:"string",write:!0,name:"RGB",required:!0},{role:/^level\.dimmer$/,indicator:!1,type:"number",write:!0,name:"DIMMER",required:!1},{role:/^level\.brightness$/,indicator:!1,type:"number",write:!0,name:"BRIGHTNESS",required:!1},{role:/^level\.color\.saturation$/,indicator:!1,type:"number",write:!0,name:"SATURATION",required:!1},{role:/^level\.color\.temperature$/,indicator:!1,type:"number",write:!0,name:"TEMPERATURE",required:!1},{role:/^switch\.light$/,indicator:!1,type:"boolean",write:!0,name:"ON_LIGHT",required:!1},{role:/^switch$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},e,r,t,i,n],type:Types.rgbSingle},hue:{states:[{role:/^level\.color\.hue$/,indicator:!1,type:"number",write:!0,name:"HUE",required:!0},{role:/^level\.dimmer$/,indicator:!1,type:"number",write:!0,name:"DIMMER",required:!1,searchInParent:!0},{role:/^level\.brightness$/,indicator:!1,type:"number",write:!0,name:"BRIGHTNESS",required:!1},{role:/^level\.color\.saturation$/,indicator:!1,type:"number",write:!0,name:"SATURATION",required:!1},{role:/^level\.color\.temperature$/,indicator:!1,type:"number",write:!0,name:"TEMPERATURE",required:!1},{role:/^switch.light$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},{role:/^switch$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},e,r,t,i,n],type:Types.hue},ct:{states:[{role:/^level\.color\.temperature$/,indicator:!1,type:"number",write:!0,name:"TEMPERATURE",required:!0},{role:/^level\.dimmer$/,indicator:!1,type:"number",write:!0,name:"DIMMER",required:!1},{role:/^level\.brightness$/,indicator:!1,type:"number",write:!0,name:"BRIGHTNESS",required:!1},{role:/^level\.color\.saturation$/,indicator:!1,type:"number",write:!0,name:"SATURATION",required:!1},{role:/^switch.light$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},{role:/^switch$/,indicator:!1,type:"boolean",write:!0,name:"ON",required:!1},e,r,t,i,n],type:Types.ct},warning:{states:[{role:/^value\.warning$/,indicator:!1,name:"LEVEL",required:!0},{role:/^weather\.title\.short$/,indicator:!1,type:"string",name:"TITLE",required:!1},{role:/^weather\.title$/,indicator:!1,type:"string",name:"INFO",required:!1},{role:/^date\.start$/,indicator:!1,type:"string",name:"START",required:!1},{role:/^date\.end$/,indicator:!1,type:"string",name:"END",required:!1},{role:/^date$/,indicator:!1,type:"string",name:"START",required:!1},{role:/^weather\.chart\.url/,indicator:!1,type:"string",name:"ICON",required:!1},{role:/^weather\.state$/,indicator:!1,type:"string",name:"DESC",required:!1,noSubscribe:!0}],type:Types.warning},thermostat:{states:[{role:/temperature(\..*)?$/,indicator:!1,write:!0,type:"number",name:"SET",required:!0},{role:/temperature(\..*)?$/,indicator:!1,write:!1,type:"number",searchInParent:!0,name:"ACTUAL",required:!1},{role:/humidity(\..*)?$/,indicator:!1,write:!1,type:"number",searchInParent:!0,name:"HUMIDITY",required:!1},{role:/^switch\.boost(\..*)?$/,indicator:!1,write:!0,type:"number",searchInParent:!0,name:"BOOST",required:!1},e,r,t,i,n],type:Types.thermostat},blinds:{states:[{role:/^level(\.blind)?$/,indicator:!1,type:"number",write:!0,enums:c,name:"SET",required:!0},{role:/^value(\.blind)?$/,indicator:!1,type:"number",enums:c,name:"ACTUAL",required:!1},{role:/^button\.stop$|^action\.stop$/,indicator:!1,type:"boolean",write:!0,enums:c,name:"STOP",required:!1,noSubscribe:!0},o,e,r,t,i,n],type:Types.blind},lock:{states:[{role:/^switch\.lock$/,indicator:!1,type:"boolean",write:!0,name:"SET",required:!0},{role:/^state$/,indicator:!1,type:"boolean",write:!1,name:"ACTUAL",required:!1},{indicator:!1,type:"boolean",write:!0,read:!1,name:"OPEN",required:!1,noSubscribe:!0},o,e,r,t,i,n],type:Types.lock},motion:{states:[{role:/^state\.motion$|^sensor\.motion$/,indicator:!1,type:"boolean",name:"ACTUAL",required:!0},{role:/brightness$/,indicator:!1,type:"number",name:"SECOND",required:!1},r,t,i,n],type:Types.motion},window:{states:[{role:/^state(\.window)?$|^sensor(\.window)?/,indicator:!1,type:"boolean",enums:b,name:"ACTUAL",required:!0},r,t,i,n],type:Types.window},windowTilt:{states:[{role:/^state?$|^value(\.window)?$/,indicator:!1,type:"number",enums:b,name:"ACTUAL",required:!0},r,t,i,n],type:Types.windowTilt},fireAlarm:{states:[{role:/^state?$|^sensor(\.alarm)?\.fire/,indicator:!1,type:"boolean",name:"ACTUAL",required:!0,channelRole:/^sensor(\.alarm)?\.fire$/},r,t,i,n],type:Types.fireAlarm},door:{states:[{role:/^state?$|^state(\.door)?$|^sensor(\.door)?/,indicator:!1,type:"boolean",write:!1,enums:function(e,r){return a(e,r,w,h)},name:"ACTUAL",required:!0},r,t,i,n],type:Types.door},dimmer:{states:[{role:/^level(\.dimmer)?|^level\.brightness$/,indicator:!1,type:"number",write:!0,enums:s,name:"SET",required:!0},{role:/^value(\.dimmer)?$/,indicator:!1,type:"number",write:!1,enums:s,name:"ACTUAL",required:!1},{role:/^switch(\.light)?$|^state$/,indicator:!1,type:"boolean",write:!0,enums:s,name:"ON_SET",required:!1},{role:/^switch(\.light)?$|^state$/,indicator:!1,type:"boolean",write:!1,enums:s,name:"ON_ACTUAL",required:!1},e,r,t,i,n],type:Types.dimmer},light:{states:[{role:/^switch(\.light)?$|^state$/,indicator:!1,type:"boolean",write:!0,enums:s,name:"SET",required:!0},{role:/^switch(\.light)?$|^state$/,indicator:!1,type:"boolean",write:!1,enums:s,name:"ACTUAL",required:!1},e,r,t,i,n],type:Types.light},volume:{states:[{role:/^level\.volume$/,indicator:!1,type:"number",min:"number",max:"number",write:!0,name:"SET",required:!0},{role:/^value\.volume$/,indicator:!1,type:"number",min:"number",max:"number",write:!1,name:"ACTUAL",required:!1},{role:/^media\.mute$/,indicator:!1,type:"boolean",write:!0,name:"MUTE",required:!1},e,r,t,i,n],type:Types.volume},volumeGroup:{states:[{role:/^level\.volume\.group?$/,indicator:!1,type:"number",min:"number",max:"number",write:!0,name:"SET",required:!0},{role:/^value\.volume\.group$/,indicator:!1,type:"number",min:"number",max:"number",write:!1,name:"ACTUAL",required:!1},{role:/^media\.mute\.group$/,indicator:!1,type:"boolean",write:!0,name:"MUTE",required:!1},e,r,t,i,n],type:Types.volumeGroup},levelSlider:{states:[{role:/^level(\..*)?$/,indicator:!1,type:"number",min:"number",max:"number",write:!0,name:"SET",required:!0},{role:/^value(\..*)?$/,indicator:!1,type:"number",min:"number",max:"number",write:!1,name:"ACTUAL",required:!1},e,r,t,i,n],type:Types.slider},socket:{states:[{role:/^switch$|^state$|^switch\.active$/,indicator:!1,type:"boolean",write:!0,name:"SET",required:!0},{role:/^state$|^state\.active$/,indicator:!1,type:"boolean",write:!1,name:"ACTUAL",required:!1},e,r,t,i,n],type:Types.socket},button:{states:[{role:/^button(\.[.\w]+)?$|^action(\.[.\w]+)?$/,indicator:!1,type:"boolean",read:!1,write:!0,name:"SET",required:!0,noSubscribe:!0},r,t,i,n],type:Types.button},temperature:{states:[{role:/temperature$/,indicator:!1,write:!1,type:"number",name:"ACTUAL",required:!0},{role:/humidity$/,indicator:!1,write:!1,type:"number",name:"SECOND",required:!1},r,t,i,n],type:Types.temperature},info:{states:[{indicator:!1,name:"ACTUAL",required:!0,multiple:!0,noDeviceDetection:!0,ignoreRole:/\.inhibit$/},e,r,t,i,n],type:Types.info}};function a(e,r,t,i){return!(!t||-1===t.indexOf(e.common.role))||(o=i,a=!1,(n=r)&&n.forEach(function(r){var e=r.lastIndexOf(".");for(var t in-1!==e&&(r=r.substring(e+1)),o)if(o.hasOwnProperty(t)&&o[t].find(function(e){return e.test(r)}))return!(a=!0)}),a);var n,o,a}var l={en:[/lights?/i,/lamps?/i,/ceilings?/i],de:[/licht(er)?/i,/lampen?/i,/beleuchtung(en)?/i],ru:[/свет/i,/ламп[аы]/i,/торшеры?/,/подсветк[аи]/i,/лампочк[аи]/i,/светильники?/i]},u=["switch.light","dimmer","value.dimmer","level.dimmer","sensor.light","state.light"];function s(e,r){return a(e,r,u,l)}var d={en:[/blinds?/i,/windows?/i,/shutters?/i],de:[/rollladen?/i,/fenstern?/i,/beschattung(en)?/i],ru:[/ставни/i,/рольставни/i,/окна|окно/,/жалюзи/i]},m=["blind","level.blind","value.blind","action.stop","button.stop"];function c(e,r){return a(e,r,m,d)}var p=["window","state.window","sensor.window","value.window"];function b(e,r){return a(e,r,p,d)}var y,h={en:[/doors?/i,/gates?/i,/wickets?/i,/entry|entries/i],de:[/türe?/i,/tuere?/i,/tore?/i,/einfahrt(en)?/i,/pforten?/i],ru:[/двери|дверь/i,/ворота/i,/калитка|калитки/,/въезды?/i,/входы?/i]},w=["door","state.door","sensor.door"];function q(e,r){var t=[],i=new RegExp("^"+r.replace(/\./g,"\\.")+"\\.[^.]+\\.[^.]+$");return e.forEach(function(e){i.test(e)&&t.push(e)}),t}function T(e){var r=e.lastIndexOf(".");return-1!==r?e.substring(0,r):e}function f(e,r){if(r||(r=JSON.parse(JSON.stringify(e))),r instanceof Array)for(var t=0;t<r.length;t++)r[t].original=e[t].original||e[t],e[t].enums&&(r[t].enums=e[t].enums),e[t].role&&(r[t].role=e[t].role),e[t].channelRole&&(r[t].channelRole=e[t].channelRole),e[t].icon&&(r[t].icon=e[t].icon);else r.original=e.original||e,e.enums&&(r.enums=e.enums),e.role&&(r.role=e.role),e.channelRole&&(r.channelRole=e.channelRole),e.icon&&(r.icon=e.icon);return r}return this._applyPattern=function(e,r,t){if(e[r]&&e[r].common){var i=null;if(t.role&&(i=t.role.test(e[r].common.role||""))&&t.channelRole){var n=T(r);i=!(!e[n]||"channel"!==e[n].type&&"device"!==e[n].type)&&t.channelRole.test(e[n].common.role)}if(!1===i)return;if(t.stateName&&!t.stateName.test(r))return!1;if(t.unit&&t.unit!==e[r].common.unit)return!1;if(t.ignoreRole&&t.ignoreRole.test(e[r].common.role))return;if(!1===t.indicator&&(e[r].common.role||"").match(/^indicator(\.[.\w]+)?$/))return;if(t.state&&!t.state.test(r.split(".").pop()))return;if(void 0!==t.write&&t.write!==(e[r].common.write||!1))return;if("number"===t.min&&"number"!=typeof e[r].common.min)return;if("number"===t.max&&"number"!=typeof e[r].common.max)return;if(void 0!==t.read&&t.read!==(void 0===e[r].common.read||e[r].common.read))return;if(t.type)if("string"==typeof t.type){if(t.type!==e[r].common.type)return}else{for(var o=!0,a=0;a<t.type.length;a++)if(t.type[a]===e[r].common.type){o=!1;break}if(o)return}if(t.enums&&"function"==typeof t.enums){var l=this._getEnumsForId(e,r);if(!t.enums(e[r],l))return}return!0}return!1},this._getEnumsForId=function(r,t){this.enums=this.enums||function(e){var r=[],t=/^enum\.functions\./;for(var i in e)e.hasOwnProperty(i)&&t.test(i)&&e[i]&&"enum"===e[i].type&&e[i].common&&e[i].common.members&&e[i].common.members.length&&r.push(i);return r}(r);var i=[];if(this.enums.forEach(function(e){-1!==r[e].common.members.indexOf(t)&&i.push(e)}),!i.length&&r[t]&&"state"===r[t].type){var n=T(t);!r[n]||"channel"!==r[n].type&&"device"!==r[n].type||this.enums.forEach(function(e){-1!==r[e].common.members.indexOf(n)&&i.push(e)})}return i.length?i:null},this._testOneState=function(o){var a=o.objects,l=o.pattern,u=o.state,s=o.channelStates,d=o.usedIds,m=o._usedIds,c=o.ignoreIndicators,p=o.result,b=!1;return s.forEach(function(t){if((u.indicator||-1===d.indexOf(t)&&(u.notSingle||-1===m.indexOf(t)))&&this._applyPattern(a,t,u)){if(u.indicator&&c){var e=t.split(".");if(-1!==c.indexOf(e.pop()))return void console.log(t+" ignored")}if(u.indicator||u.notSingle||m.push(t),p||(o.result=p=JSON.parse(JSON.stringify(v[l])),p.states.forEach(function(e,r){f(v[l].states[r],e)})),p.type,!p.states.find(function(e){return e.id===t})){for(var r=!1,i=0;i<p.states.length;i++)if(p.states[i]instanceof Array){for(var n=0;n<p.states[i].length;n++)if(p.states[i][n].name===u.name&&p.states[i][n].role===u.role){p.states[i]=p.states[i][n],p.states[i].id=t,r=!0;break}if(r)break}else if(p.states[i].name===u.name){p.states[i].id=t,r=!0;break}r||console.error("Cannot find state for "+t)}return b=!0,u.multiple&&1<s.length&&s.forEach(function(e){if(e!==t&&(u.indicator||-1===d.indexOf(e)&&(u.notSingle||-1===m.indexOf(e)))&&this._applyPattern(a,e,u)){u.indicator||u.notSingle||m.push(e);var r=f(u);r.id=e,p.states.push(r)}}.bind(this)),!1}}.bind(this)),b},this._detectNext=function(e){var r,t,i,n=e.objects,o=e.id,a=e._keysOptional,l=e._usedIdsOptional,u=e.ignoreIndicators,s=e.allowedTypes;if(l||(l=[],e._usedIdsOptional=l),n[o]&&n[o].common){var d;d="state"===n[o].type?[o]:"device"===n[o].type?q(a,o):(r=a,t=[],i=new RegExp("^"+o.replace(/\./g,"\\.")+"\\.[^.]+$"),r.forEach(function(e){i.test(e)&&t.push(e)}),t),-1!==o.indexOf("yeelight-2.0.color-")&&console.log("aaa");var m={objects:n,channelStates:d,usedIds:l,ignoreIndicators:u};for(var c in v)if(v.hasOwnProperty(c)&&(!s||-1!==s.indexOf(v[c].type))){m.result=null,"hue"===c&&-1!==o.indexOf("yeelight-2.0.color-")&&console.log(c);var p=[];m.pattern=c,m._usedIds=p,v[c].states.forEach(function(e){var r=!1;if(e.name,e instanceof Array){for(var t=0;t<e.length;t++)if(m.state=e[t],this._testOneState(m)){r=!0;break}if(!r)return m.result=null,!1}else if(m.state=e,this._testOneState(m)&&(r=!0),e.required&&!r)return m.result=null,!1}.bind(this));var b=!0;if(m.result){for(var y=0;y<m.result.states.length;y++)if(m.result.states[y]instanceof Array){for(var h=!1,w=0;w<m.result.states[y].length;w++)if(m.result.states[y][w].required&&m.result.states[y].id){h=!0;break}if(!h){b=!1;break}}else if(m.result.states[y].required&&!m.result.states[y].id){b=!1;break}}else b=!1;if(b){var f;if(p.forEach(function(e){l.push(e)}),"device"!==n[o].type){var $=T(o);!n[$]||"channel"!==n[$].type&&"device"!==n[$].type||(f=q(a,$))&&f.forEach(function(t){m.result.states.forEach(function(e,r){e.id||!e.indicator&&!e.searchInParent||e.noDeviceDetection||this._applyPattern(n,t,e.original)&&(m.result.states[r].id=t)}.bind(this))}.bind(this))}return m.result.states.forEach(function(e){if(-1!==e.name.indexOf("%d")&&e.role&&e.id){var r=e.role.exec(m.objects[e.id].common.role);r&&(e.name=e.name.replace("%d",r[1]))}e.role&&delete e.role,e.enums&&delete e.enums,e.original&&(e.original.icon&&(e.icon=e.original.icon),delete e.original)}),m.result}}}return null},this.detect=function(e){var r=e.objects,t=e.id,i=e._keysOptional,n=e._usedIdsOptional;e.ignoreIndicators;if(void 0!==this.cache[t])return this.cache[t];i||((i=Object.keys(r)).sort(),e._keysOptional=i);var o,a=[];for(n&&(n=[],e._usedIdsOptional=n);o=this._detectNext(e);)a.push(o);return this.cache[t]=a.length?a:null,this.cache[t]},(y=this).enums=null,y.cache={},this}"undefined"!=typeof module&&module.parent&&(module.exports={Types:Types,ChannelDetector:ChannelDetector});
|
|
//# sourceMappingURL=vendor.js.map
|