UNPKG

iobroker.lovelace

Version:

With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI

1 lines 16.7 kB
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[48347],{90433:function(t,e,n){n.d(e,{Vy:function(){return i},fI:function(){return s},ux:function(){return d}});var o=n(22786),r=n(79468);const a=54;function i(t,e){const n=t%a+1;return e.getPropertyValue(`--color-${n}`)}function s(t,e){const n=e.getPropertyValue(`--graph-color-${t+1}`)||i(t,e);return(0,r.RQ)(n)}const d=(0,o.A)(t=>Array.from({length:a},(e,n)=>s(n,t)),(t,e)=>t[0].getPropertyValue("--graph-color-1")===e[0].getPropertyValue("--graph-color-1")&&t[0].getPropertyValue("--color-1")===e[0].getPropertyValue("--color-1"))},29961:function(t,e,n){n.a(t,async function(t,o){try{n.d(e,{d:function(){return d},n:function(){return c}});var r=n(72487),a=n(30162),i=t([r,a]);function d(t,e,n){return"month"===t?{formatter:t=>{const o=new Date(t);return 0===o.getMonth()?`{bold|${(0,r.fr)(o,e,n)}}`:(0,r.Wq)(o,e,n)}}:"year"===t?{formatter:t=>(0,r.Pm)(new Date(t),e,n)}:void 0}function c(t,e,n,o){const i=o/60/24,s=new Date(t);if(i>88)return 0===s.getMonth()?`{bold|${(0,r.fr)(s,e,n)}}`:(0,r.Wq)(s,e,n);if(i>35)return 1===s.getDate()?`{bold|${(0,r.sl)(s,e,n)}}`:(0,r.sl)(s,e,n);if(i>7){const t=(0,r.sl)(s,e,n);return 1===s.getDate()?`{bold|${t}}`:t}return i>2?(0,r.gu)(s,e,n):o&&o<5?(0,a.ie)(s,e,n):0===s.getHours()&&0===s.getMinutes()&&0===s.getSeconds()?`{bold|${(0,r.sl)(s,e,n)}}`:(0,a.fU)(s,e,n)}[r,a]=i.then?(await i)():i,o()}catch(s){o(s)}})},33062:function(t,e,n){n(62953);var o=n(40445),r=n(5124),a=n(67576);let i;class s extends r.WF{willUpdate(t){t.has("color")&&(this.style.backgroundColor=this.color)}render(){return r.s6}constructor(...t){super(...t),this.color="",this.rtl=!1}}s.styles=(0,r.AH)(i||(i=(t=>t)`:host{display:inline-block;margin-inline-end:4px;margin-inline-start:initial;border-radius:10px;width:10px;height:10px;vertical-align:middle}:host([rtl]){direction:rtl}`)),(0,o.Cg)([(0,a.MZ)()],s.prototype,"color",void 0),(0,o.Cg)([(0,a.MZ)({type:Boolean,reflect:!0})],s.prototype,"rtl",void 0),s=(0,o.Cg)([(0,a.EM)("ha-chart-tooltip-marker")],s)},3609:function(t,e,n){n.a(t,async function(t,e){try{n(46449),n(44114),n(72712),n(26910),n(93514),n(18111),n(22489),n(20116),n(7588),n(61701),n(18237),n(45367),n(92731),n(17642),n(58004),n(33853),n(45876),n(32475),n(15024),n(31698),n(62953);var o=n(40445),r=n(67576),a=n(5124),i=n(22786),s=n(88696),d=n(1087),c=n(13234),u=n(3461),l=n(44439),h=(n(33062),n(38962)),g=t([l,h,s]);[l,h,s]=g.then?(await g)():g;let f,p,y,v,x,b=t=>t;const m=5,k=12,I=6,_=5;class z extends a.WF{render(){var t;const e={grid:{top:0,bottom:0,left:0,right:0},tooltip:{trigger:"item",formatter:this._renderTooltip,appendTo:document.body}};return(0,a.qy)(f||(f=b`<ha-chart-base .hass="${0}" .data="${0}" .options="${0}" height="100%" .extraComponents="${0}" @chart-click="${0}" @chart-sankeyroam="${0}"></ha-chart-base>`),this.hass,this._createData(this.data,null===(t=this._sizeController.value)||void 0===t?void 0:t.width),e,[c.A],this._handleChartClick,this._handleChartSankeyRoam)}_processLinks(t,e){const n=new Map,o=new Map,r=[];return e.forEach(e=>{var a;const i=t.find(t=>t.id===e.source),s=t.find(t=>t.id===e.target);if(!i||!s)return;const d=o.get(i.id)||0,c=n.get(s.id)||0,u=i.value-d,l=s.value-c,h=Math.min(null!==(a=e.value)&&void 0!==a?a:u,u,l);n.set(s.id,c+h),o.set(i.id,d+h),h>0&&r.push(Object.assign(Object.assign({},e),{},{value:h}))}),r}_findParentIndex(t,e,n){const o=e.filter(e=>e.target===t).map(t=>t.source);if(0===o.length)return-1;let r=0,a=0;for(const i of o){let t=0;for(let e=n.length-1;e>=0;e--){const o=n[e],s=o.findIndex(t=>t.id===i);if(-1!==s){r+=t+s,a++;break}t+=o.length}}return a>0?r/a:-1}constructor(...t){super(...t),this.data={nodes:[],links:[]},this.vertical=!1,this._currentZoom=1,this._sizeController=new s.P(this,{callback:t=>{var e;return null===(e=t[0])||void 0===e?void 0:e.contentRect}}),this._renderTooltip=t=>{const e=t.data,n=this.valueFormatter?this.valueFormatter(e.value):e.value,o=(0,a.qy)(p||(p=b`<div style="direction:ltr;display:inline"> ${0} </div>`),n);if(e.id){var r,i;const n=this.data.nodes.find(t=>t.id===e.id);return(0,a.qy)(y||(y=b`<ha-chart-tooltip-marker .color="${0}"></ha-chart-tooltip-marker> ${0}<br>${0}`),String(null!==(r=t.color)&&void 0!==r?r:""),null!==(i=null==n?void 0:n.label)&&void 0!==i?i:e.id,o)}if(e.source&&e.target){var s,d;const t=this.data.nodes.find(t=>t.id===e.source),n=this.data.nodes.find(t=>t.id===e.target);return(0,a.qy)(v||(v=b`${0}${0}<br>${0}`),null!==(s=null==t?void 0:t.label)&&void 0!==s?s:e.source,null!==(d=null==n?void 0:n.label)&&void 0!==d?d:e.target,o)}return null},this._handleChartSankeyRoam=t=>{this._currentZoom=t.detail.zoom},this._handleChartClick=t=>{var e;const n=t.detail;if("node"!==n.dataType)return;const o=null===(e=n.data)||void 0===e?void 0:e.id;if(!o)return;const r=this.data.nodes.find(t=>t.id===o);null!=r&&r.entityId&&(0,d.r)(this,"node-click",{node:r})},this._createData=(0,i.A)((t,e=0)=>{const n=t.nodes.filter(t=>t.value>0),o=[...new Set(n.map(t=>t.index))].sort(),r=new Map,a=[];o.forEach((e,o)=>{r.set(e,o);const i=n.filter(t=>t.index===e);i.length>0&&a.push(a.length>0?i.sort((e,n)=>{const o=this._findParentIndex(e.id,t.links,a),r=this._findParentIndex(n.id,t.links,a);return o===r?0:-1===o?1:-1===r?-1:o-r}):i)});const i=this._processLinks(n,t.links),s=e/o.length-30-_;return{id:"sankey",type:"sankey",nodes:a.flat().map(t=>({id:t.id,value:t.value,itemStyle:{color:t.color},depth:r.get(t.index)})),links:i,draggable:!1,scaleLimit:{min:1,max:4},orient:this.vertical?"vertical":"horizontal",nodeWidth:15,nodeGap:I,lineStyle:{color:"gradient",opacity:.4,curveness:.5},layoutIterations:0,animationDuration:500,label:{formatter:e=>{var n,o;return null!==(n=null===(o=t.nodes.find(t=>t.id===e.data.id))||void 0===o?void 0:o.label)&&void 0!==n?n:e.data.id},position:this.vertical?"bottom":"right",distance:_,minMargin:5,overflow:"break"},labelLayout:t=>{if(this.vertical){const e=t.text.split(" ").reduce((t,e)=>t.length>e.length?t:e,""),n=(0,u.W)(e,k),o=(t.rect.width+6)*this._currentZoom,r=Math.min(k,o/n*k);return{fontSize:r>1?r:0,width:o,align:"center",dy:-2}}const e=(t.rect.height+8)*this._currentZoom,n=Math.min(e/t.labelRect.height*k,k);return{fontSize:n,lineHeight:n,width:s,height:t.rect.height}},top:this.vertical?0:m,bottom:this.vertical?25:m,left:this.vertical?m:0,right:this.vertical?m:s+_,emphasis:{focus:"adjacency"}}})}}z.styles=(0,a.AH)(x||(x=b`:host{display:block;flex:1;max-width:100%;background:var(--ha-card-background,var(--card-background-color))}ha-chart-base{width:100%;height:100%}`)),(0,o.Cg)([(0,r.MZ)({attribute:!1})],z.prototype,"hass",void 0),(0,o.Cg)([(0,r.MZ)({attribute:!1})],z.prototype,"data",void 0),(0,o.Cg)([(0,r.MZ)({type:Boolean})],z.prototype,"vertical",void 0),(0,o.Cg)([(0,r.MZ)({attribute:!1})],z.prototype,"valueFormatter",void 0),(0,o.Cg)([(0,r.wk)()],z.prototype,"_sizeController",void 0),z=(0,o.Cg)([(0,r.EM)("ha-sankey-chart")],z),e()}catch(f){e(f)}})},48949:function(t,e,n){n.d(e,{Q:function(){return s}});n(62953);var o=n(40445),r=n(67576),a=n(71769),i=n(84187);const s=t=>{class e extends t{connectedCallback(){super.connectedCallback(),this._unsubMql=(0,a.m)(this.mobileSizeQuery,t=>{this._isMobileSize=t})}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._unsubMql)||void 0===t||t.call(this),this._unsubMql=void 0}constructor(...t){super(...t),this._isMobileSize=!1,this._isMobileClient=i.M,this.mobileSizeQuery="all and (max-width: 450px), all and (max-height: 500px)"}}return(0,o.Cg)([(0,r.wk)()],e.prototype,"_isMobileSize",void 0),e}},54706:function(t,e,n){n.d(e,{E:function(){return a}});n(74423),n(18111),n(13579),n(3362),n(62953);var o=n(40445),r=n(67576);const a=t=>{class e extends t{connectedCallback(){super.connectedCallback(),this._checkSubscribed()}disconnectedCallback(){if(super.disconnectedCallback(),this.__unsubs){for(;this.__unsubs.length;){const t=this.__unsubs.pop();t instanceof Promise?t.then(t=>t()):t()}this.__unsubs=void 0}}updated(t){if(super.updated(t),t.has("hass"))this._checkSubscribed();else if(this.hassSubscribeRequiredHostProps)for(const e of t.keys())if(this.hassSubscribeRequiredHostProps.includes(e))return void this._checkSubscribed()}hassSubscribe(){return[]}_checkSubscribed(){var t;void 0!==this.__unsubs||!this.isConnected||void 0===this.hass||null!==(t=this.hassSubscribeRequiredHostProps)&&void 0!==t&&t.some(t=>void 0===this[t])||(this.__unsubs=this.hassSubscribe())}}return(0,o.Cg)([(0,r.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},13234:function(t,e,n){n.d(e,{A:function(){return _}});var o=n(47685),r=(n(78350),n(44114),n(72712),n(26910),n(30237),n(18111),n(22489),n(20116),n(30531),n(7588),n(61701),n(18237),n(13579),n(45367),n(92731),n(17642),n(58004),n(33853),n(45876),n(32475),n(15024),n(31698),n(62953),n(83354));function a(t){return"passThrough"in t}const i=1;function s(t,e){t.eachSeriesByType("sankey",t=>{if("justify"!==t.get("nodeAlign"))return;const n=t.get("nodeWidth"),o=t.get("nodeGap"),s=(0,r.Lj)(t,e).refContainer,{width:h,height:p}=s,y=t.getGraph();!function(t,e,n,o,r,s,h){const p=t.filter(t=>t.getLayout().value>0),y=[...new Set(p.map(t=>t.hostGraph.data.getRawDataItem(t.dataIndex).depth||0))].sort(),m=function(t,e){const n=[];return e.forEach(e=>{const o=function(t,e,n){if(0===t.getLayout().value)return[];const o=d(t.node1,e),r=d(t.node2,e),a=c(t),i=function(t,e,n){return n.slice(t+1,e)}(o.depthIndex,r.depthIndex,e),s=t.node1.hostGraph.data.getRawDataItem(t.node1.dataIndex),l=t.node2.hostGraph.data.getRawDataItem(t.node2.dataIndex),h=i.map(t=>{const e=function(t,e,n,o){return{passThrough:!0,id:u(t,e,n),value:o,depth:n,sourceId:t,targetId:e}}(s.id,l.id,t,a);return n.push(e),e.id});return h}(e,t,n);e.passThroughNodeIds=o}),n}(y,e),k=function(t,e,n,o,r,s,d,c){const{sectionSize:u,sectionDepthSize:h}=function(t,e,n,o,r){const a=("vertical"===t?e:n)-2*r,i="vertical"===t?n/o.length:e/o.length;return{sectionSize:a,sectionDepthSize:i}}(d,r,s,o,c),p=function(t,e){const n={};return t.forEach(t=>{const e=t.getLayout().depth;n[e]?n[e].push(t):n[e]=[t]}),e.forEach(t=>{n[t.depth]?n[t.depth].push(t):n[t.depth]=[t]}),n}(t,e),y=function(t,e,n){const o=e.map(e=>[...t[e]||[]]),r=o.map(g),a=(t,a)=>{const i=v(t,o,r,e,n),s=o[t],d=r[t];o[t]=a,r[t]=g(a);return v(t,o,r,e,n)<i||(o[t]=s,r[t]=d,!1)};for(let s=0;s<x;s++){let t=!1;for(let n=1;n<o.length;n++){const i=e[n-1],s=f(o[n],r[n-1],t=>l(t,"source",i,e));s.changed&&a(n,s.sorted)&&(t=!0)}for(let n=o.length-2;n>=0;n--){const i=e[n+1],s=f(o[n],r[n+1],t=>l(t,"target",i,e));s.changed&&a(n,s.sorted)&&(t=!0)}if(!t)break}const i={};return e.forEach((t,e)=>{i[t]=o[e]}),i}(p,o,n);let m=0;const k=o.map(t=>{const e=function(t){return t.map(t=>({node:t,id:t.id,value:a(t)?t.value:t.getLayout().value,x:0,y:0,dx:0,dy:0,size:0}))}(y[t]||[]),n=u-(e.length+1)*c,o=e.reduce((t,e)=>t+e.value,0),{nodes:r,valueToSizeRatio:i}=b(e,n,o,m);return i>m&&(m=i),{nodes:r,depth:t,totalValue:o,valueToSizeRatio:i}});return k.forEach((t,e)=>{!function(t,e,n,o,r,a){let s=0;t.valueToSizeRatio!==r?t.nodes.forEach(t=>{const e=Math.max(i,Math.floor(t.value/r));s+=e,t.size=e}):s=t.nodes.reduce((t,e)=>t+e.size,0);const d=n-s;let c=d/(t.nodes.length+1);t.nodes.forEach(n=>{"vertical"===a?(n.x=c,n.y=e*o):(n.x=e*o,n.y=c),c+=n.size+d/(t.nodes.length+1)})}(t,e,u,h,m,d)}),k.flatMap(t=>t.nodes)}(p,m,e,y,r,s,h,o);!function(t,e,n){const o=function(t){return"vertical"===t?{breadth:"x",depth:"y",breadthSize:"dx",depthSize:"dy"}:{breadth:"y",depth:"x",breadthSize:"dy",depthSize:"dx"}}(n),r="vertical"===n?"curveVertical":"curveHorizontal";(function(t,e,n){t.forEach(t=>{t[n.breadthSize]=t.size,t[n.depthSize]=e,a(t.node)||t.node.setLayout({x:t.x,y:t.y,dx:t.dx,dy:t.dy},!0)})})(t,e,o),function(t,e){t.forEach(t=>{a(t.node)||t.node.outEdges.forEach(n=>{const o=n.hostGraph.edgeData.getRawDataItem(n.dataIndex).value/t.value*t.size;n.setLayout({[e.breadthSize]:o,[e.depthSize]:0},!0)})})}(t,o),function(t,e){t.forEach(t=>{a(t.node)||(t.node.outEdges.sort((t,n)=>t.node2.getLayout()[e.breadth]-n.node2.getLayout()[e.breadth]),t.node.inEdges.sort((t,n)=>t.node1.getLayout()[e.breadth]-n.node1.getLayout()[e.breadth]))})}(t,o),t.forEach(e=>{a(e.node)||(function(t,e,n){if(a(t.node))return;let o=0;t.node.outEdges.forEach(r=>{r.setLayout({x:"vertical"===e?t.x+o:t.x+t.dx,y:"vertical"===e?t.y+t.dy:t.y+o},!0),o+=r.getLayout()[n.breadthSize]})}(e,n,o),function(t,e,n,o,r){if(a(t.node))return;let i=0;t.node.inEdges.forEach(a=>{const s=function(t,e,n,o){const r=[];return t.passThroughNodeIds.forEach(t=>{const a=e.find(e=>e.id===t);r.push({x:a.x,y:a.y,type:o}),"vertical"===n?r.push({x:a.x,y:a.y+a.dy,type:"line"}):r.push({x:a.x+a.dx,y:a.y,type:"line"})}),r}(a,e,n,r);a.setLayout({targets:[...s,{x:"vertical"===n?t.x+i:t.x,y:"vertical"===n?t.y:t.y+i,type:r}]},!0),i+=a.getLayout()[o.breadthSize]})}(e,t,n,o,r))})}(k,n,h)}(y.nodes,y.edges,n,o,h,p,t.get("orient"))})}function d(t,e){const n=t.hostGraph.data.getRawDataItem(t.dataIndex).depth||0,o=e.findIndex(t=>t===n);return{depth:n,depthIndex:o}}function c(t){return t.hostGraph.edgeData.getRawDataItem(t.dataIndex).value}function u(t,e,n){return`${t}-${e}-${n}`}function l(t,e,n,o){if(a(t)){return[{id:"source"===e?t.sourceId:t.targetId,weight:t.value},{id:u(t.sourceId,t.targetId,n),weight:t.value}]}const r="source"===e?t.inEdges:t.outEdges,i=[];return r.forEach(t=>{const r=t.node1.hostGraph.data.getRawDataItem(t.node1.dataIndex),a=t.node2.hostGraph.data.getRawDataItem(t.node2.dataIndex),s=d("source"===e?t.node1:t.node2,o).depth,l=c(t);if(s===n){const t="source"===e?r:a;return void i.push({id:t.id,weight:l})}("source"===e?s<n:s>n)&&i.push({id:u(r.id,a.id,n),weight:l})}),i}function h(t,e,n){let o=0,r=0;return t.forEach(({id:t,weight:n})=>{const a=e.get(t);void 0!==a&&(o+=a*n,r+=n)}),r>0?o/r:n}function g(t){const e=new Map;return t.forEach((t,n)=>e.set(t.id,n)),e}function f(t,e,n){const o=t.map((t,o)=>({node:t,index:o,barycenter:h(n(t),e,o)}));o.sort((t,e)=>t.barycenter-e.barycenter||t.index-e.index);const r=o.map(t=>t.node),a=r.some((e,n)=>e!==t[n]);return{sorted:r,changed:a}}function p(t,e,n,o,r,a){const i=[];return o.forEach(o=>{if(0===o.getLayout().value)return;const s=o.node1.hostGraph.data.getRawDataItem(o.node1.dataIndex),c=o.node2.hostGraph.data.getRawDataItem(o.node2.dataIndex),l=d(o.node1,n).depth,h=d(o.node2,n).depth;if(l>t||h<e)return;const g=l===t?s.id:u(s.id,c.id,t),f=h===e?c.id:u(s.id,c.id,e),p=r.get(g),y=a.get(f);void 0!==p&&void 0!==y&&i.push({sourceIdx:p,targetIdx:y})}),i}function y(t){let e=0;for(let n=0;n<t.length;n++)for(let o=n+1;o<t.length;o++){const r=t[n],a=t[o];(r.sourceIdx-a.sourceIdx)*(r.targetIdx-a.targetIdx)<0&&e++}return e}function v(t,e,n,o,r){let a=0;return t>0&&(a+=y(p(o[t-1],o[t],o,r,n[t-1],n[t]))),t<e.length-1&&(a+=y(p(o[t],o[t+1],o,r,n[t],n[t+1]))),a}const x=4;function b(t,e,n,o=0){let r=n/e;r<o&&(r=o);let a=0;const s=t.map(t=>{if(t.size===i)return t;let e=Math.floor(t.value/r);return e<i&&(a+=i-e,e=i),Object.assign(Object.assign({},t),{},{size:e})});return a>0?b(s,e-a,n,r):{nodes:s,valueToSizeRatio:r}}var m=n(30052);class k extends m.A{render(t,e,n){super.render(t,e,n);const o=t.getData("edge");t.getGraph().eachEdge(t=>{const e=t.getLayout(),n=t.getModel().getModel("lineStyle").get("curveness"),r=o.getItemGraphicEl(t.dataIndex);r.buildPath=t=>function(t,e,n){var o;if(null===(o=e.targets)||void 0===o||!o.length)return;t.moveTo(e.x,e.y);const r=e.targets[e.targets.length-1],a=[{x:e.x,y:e.y,type:r.type},...e.targets];for(let i=1;i<a.length;i++){const e=a[i],o=a[i-1];"curveHorizontal"===e.type?t.bezierCurveTo(o.x*(1-n)+e.x*n,o.y,e.x*(1-n)+o.x*n,e.y,e.x,e.y):"curveVertical"===e.type?t.bezierCurveTo(o.x,o.y*(1-n)+e.y*n,e.x,e.y*(1-n)+o.y*n,e.x,e.y):t.lineTo(e.x,e.y)}t.lineTo(r.x+e.dx,r.y+e.dy);for(let i=a.length-2;i>=0;i--){const o={x:a[i+1].x+e.dx,y:a[i+1].y+e.dy,type:a[i+1].type},r={x:a[i].x+e.dx,y:a[i].y+e.dy,type:o.type};"curveHorizontal"===r.type?t.bezierCurveTo(o.x*(1-n)+r.x*n,o.y,r.x*(1-n)+o.x*n,r.y,r.x,r.y):"curveVertical"===r.type?t.bezierCurveTo(o.x,o.y*(1-n)+r.y*n,r.x,r.y*(1-n)+o.y*n,r.x,r.y):t.lineTo(r.x,r.y)}t.closePath()}(t,e,n),r.dirtyShape()})}}var I=k;function _(t){(0,o.a)(t),t.registerLayout(s),t.registerChartView(I)}},84187:function(t,e,n){n.d(e,{M:function(){return o}});n(27495);const o=/(?:iphone|android|ipad)/i.test(navigator.userAgent)},3461:function(t,e,n){let o;function r(t,e,n="Roboto, Noto, sans-serif"){o||(o=document.createElement("canvas"));const r=o.getContext("2d");if(!r)return 0;r.font=`${e}px ${n}`;const a=r.measureText(t);return Math.ceil(Math.max(a.actualBoundingBoxRight+a.actualBoundingBoxLeft,a.width))}n.d(e,{W:function(){return r}})}}]);