iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 12.7 kB
JavaScript
export const __rspack_esm_id=64811;export const __rspack_esm_ids=[64811];export const __webpack_modules__={67932(e,t,s){s.d(t,{S:()=>o});const a={en:"US",hi:"IN",deva:"IN",te:"IN",mr:"IN",ta:"IN",gu:"IN",kn:"IN",or:"IN",ml:"IN",pa:"IN",bho:"IN",awa:"IN",as:"IN",mwr:"IN",mai:"IN",mag:"IN",bgc:"IN",hne:"IN",dcc:"IN",bn:"BD",beng:"BD",rkt:"BD",dz:"BT",tibt:"BT",tn:"BW",am:"ET",ethi:"ET",om:"ET",quc:"GT",id:"ID",jv:"ID",su:"ID",mad:"ID",ms_arab:"ID",he:"IL",hebr:"IL",jam:"JM",ja:"JP",jpan:"JP",km:"KH",khmr:"KH",ko:"KR",kore:"KR",lo:"LA",laoo:"LA",mh:"MH",my:"MM",mymr:"MM",mt:"MT",ne:"NP",fil:"PH",ceb:"PH",ilo:"PH",ur:"PK",pa_arab:"PK",lah:"PK",ps:"PK",sd:"PK",skr:"PK",gn:"PY",th:"TH",thai:"TH",tts:"TH",zh_hant:"TW",hant:"TW",sm:"WS",zu:"ZA",sn:"ZW",arq:"DZ",ar:"EG",arab:"EG",arz:"EG",fa:"IR",az_arab:"IR",dv:"MV",thaa:"MV"};const r={AG:0,ATG:0,28:0,AS:0,ASM:0,16:0,BD:0,BGD:0,50:0,BR:0,BRA:0,76:0,BS:0,BHS:0,44:0,BT:0,BTN:0,64:0,BW:0,BWA:0,72:0,BZ:0,BLZ:0,84:0,CA:0,CAN:0,124:0,CO:0,COL:0,170:0,DM:0,DMA:0,212:0,DO:0,DOM:0,214:0,ET:0,ETH:0,231:0,GT:0,GTM:0,320:0,GU:0,GUM:0,316:0,HK:0,HKG:0,344:0,HN:0,HND:0,340:0,ID:0,IDN:0,360:0,IL:0,ISR:0,376:0,IN:0,IND:0,356:0,JM:0,JAM:0,388:0,JP:0,JPN:0,392:0,KE:0,KEN:0,404:0,KH:0,KHM:0,116:0,KR:0,KOR:0,410:0,LA:0,LA0:0,418:0,MH:0,MHL:0,584:0,MM:0,MMR:0,104:0,MO:0,MAC:0,446:0,MT:0,MLT:0,470:0,MX:0,MEX:0,484:0,MZ:0,MOZ:0,508:0,NI:0,NIC:0,558:0,NP:0,NPL:0,524:0,PA:0,PAN:0,591:0,PE:0,PER:0,604:0,PH:0,PHL:0,608:0,PK:0,PAK:0,586:0,PR:0,PRI:0,630:0,PT:0,PRT:0,620:0,PY:0,PRY:0,600:0,SA:0,SAU:0,682:0,SG:0,SGP:0,702:0,SV:0,SLV:0,222:0,TH:0,THA:0,764:0,TT:0,TTO:0,780:0,TW:0,TWN:0,158:0,UM:0,UMI:0,581:0,US:0,USA:0,840:0,VE:0,VEN:0,862:0,VI:0,VIR:0,850:0,WS:0,WSM:0,882:0,YE:0,YEM:0,887:0,ZA:0,ZAF:0,710:0,ZW:0,ZWE:0,716:0,AE:6,ARE:6,784:6,AF:6,AFG:6,4:6,BH:6,BHR:6,48:6,DJ:6,DJI:6,262:6,DZ:6,DZA:6,12:6,EG:6,EGY:6,818:6,IQ:6,IRQ:6,368:6,IR:6,IRN:6,364:6,JO:6,JOR:6,400:6,KW:6,KWT:6,414:6,LY:6,LBY:6,434:6,OM:6,OMN:6,512:6,QA:6,QAT:6,634:6,SD:6,SDN:6,729:6,SY:6,SYR:6,760:6,MV:5,MDV:5,462:5};function o(e){return function(e,t,s){if(e){var a,r=e.toLowerCase().split(/[-_]/),o=r[0],n=o;if(r[1]&&4===r[1].length?(n+="_"+r[1],a=r[2]):a=r[1],a||(a=t[n]||t[o]),a)return function(e,t){var s=t["string"==typeof e?e.toUpperCase():e];return"number"==typeof s?s:1}(a.match(/^\d+$/)?Number(a):a,s)}return 1}(e,a,r)}},380(e,t,s){s.d(t,{D:()=>i,P:()=>n});s(74423);var a=s(67932),r=s(46927),o=s(96029);const n=e=>e.first_weekday===r.zt.language?"weekInfo"in Intl.Locale.prototype?new Intl.Locale(e.language).weekInfo.firstDay%7:(0,a.S)(e.language)%7:o.Z.includes(e.first_weekday)?o.Z.indexOf(e.first_weekday):1,i=e=>{const t=n(e);return o.Z[t]}},98975(e,t,s){s.a(e,async function(e,a){try{s.d(t,{K:()=>c});var r=s(74487),o=s(22786),n=s(63927),i=e([r,n]);[r,n]=i.then?(await i)():i;const u=(0,o.A)(e=>new Intl.RelativeTimeFormat(e.language,{numeric:"auto"})),c=(e,t,s,a=!0)=>{const r=(0,n.x)(e,s,t);return a?u(t).format(r.value,r.unit):Intl.NumberFormat(t.language,{style:"unit",unit:r.unit,unitDisplay:"long"}).format(Math.abs(r.value))};a()}catch(e){a(e)}})},96029(e,t,s){s.d(t,{Tq:()=>n,Z:()=>r,ZV:()=>a,sj:()=>o});const a=["sun","mon","tue","wed","thu","fri","sat"],r=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],o={0:"sun",1:"mon",2:"tue",3:"wed",4:"thu",5:"fri",6:"sat"},n={sun:"sunday",mon:"monday",tue:"tuesday",wed:"wednesday",thu:"thursday",fri:"friday",sat:"saturday"}},63927(e,t,s){s.a(e,async function(e,a){try{s.d(t,{x:()=>h});var r=s(6946),o=s(52640),n=s(38684),i=s(380);const u=1e3,c=60,l=60*c;function h(e,t=Date.now(),s,a={}){const h={...d,...a||{}},g=(+e-+t)/u;if(Math.abs(g)<h.second)return{value:Math.round(g),unit:"second"};const b=g/c;if(Math.abs(b)<h.minute)return{value:Math.round(b),unit:"minute"};const m=g/l;if(Math.abs(m)<h.hour)return{value:Math.round(m),unit:"hour"};const p=new Date(e),_=new Date(t);p.setHours(0,0,0,0),_.setHours(0,0,0,0);const y=(0,r.c)(p,_);if(0===y)return{value:Math.round(m),unit:"hour"};if(Math.abs(y)<h.day)return{value:y,unit:"day"};const v=(0,i.P)(s),f=(0,o.k)(p,{weekStartsOn:v}),M=(0,o.k)(_,{weekStartsOn:v}),D=(0,n.I)(f,M);if(0===D)return{value:y,unit:"day"};if(Math.abs(D)<h.week)return{value:D,unit:"week"};const w=p.getFullYear()-_.getFullYear(),I=12*w+p.getMonth()-_.getMonth();return 0===I?{value:D,unit:"week"}:Math.abs(I)<h.month||0===w?{value:I,unit:"month"}:{value:Math.round(w),unit:"year"}}const d={second:59,minute:59,hour:22,day:5,week:4,month:11};a()}catch(g){a(g)}})},2854(e,t,s){s.a(e,async function(e,a){try{s.r(t),s.d(t,{BluetoothNetworkVisualization:()=>M});s(44114),s(18111),s(22489),s(20116),s(7588),s(61701);var r=s(62826),o=s(5124),n=s(22441),i=s(22786),u=s(98975),c=s(76774),l=s(91926),h=s(77796),d=s(7358),g=s(36866),b=s(21030),m=s(81310),p=e([d,g,m,u]);[d,g,m,u]=p.then?(await p)():p;const _=1e4,y="ha",v="ioBroker",f=[[-70,"--green-color"],[-75,"--lime-color"],[-80,"--yellow-color"],[-85,"--amber-color"],[-90,"--orange-color"],[-95,"--deep-orange-color"],[-1/0,"--red-color"]];class M extends o.WF{connectedCallback(){if(super.connectedCallback(),this.hass){this._unsub_advertisements=(0,b.Ht)(this.hass.connection,e=>{this._data.length?this._throttledUpdateData(e):this._data=e}),this._unsub_scanners=(0,b.mj)(this.hass.connection,e=>{this._scanners=e});const e=Object.values(this.hass.devices).filter(e=>e.connections.find(e=>"bluetooth"===e[0]));this._sourceDevices=Object.fromEntries(e.map(e=>[e.connections.find(e=>"bluetooth"===e[0])[1],e]))}}disconnectedCallback(){super.disconnectedCallback(),this._unsub_advertisements&&(this._unsub_advertisements(),this._unsub_advertisements=void 0),this._throttledUpdateData.cancel(),this._unsub_scanners&&(this._unsub_scanners(),this._unsub_scanners=void 0)}render(){return o.qy` <hass-subpage .hass="${this.hass}" .narrow="${this.narrow}" .header="${this.hass.localize("ui.panel.config.bluetooth.navigation.visualization")}" back-path="/config/bluetooth/dashboard"> ${this.narrow?o.qy`<div slot="header">${this._renderInputSearch()}</div>`:o.s6} <ha-network-graph .hass="${this.hass}" .searchFilter="${this._searchFilter}" .data="${this._formatNetworkData(this._data,this._scanners)}" .searchableAttributes="${this._getSearchableAttributes}" .tooltipFormatter="${this._tooltipFormatter}" -click="${this._handleChartClick}"> ${this.narrow?o.s6:this._renderInputSearch("search")} </ha-network-graph> </hass-subpage> `}_renderInputSearch(e=""){return o.qy`<ha-input-search appearance="outlined" slot="${e}" .value="${this._searchFilter}" ="${this._handleSearchChange}"></ha-input-search>`}_handleSearchChange(e){this._searchFilter=e.target.value??""}_getBluetoothDeviceName(e){return e===y?v:this._sourceDevices[e]?this._sourceDevices[e]?.name_by_user||this._sourceDevices[e]?.name||e:this._scanners[e]?this._scanners[e]?.name||e:this._data.find(t=>t.address===e)?.name||e}_getLineWidth(e){return e>-33?3:e>-66?2:1}_handleChartClick(e){if("node"===e.detail.dataType&&"pointer"===e.detail.event.target.cursor){const{id:t}=e.detail.data,s=this._sourceDevices[t];s&&(0,l.oo)(`/config/devices/device/${s.id}`)}}static get styles(){return[o.AH`ha-network-graph{height:100%}[slot=header]{display:flex;align-items:center}ha-input-search{flex:1}`]}constructor(...e){super(...e),this.narrow=!1,this.isWide=!1,this._data=[],this._scanners={},this._sourceDevices={},this._searchFilter="",this._throttledUpdateData=(0,h.n)(e=>{this._data=e},_),this._getSearchableAttributes=e=>{const t=[],s=this._sourceDevices[e];s?.manufacturer&&t.push(s.manufacturer),s?.model&&t.push(s.model);const a=this._scanners[e];return a?.name&&t.push(a.name),t},this._getRssiColorVar=(0,i.A)(e=>{for(const[t,s]of f)if(e>t)return s;return"--red-color"}),this._formatNetworkData=(0,i.A)((e,t)=>{const s=getComputedStyle(this),a=[{name:v,symbol:"roundRect",itemStyle:{color:s.getPropertyValue("--primary-color")}},{name:this.hass.localize("ui.panel.config.bluetooth.scanners"),symbol:"circle",itemStyle:{color:s.getPropertyValue("--cyan-color")}},{name:this.hass.localize("ui.panel.config.bluetooth.known_devices"),symbol:"circle",itemStyle:{color:s.getPropertyValue("--teal-color")}},{name:this.hass.localize("ui.panel.config.bluetooth.unknown_devices"),symbol:"circle",itemStyle:{color:s.getPropertyValue("--disabled-color")}}],r=[{id:y,name:v,category:0,value:4,symbol:"roundRect",symbolSize:40,polarDistance:0}],o=[];return Object.values(t).forEach(e=>{const t=this._sourceDevices[e.source],a=t?(0,c.q)(t,this.hass.areas):void 0;r.push({id:e.source,name:t?.name_by_user||t?.name||e.name,context:a?.name,category:1,value:5,symbol:"circle",symbolSize:30,polarDistance:.25}),o.push({source:y,target:e.source,value:0,symbol:"none",lineStyle:{width:3,color:s.getPropertyValue("--primary-color")}})}),e.forEach(e=>{if(t[e.address])return void o.push({source:e.source,target:e.address,value:e.rssi,symbol:"none",lineStyle:{width:this._getLineWidth(e.rssi),color:s.getPropertyValue(this._getRssiColorVar(e.rssi))}});const a=this._sourceDevices[e.address],n=a?(0,c.q)(a,this.hass.areas):void 0;r.push({id:e.address,name:this._getBluetoothDeviceName(e.address),context:n?.name,value:a?1:0,category:a?2:3,symbolSize:20}),o.push({source:e.source,target:e.address,value:e.rssi,symbol:"none",lineStyle:{width:this._getLineWidth(e.rssi),color:a?s.getPropertyValue(this._getRssiColorVar(e.rssi)):s.getPropertyValue("--disabled-color")}})}),{nodes:r,links:o,categories:a}}),this._tooltipFormatter=e=>{const{dataType:t,data:s}=e;if("edge"===t){const{source:e,target:t,value:a}=s,r=this._getBluetoothDeviceName(e),n=this._getBluetoothDeviceName(t);return o.qy`${r} → ${n}${e!==y?o.qy` <b>${this.hass.localize("ui.panel.config.bluetooth.rssi")}:</b> ${a}`:o.s6}`}const{id:a}=s,r=this._getBluetoothDeviceName(a),n=this._data.find(e=>e.address===a),i=this._sourceDevices[a],l=i?(0,c.q)(i,this.hass.areas):void 0,h=l?o.qy`<br><b>${this.hass.localize("ui.panel.config.bluetooth.area")}: </b>${l.name}`:o.s6;return n?o.qy`<b>${r}</b><br> <b>${this.hass.localize("ui.panel.config.bluetooth.address")}:</b> ${a}<br> <b>${this.hass.localize("ui.panel.config.bluetooth.rssi")}:</b> ${n.rssi}<br> <b>${this.hass.localize("ui.panel.config.bluetooth.source")}:</b> ${n.source}<br> <b>${this.hass.localize("ui.panel.config.bluetooth.updated")}:</b> ${(0,u.K)(new Date(1e3*n.time),this.hass.locale)}${h}`:i?o.qy`<b>${r}</b><br> <b>${this.hass.localize("ui.panel.config.bluetooth.address")}:</b> ${a}${h}`:o.s6}}}(0,r.Cg)([(0,n.MZ)({attribute:!1})],M.prototype,"hass",void 0),(0,r.Cg)([(0,n.MZ)({type:Boolean,reflect:!0})],M.prototype,"narrow",void 0),(0,r.Cg)([(0,n.MZ)({attribute:"is-wide",type:Boolean})],M.prototype,"isWide",void 0),(0,r.Cg)([(0,n.MZ)({attribute:!1})],M.prototype,"route",void 0),(0,r.Cg)([(0,n.wk)()],M.prototype,"_data",void 0),(0,r.Cg)([(0,n.wk)()],M.prototype,"_scanners",void 0),(0,r.Cg)([(0,n.wk)()],M.prototype,"_sourceDevices",void 0),(0,r.Cg)([(0,n.wk)()],M.prototype,"_searchFilter",void 0),M=(0,r.Cg)([(0,n.EM)("bluetooth-network-visualization")],M),a()}catch(e){a(e)}})},2045(e,t,s){s.d(t,{q:()=>r});let a={};function r(){return a}},74816(e,t,s){s.d(t,{x:()=>r});s(18111),s(20116),s(61701);var a=s(73420);function r(e,...t){const s=a.w.bind(null,e||t.find(e=>"object"==typeof e));return t.map(s)}},465(e,t,s){s.d(t,{m:()=>u});var a=s(83504);function r(e){const t=(0,a.a)(e),s=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return s.setUTCFullYear(t.getFullYear()),+e-+s}var o=s(74816),n=s(9160),i=s(35932);function u(e,t,s){const[a,u]=(0,o.x)(s?.in,e,t),c=(0,i.o)(a),l=(0,i.o)(u),h=+c-r(c),d=+l-r(l);return Math.round((h-d)/n.w4)}},6946(e,t,s){s.d(t,{c:()=>o});var a=s(74816),r=s(465);function o(e,t,s){const[o,i]=(0,a.x)(s?.in,e,t),u=n(o,i),c=Math.abs((0,r.m)(o,i));o.setDate(o.getDate()-u*c);const l=u*(c-Number(n(o,i)===-u));return 0===l?0:l}function n(e,t){const s=e.getFullYear()-t.getFullYear()||e.getMonth()-t.getMonth()||e.getDate()-t.getDate()||e.getHours()-t.getHours()||e.getMinutes()-t.getMinutes()||e.getSeconds()-t.getSeconds()||e.getMilliseconds()-t.getMilliseconds();return s<0?-1:s>0?1:s}},38684(e,t,s){s.d(t,{I:()=>o});var a=s(6439),r=s(6946);function o(e,t,s){const o=(0,r.c)(e,t,s)/7;return(0,a.u)(s?.roundingMethod)(o)}},35932(e,t,s){s.d(t,{o:()=>r});var a=s(83504);function r(e,t){const s=(0,a.a)(e,t?.in);return s.setHours(0,0,0,0),s}},52640(e,t,s){s.d(t,{k:()=>o});var a=s(2045),r=s(83504);function o(e,t){const s=(0,a.q)(),o=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??s.weekStartsOn??s.locale?.options?.weekStartsOn??0,n=(0,r.a)(e,t?.in),i=n.getDay(),u=(i<o?7:0)+i-o;return n.setDate(n.getDate()-u),n.setHours(0,0,0,0),n}}};