iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 14.6 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[22629],{5127:function(e,t,s){s.a(e,async function(e,t){try{s(26910),s(13609),s(18111),s(61701),s(62953);var i=s(40445),a=s(5124),n=s(67576),o=s(89784),r=s(20058),l=s(67258),h=s(12587),c=s(36240),u=e([r]);r=(u.then?(await u)():u)[0];let d,g,v,_,p,f,m,b=e=>e;const y=(e,t,s)=>180*(0,c.NN)((0,c.S8)(e,t,s),t,s)/100;class x extends a.WF{connectedCallback(){super.connectedCallback(),this._rescaleOnConnect&&(this._rescaleSvg(),this._rescaleOnConnect=!1)}firstUpdated(e){super.firstUpdated(e),(0,h.m)(()=>{this._updated=!0,this.needle&&(this._angle=y(this.value,this.min,this.max)),this._segment_label=this._getSegmentLabel(),this._rescaleSvg()})}willUpdate(e){(e.has("levels")||e.has("min"))&&(this.levels?(this._sortedLevels=[...this.levels].sort((e,t)=>e.level-t.level),this._sortedLevels.length>0&&this._sortedLevels[0].level!==this.min&&this._sortedLevels.unshift({level:this.min,stroke:"var(--info-color)"})):this._sortedLevels=void 0)}updated(e){super.updated(e),this._updated&&(e.has("value")||e.has("valueText")||e.has("label")||e.has("_segment_label"))&&(this._angle=y(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg())}render(){var e;const t=40,s=Math.PI*t,i=y(this.value,this.min,this.max),n=this._updated?s*(1-i/180):s;return(0,a.JW)(d||(d=b` <svg viewBox="-50 -50 100 55" class="gauge"> <path class="levels-base" d="M -40 0 A 40 40 0 0 1 40 0"/> ${0} ${0} </svg> <svg class="text"> <text class="value-text" x="0" y="-5" dominant-baseline="middle" text-anchor="middle"> ${0}${0} </text> </svg> `),null===(e=this._sortedLevels)||void 0===e?void 0:e.map((e,s,i)=>{const n=e.level,o=s+1<i.length?i[s+1].level:this.max,r=y(n,this.min,this.max),l=y(o,this.min,this.max),h=l-r>180?1:0,c=-40*Math.cos(r*Math.PI/180),u=-40*Math.sin(r*Math.PI/180),d=0===s,p=s===i.length-1;if(d)return(0,a.JW)(g||(g=b` <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 ${0} 1 40 0"/> `),e.stroke,c,u,t,t,h);if(p){const s=l-.5,i=-40*Math.cos(s*Math.PI/180),n=-40*Math.sin(s*Math.PI/180);return(0,a.JW)(v||(v=b` <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 ${0} 1 40 0"/> <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 0 1 40 0"/> `),e.stroke,c,u,t,t,h,e.stroke,i,n,t,t)}return(0,a.JW)(_||(_=b` <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 ${0} 1 40 0"></path> `),e.stroke,c,u,t,t,h)}),this.needle?(0,a.JW)(p||(p=b` <path class="needle" d="M -34,-3 L -40,-1 A 1,1,0,0,0,-40,1 L -34,3 A 2,2,0,0,0,-34,-3 Z" style="${0}"/> `),(0,o.W)({transform:`rotate(${this._angle}deg)`})):(0,a.JW)(f||(f=b` <path class="value" d="M -40 0 A 40 40 0 0 1 40 0" stroke-dasharray="${0}" style="${0}"/> `),s,(0,o.W)({strokeDashoffset:`${n}`})),this._segment_label?this._segment_label:this.valueText||(0,r.ZV)(this.value,this.locale,this.formatOptions),this._segment_label?"":"%"===this.label?(0,l.d)(this.locale)+"%":` ${this.label}`)}_rescaleSvg(){if(!this.isConnected)return void(this._rescaleOnConnect=!0);const e=this.shadowRoot.querySelector(".text"),t=e.querySelector("text").getBBox();e.setAttribute("viewBox",`${t.x} ${t.y} ${t.width} ${t.height}`)}_getSegmentLabel(){if(this._sortedLevels)for(let e=this._sortedLevels.length-1;e>=0;e--)if(this.value>=this._sortedLevels[e].level)return this._sortedLevels[e].label;return""}constructor(...e){super(...e),this.min=0,this.max=100,this.value=0,this.needle=!1,this.label="",this._angle=0,this._updated=!1,this._segment_label="",this._rescaleOnConnect=!1}}x.styles=(0,a.AH)(m||(m=b`:host{position:relative}.levels-base{fill:none;stroke:var(--primary-background-color);stroke-width:12;stroke-linecap:butt}.level{fill:none;stroke-width:12;stroke-linecap:butt}.value{fill:none;stroke-width:12;stroke:var(--gauge-color);stroke-linecap:butt;transition:stroke-dashoffset 1s ease 0s}.needle{fill:var(--primary-text-color);stroke:var(--card-background-color);color:var(--primary-text-color);stroke-width:1;stroke-linecap:round;transform-origin:0 0;transition:all 1s ease 0s}.text{position:absolute;max-height:40%;max-width:55%;left:50%;bottom:10%;transform:translate(-50%,0%)}.value-text{font-size:var(--ha-font-size-l);fill:var(--primary-text-color);direction:ltr}`)),(0,i.Cg)([(0,n.MZ)({type:Number})],x.prototype,"min",void 0),(0,i.Cg)([(0,n.MZ)({type:Number})],x.prototype,"max",void 0),(0,i.Cg)([(0,n.MZ)({type:Number})],x.prototype,"value",void 0),(0,i.Cg)([(0,n.MZ)({attribute:!1})],x.prototype,"formatOptions",void 0),(0,i.Cg)([(0,n.MZ)({attribute:!1})],x.prototype,"valueText",void 0),(0,i.Cg)([(0,n.MZ)({attribute:!1})],x.prototype,"locale",void 0),(0,i.Cg)([(0,n.MZ)({type:Boolean})],x.prototype,"needle",void 0),(0,i.Cg)([(0,n.MZ)({type:Array})],x.prototype,"levels",void 0),(0,i.Cg)([(0,n.MZ)()],x.prototype,"label",void 0),(0,i.Cg)([(0,n.wk)()],x.prototype,"_angle",void 0),(0,i.Cg)([(0,n.wk)()],x.prototype,"_updated",void 0),(0,i.Cg)([(0,n.wk)()],x.prototype,"_segment_label",void 0),x=(0,i.Cg)([(0,n.EM)("ha-gauge")],x),t()}catch(d){t(d)}})},54706:function(e,t,s){s.d(t,{E:function(){return n}});s(74423),s(18111),s(13579),s(3362),s(62953);var i=s(40445),a=s(67576);const n=e=>{class t extends e{connectedCallback(){super.connectedCallback(),this._checkSubscribed()}disconnectedCallback(){if(super.disconnectedCallback(),this.__unsubs){for(;this.__unsubs.length;){const e=this.__unsubs.pop();e instanceof Promise?e.then(e=>e()):e()}this.__unsubs=void 0}}updated(e){if(super.updated(e),e.has("hass"))this._checkSubscribed();else if(this.hassSubscribeRequiredHostProps)for(const t of e.keys())if(this.hassSubscribeRequiredHostProps.includes(t))return void this._checkSubscribed()}hassSubscribe(){return[]}_checkSubscribed(){var e;void 0!==this.__unsubs||!this.isConnected||void 0===this.hass||null!==(e=this.hassSubscribeRequiredHostProps)&&void 0!==e&&e.some(e=>void 0===this[e])||(this.__unsubs=this.hassSubscribe())}}return(0,i.Cg)([(0,a.MZ)({attribute:!1})],t.prototype,"hass",void 0),t}},89979:function(e,t,s){s.a(e,async function(e,i){try{s.r(t);s(3362),s(62953);var a=s(40445),n=s(5124),o=s(67576),r=s(89784),l=(s(76776),s(5127)),h=(s(67094),s(38114)),c=s(54706),u=s(91874),d=s(784),g=e([l,h,u]);[l,h,u]=g.then?(await g)():g;let v,_,p,f,m=e=>e;const b="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z",y={maximumFractionDigits:0};class x extends((0,c.E)(n.WF)){static async getConfigElement(){return await s.e(79062).then(s.bind(s,54197)),document.createElement("hui-energy-graph-card-editor")}static getStubConfig(e,t,s){return{type:"energy-solar-consumed-gauge"}}hassSubscribe(){var e;return[(0,h.tb)(this.hass,{key:null===(e=this._config)||void 0===e?void 0:e.collection_key}).subscribe(e=>{this._data=e})]}getCardSize(){return 4}setConfig(e){e.collection_key&&(0,h.s8)(e.collection_key),this._config=e}shouldUpdate(e){return(0,d.xP)(this,e)||e.size>1||!e.has("hass")}render(){var e;if(!this._config||!this.hass)return n.s6;if(!this._data)return(0,n.qy)(v||(v=m`${0}`),this.hass.localize("ui.panel.lovelace.cards.energy.loading"));const{summedData:t,compareSummedData:s}=(0,h.gv)(this._data);if(!("solar"in t.total))return n.s6;const i=null!==(e=t.total.to_grid)&&void 0!==e?e:null;let a;if(null!==i){const e=!!t.to_battery||!!t.from_battery;a=(0,h.pe)(e,t)}return(0,n.qy)(_||(_=m` <ha-card> ${0} </ha-card> `),void 0!==a?(0,n.qy)(p||(p=m` <ha-gauge min="0" max="100" .value="${0}" label="%" .formatOptions="${0}" .locale="${0}" style="${0}"></ha-gauge> <ha-svg-icon id="info" .path="${0}"></ha-svg-icon> <ha-tooltip for="info" placement="left"> ${0} <br><br> ${0} </ha-tooltip> <div class="name"> ${0} </div> `),a,y,this.hass.locale,(0,r.W)({"--gauge-color":this._computeSeverity(a)}),b,this.hass.localize("ui.panel.lovelace.cards.energy.solar_consumed_gauge.card_indicates_solar_energy_used"),this.hass.localize("ui.panel.lovelace.cards.energy.solar_consumed_gauge.card_indicates_solar_energy_used_charge_home_bat"),this.hass.localize("ui.panel.lovelace.cards.energy.solar_consumed_gauge.self_consumed_solar_energy")):null!==i?this.hass.localize("ui.panel.lovelace.cards.energy.solar_consumed_gauge.not_produced_solar_energy"):this.hass.localize("ui.panel.lovelace.cards.energy.solar_consumed_gauge.self_consumed_solar_could_not_calc"))}_computeSeverity(e){return e>75?u.severityMap.green:e<50?u.severityMap.yellow:u.severityMap.normal}constructor(...e){super(...e),this.hassSubscribeRequiredHostProps=["_config"]}}x.styles=(0,n.AH)(f||(f=m`ha-card{height:100%;overflow:hidden;padding:16px;display:flex;align-items:center;justify-content:center;flex-direction:column;box-sizing:border-box}ha-gauge{width:100%;max-width:250px;direction:ltr}.name{text-align:center;line-height:initial;color:var(--primary-text-color);width:100%;font-size:var(--ha-font-size-m);margin-top:8px}ha-svg-icon{position:absolute;right:4px;inset-inline-end:4px;inset-inline-start:initial;top:4px;color:var(--secondary-text-color)}`)),(0,a.Cg)([(0,o.MZ)({attribute:!1})],x.prototype,"hass",void 0),(0,a.Cg)([(0,o.wk)()],x.prototype,"_config",void 0),(0,a.Cg)([(0,o.wk)()],x.prototype,"_data",void 0),x=(0,a.Cg)([(0,o.EM)("hui-energy-solar-consumed-gauge-card")],x),i()}catch(v){i(v)}})},91874:function(e,t,s){s.a(e,async function(e,i){try{s.r(t),s.d(t,{DEFAULT_MAX:function(){return N},DEFAULT_MIN:function(){return A},severityMap:function(){return z}});s(16280),s(26910),s(18111),s(20116),s(61701),s(3362),s(62953);var a=s(40445),n=s(5124),o=s(67576),r=s(6412),l=s(63672),h=s(89784),c=s(42372),u=s(78536),d=s(78649),g=(s(76776),s(5127)),v=s(22675),_=s(19037),p=s(13632),f=s(22064),m=s(97176),b=s(784),y=s(85979),x=e([g,y]);[g,y]=x.then?(await x)():x;let $,k,w,C,M,S=e=>e;const A=0,N=100,z={red:"var(--error-color)",green:"var(--success-color)",yellow:"var(--warning-color)",normal:"var(--info-color)"};class L extends n.WF{static async getConfigElement(){return await s.e(88292).then(s.bind(s,89647)),document.createElement("hui-gauge-card-editor")}static getStubConfig(e,t,s){return{type:"gauge",entity:(0,p.B)(e,1,t,s,["counter","input_number","number","sensor"],e=>!isNaN(Number(e.state)))[0]||""}}getCardSize(){return 4}setConfig(e){if(!e.entity)throw new Error("Entity must be specified");if(!(0,d.n)(e.entity))throw new Error("Invalid entity");this._config=Object.assign({min:A,max:N},e)}render(){var e,t;if(!this._config||!this.hass)return n.s6;const s=this.hass.states[this._config.entity];if(!s)return(0,n.qy)($||($=S` <hui-warning .hass="${0}"> ${0} </hui-warning> `),this.hass,(0,y.j)(this.hass,this._config.entity));if(s.state===v.Hh)return(0,n.qy)(k||(k=S` <hui-warning>${0}</hui-warning> `),this.hass.localize("ui.panel.lovelace.warning.entity_unavailable",{entity:this._config.entity}));let i;i=this._config.attribute?this.hass.formatEntityAttributeValueToParts(s,this._config.attribute):this.hass.formatEntityStateToParts(s);const a=null===(e=i.find(e=>"value"===e.type))||void 0===e?void 0:e.value,o=this._config.attribute?s.attributes[this._config.attribute]:s.state;if(isNaN(o))return(0,n.qy)(w||(w=S` <hui-warning>${0}</hui-warning> `),this.hass.localize(this._config.attribute?"ui.panel.lovelace.warning.attribute_not_numeric":"ui.panel.lovelace.warning.entity_non_numeric",{entity:this._config.entity,attribute:this._config.attribute}));const c=this.hass.formatEntityName(s,this._config.name),d=null!==(t=(0,u.h)(this.hass,s,this._config))&&void 0!==t?t:"";return(0,n.qy)(C||(C=S` <ha-card class="${0}" ="${0}" .actionHandler="${0}" tabindex="${0}"> <ha-gauge .min="${0}" .max="${0}" .value="${0}" .valueText="${0}" .locale="${0}" .label="${0}" style="${0}" .needle="${0}" .levels="${0}"></ha-gauge> <p class="title" .title="${0}">${0}</p> </ha-card> `),(0,r.H)({action:(0,m.A)(this._config)}),this._handleAction,(0,_.T)({hasHold:(0,m.h)(this._config.hold_action),hasDoubleClick:(0,m.h)(this._config.double_tap_action)}),(0,l.J)(!this._config.tap_action||(0,m.h)(this._config.tap_action)?"0":void 0),this._config.min,this._config.max,o,a,this.hass.locale,d,(0,h.W)({"--gauge-color":this._computeSeverity(Number(o))}),this._config.needle,this._config.needle?this._severityLevels():void 0,c,c)}shouldUpdate(e){return(0,b.LX)(this,e)}updated(e){if(super.updated(e),!this._config||!this.hass)return;const t=e.get("hass"),s=e.get("_config");t&&s&&t.themes===this.hass.themes&&s.theme===this._config.theme||(0,c.Q)(this,this.hass.themes,this._config.theme)}_computeSeverity(e){if(this._config.needle)return;let t=this._config.segments;if(t){t=[...t].sort((e,t)=>e.from-t.from);for(let i=0;i<t.length;i++){var s;const a=t[i];if(a&&e>=a.from&&(i+1===t.length||e<(null===(s=t[i+1])||void 0===s?void 0:s.from)))return a.color}return z.normal}const i=this._config.severity;if(!i)return z.normal;const a=Object.keys(i).map(e=>[e,i[e]]);for(const n of a)if(null==z[n[0]]||isNaN(n[1]))return z.normal;return a.sort((e,t)=>e[1]-t[1]),e>=a[0][1]&&e<a[1][1]?z[a[0][0]]:e>=a[1][1]&&e<a[2][1]?z[a[1][0]]:e>=a[2][1]?z[a[2][0]]:z.normal}_severityLevels(){const e=this._config.segments;if(e)return e.map(e=>({level:null==e?void 0:e.from,stroke:null==e?void 0:e.color,label:null==e?void 0:e.label}));const t=this._config.severity;if(!t)return[{level:0,stroke:z.normal}];return Object.keys(t).map(e=>({level:t[e],stroke:z[e]}))}_handleAction(e){(0,f.$)(this,this.hass,this._config,e.detail.action)}}L.styles=(0,n.AH)(M||(M=S`ha-card{height:100%;overflow:hidden;padding:var(--ha-space-3);display:flex;align-items:center;justify-content:center;flex-direction:column;box-sizing:border-box}ha-card.action{cursor:pointer}ha-card:focus{outline:0}.title{width:100%;font-size:var(--ha-font-size-m);line-height:var(--ha-line-height-expanded);margin:0;text-align:center;box-sizing:border-box;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:none;color:var(--primary-text-color)}ha-gauge{width:100%;max-width:250px}`)),(0,a.Cg)([(0,o.MZ)({attribute:!1})],L.prototype,"hass",void 0),(0,a.Cg)([(0,o.wk)()],L.prototype,"_config",void 0),L=(0,a.Cg)([(0,o.EM)("hui-gauge-card")],L),i()}catch($){i($)}})},36240:function(e,t,s){s.d(t,{NN:function(){return a},S8:function(){return i},gN:function(){return n}});const i=(e,t,s)=>isNaN(e)||isNaN(t)||isNaN(s)?0:e>s?s:e<t?t:e,a=(e,t,s)=>100*(e-t)/(s-t),n=e=>Math.round(10*e)/10},56434:function(e,t,s){s.d(t,{e:function(){return a}});var i=s(81977);function a(e,t,s){return(0,i.P)(e,12*t,s)}}}]);