iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 14.5 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[35546],{5127:function(t,e,i){i.a(t,async function(t,e){try{i(26910),i(13609),i(18111),i(61701),i(62953);var s=i(40445),a=i(5124),n=i(67576),o=i(89784),r=i(20058),l=i(67258),h=i(12587),c=i(36240),u=t([r]);r=(u.then?(await u)():u)[0];let d,g,f,v,p,_,m,y=t=>t;const b=(t,e,i)=>180*(0,c.NN)((0,c.S8)(t,e,i),e,i)/100;class x extends a.WF{connectedCallback(){super.connectedCallback(),this._rescaleOnConnect&&(this._rescaleSvg(),this._rescaleOnConnect=!1)}firstUpdated(t){super.firstUpdated(t),(0,h.m)(()=>{this._updated=!0,this.needle&&(this._angle=b(this.value,this.min,this.max)),this._segment_label=this._getSegmentLabel(),this._rescaleSvg()})}willUpdate(t){(t.has("levels")||t.has("min"))&&(this.levels?(this._sortedLevels=[...this.levels].sort((t,e)=>t.level-e.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(t){super.updated(t),this._updated&&(t.has("value")||t.has("valueText")||t.has("label")||t.has("_segment_label"))&&(this._angle=b(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg())}render(){var t;const e=40,i=Math.PI*e,s=b(this.value,this.min,this.max),n=this._updated?i*(1-s/180):i;return(0,a.JW)(d||(d=y` <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===(t=this._sortedLevels)||void 0===t?void 0:t.map((t,i,s)=>{const n=t.level,o=i+1<s.length?s[i+1].level:this.max,r=b(n,this.min,this.max),l=b(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===i,p=i===s.length-1;if(d)return(0,a.JW)(g||(g=y` <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 ${0} 1 40 0"/> `),t.stroke,c,u,e,e,h);if(p){const i=l-.5,s=-40*Math.cos(i*Math.PI/180),n=-40*Math.sin(i*Math.PI/180);return(0,a.JW)(f||(f=y` <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"/> `),t.stroke,c,u,e,e,h,t.stroke,s,n,e,e)}return(0,a.JW)(v||(v=y` <path class="level" stroke="${0}" style="stroke-linecap:butt" d="M ${0} ${0} A ${0} ${0} 0 ${0} 1 40 0"></path> `),t.stroke,c,u,e,e,h)}),this.needle?(0,a.JW)(p||(p=y` <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)(_||(_=y` <path class="value" d="M -40 0 A 40 40 0 0 1 40 0" stroke-dasharray="${0}" style="${0}"/> `),i,(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 t=this.shadowRoot.querySelector(".text"),e=t.querySelector("text").getBBox();t.setAttribute("viewBox",`${e.x} ${e.y} ${e.width} ${e.height}`)}_getSegmentLabel(){if(this._sortedLevels)for(let t=this._sortedLevels.length-1;t>=0;t--)if(this.value>=this._sortedLevels[t].level)return this._sortedLevels[t].label;return""}constructor(...t){super(...t),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=y`: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,s.Cg)([(0,n.MZ)({type:Number})],x.prototype,"min",void 0),(0,s.Cg)([(0,n.MZ)({type:Number})],x.prototype,"max",void 0),(0,s.Cg)([(0,n.MZ)({type:Number})],x.prototype,"value",void 0),(0,s.Cg)([(0,n.MZ)({attribute:!1})],x.prototype,"formatOptions",void 0),(0,s.Cg)([(0,n.MZ)({attribute:!1})],x.prototype,"valueText",void 0),(0,s.Cg)([(0,n.MZ)({attribute:!1})],x.prototype,"locale",void 0),(0,s.Cg)([(0,n.MZ)({type:Boolean})],x.prototype,"needle",void 0),(0,s.Cg)([(0,n.MZ)({type:Array})],x.prototype,"levels",void 0),(0,s.Cg)([(0,n.MZ)()],x.prototype,"label",void 0),(0,s.Cg)([(0,n.wk)()],x.prototype,"_angle",void 0),(0,s.Cg)([(0,n.wk)()],x.prototype,"_updated",void 0),(0,s.Cg)([(0,n.wk)()],x.prototype,"_segment_label",void 0),x=(0,s.Cg)([(0,n.EM)("ha-gauge")],x),e()}catch(d){e(d)}})},54706:function(t,e,i){i.d(e,{E:function(){return n}});i(74423),i(18111),i(13579),i(3362),i(62953);var s=i(40445),a=i(67576);const n=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,s.Cg)([(0,a.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},48196:function(t,e,i){i.a(t,async function(t,s){try{i.r(e);i(3362),i(62953);var a=i(40445),n=i(5124),o=i(67576),r=i(89784),l=(i(76776),i(5127)),h=(i(67094),i(34127)),c=i(38114),u=i(54706),d=i(91874),g=i(784),f=t([l,h,c,d]);[l,h,c,d]=f.then?(await f)():f;let v,p,_,m,y=t=>t;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",x={maximumFractionDigits:0};class $ extends((0,u.E)(n.WF)){static async getConfigElement(){return await i.e(79062).then(i.bind(i,54197)),document.createElement("hui-energy-graph-card-editor")}static getStubConfig(t,e,i){return{type:"energy-self-sufficiency-gauge"}}hassSubscribe(){var t;return[(0,c.tb)(this.hass,{key:null===(t=this._config)||void 0===t?void 0:t.collection_key}).subscribe(t=>{this._data=t})]}getCardSize(){return 4}setConfig(t){t.collection_key&&(0,c.s8)(t.collection_key),this._config=t}shouldUpdate(t){return(0,g.xP)(this,t)||t.size>1||!t.has("hass")}render(){var t;if(!this._config||!this.hass)return n.s6;if(!this._data)return(0,n.qy)(v||(v=y`${0}`),this.hass.localize("ui.panel.lovelace.cards.energy.loading"));const{summedData:e,compareSummedData:i}=(0,c.gv)(this._data),{consumption:s,compareConsumption:a}=(0,c.DR)(e,void 0),o=null!==(t=e.total.from_grid)&&void 0!==t?t:0,l=Math.max(0,s.total.used_total);let h;return null!==o&&null!==l&&l>0&&(h=100*(1-Math.min(1,o/l))),(0,n.qy)(p||(p=y` <ha-card> ${0} </ha-card> `),void 0!==h?(0,n.qy)(_||(_=y` <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} </ha-tooltip> <div class="name"> ${0} </div> `),h,x,this.hass.locale,(0,r.W)({"--gauge-color":this._computeSeverity(h)}),b,this.hass.localize("ui.panel.lovelace.cards.energy.self_sufficiency_gauge.card_indicates_self_sufficiency_quota"),this.hass.localize("ui.panel.lovelace.cards.energy.self_sufficiency_gauge.self_sufficiency_quota")):this.hass.localize("ui.panel.lovelace.cards.energy.self_sufficiency_gauge.self_sufficiency_could_not_calc"))}_computeSeverity(t){return t>75?d.severityMap.green:t<50?d.severityMap.yellow:d.severityMap.normal}constructor(...t){super(...t),this.hassSubscribeRequiredHostProps=["_config"]}}$.styles=(0,n.AH)(m||(m=y`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)}ha-tooltip::part(base__popup){margin-top:4px}`)),(0,a.Cg)([(0,o.MZ)({attribute:!1})],$.prototype,"hass",void 0),(0,a.Cg)([(0,o.wk)()],$.prototype,"_config",void 0),(0,a.Cg)([(0,o.wk)()],$.prototype,"_data",void 0),$=(0,a.Cg)([(0,o.EM)("hui-energy-self-sufficiency-gauge-card")],$),s()}catch(v){s(v)}})},91874:function(t,e,i){i.a(t,async function(t,s){try{i.r(e),i.d(e,{DEFAULT_MAX:function(){return N},DEFAULT_MIN:function(){return A},severityMap:function(){return L}});i(16280),i(26910),i(18111),i(20116),i(61701),i(3362),i(62953);var a=i(40445),n=i(5124),o=i(67576),r=i(6412),l=i(63672),h=i(89784),c=i(42372),u=i(78536),d=i(78649),g=(i(76776),i(5127)),f=i(22675),v=i(19037),p=i(13632),_=i(22064),m=i(97176),y=i(784),b=i(85979),x=t([g,b]);[g,b]=x.then?(await x)():x;let $,k,w,C,M,S=t=>t;const A=0,N=100,L={red:"var(--error-color)",green:"var(--success-color)",yellow:"var(--warning-color)",normal:"var(--info-color)"};class z extends n.WF{static async getConfigElement(){return await i.e(88292).then(i.bind(i,89647)),document.createElement("hui-gauge-card-editor")}static getStubConfig(t,e,i){return{type:"gauge",entity:(0,p.B)(t,1,e,i,["counter","input_number","number","sensor"],t=>!isNaN(Number(t.state)))[0]||""}}getCardSize(){return 4}setConfig(t){if(!t.entity)throw new Error("Entity must be specified");if(!(0,d.n)(t.entity))throw new Error("Invalid entity");this._config=Object.assign({min:A,max:N},t)}render(){var t,e;if(!this._config||!this.hass)return n.s6;const i=this.hass.states[this._config.entity];if(!i)return(0,n.qy)($||($=S` <hui-warning .hass="${0}"> ${0} </hui-warning> `),this.hass,(0,b.j)(this.hass,this._config.entity));if(i.state===f.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 s;s=this._config.attribute?this.hass.formatEntityAttributeValueToParts(i,this._config.attribute):this.hass.formatEntityStateToParts(i);const a=null===(t=s.find(t=>"value"===t.type))||void 0===t?void 0:t.value,o=this._config.attribute?i.attributes[this._config.attribute]:i.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(i,this._config.name),d=null!==(e=(0,u.h)(this.hass,i,this._config))&&void 0!==e?e:"";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,v.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(t){return(0,y.LX)(this,t)}updated(t){if(super.updated(t),!this._config||!this.hass)return;const e=t.get("hass"),i=t.get("_config");e&&i&&e.themes===this.hass.themes&&i.theme===this._config.theme||(0,c.Q)(this,this.hass.themes,this._config.theme)}_computeSeverity(t){if(this._config.needle)return;let e=this._config.segments;if(e){e=[...e].sort((t,e)=>t.from-e.from);for(let s=0;s<e.length;s++){var i;const a=e[s];if(a&&t>=a.from&&(s+1===e.length||t<(null===(i=e[s+1])||void 0===i?void 0:i.from)))return a.color}return L.normal}const s=this._config.severity;if(!s)return L.normal;const a=Object.keys(s).map(t=>[t,s[t]]);for(const n of a)if(null==L[n[0]]||isNaN(n[1]))return L.normal;return a.sort((t,e)=>t[1]-e[1]),t>=a[0][1]&&t<a[1][1]?L[a[0][0]]:t>=a[1][1]&&t<a[2][1]?L[a[1][0]]:t>=a[2][1]?L[a[2][0]]:L.normal}_severityLevels(){const t=this._config.segments;if(t)return t.map(t=>({level:null==t?void 0:t.from,stroke:null==t?void 0:t.color,label:null==t?void 0:t.label}));const e=this._config.severity;if(!e)return[{level:0,stroke:L.normal}];return Object.keys(e).map(t=>({level:e[t],stroke:L[t]}))}_handleAction(t){(0,_.$)(this,this.hass,this._config,t.detail.action)}}z.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})],z.prototype,"hass",void 0),(0,a.Cg)([(0,o.wk)()],z.prototype,"_config",void 0),z=(0,a.Cg)([(0,o.EM)("hui-gauge-card")],z),s()}catch($){s($)}})},36240:function(t,e,i){i.d(e,{NN:function(){return a},S8:function(){return s},gN:function(){return n}});const s=(t,e,i)=>isNaN(t)||isNaN(e)||isNaN(i)?0:t>i?i:t<e?e:t,a=(t,e,i)=>100*(t-e)/(i-e),n=t=>Math.round(10*t)/10},56434:function(t,e,i){i.d(e,{e:function(){return a}});var s=i(81977);function a(t,e,i){return(0,s.P)(t,12*e,i)}}}]);