UNPKG

iobroker.lovelace

Version:

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

1 lines 15.1 kB
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[77735],{5127:function(t,e,s){s.a(t,async function(t,e){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=t([r]);r=(u.then?(await u)():u)[0];let d,g,v,p,_,f,m,y=t=>t;const b=(t,e,s)=>180*(0,c.NN)((0,c.S8)(t,e,s),e,s)/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,s=Math.PI*e,i=b(this.value,this.min,this.max),n=this._updated?s*(1-i/180):s;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,s,i)=>{const n=t.level,o=s+1<i.length?i[s+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===s,_=s===i.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(_){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=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,i,n,e,e)}return(0,a.JW)(p||(p=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)(_||(_=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)(f||(f=y` <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 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,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),e()}catch(d){e(d)}})},54706:function(t,e,s){s.d(e,{E:function(){return n}});s(74423),s(18111),s(13579),s(3362),s(62953);var i=s(40445),a=s(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,i.Cg)([(0,a.MZ)({attribute:!1})],e.prototype,"hass",void 0),e}},57545:function(t,e,s){s.a(t,async function(t,i){try{s.r(e);s(72712),s(18111),s(18237),s(3362),s(62953);var a=s(40445),n=s(5124),o=s(67576),r=s(89784),l=s(79791),h=(s(76776),s(5127)),c=(s(67094),s(34127)),u=s(38114),d=s(54706),g=s(85979),v=s(91874),p=s(784),_=t([h,c,g,u,v]);[h,c,g,u,v]=_.then?(await _)():_;let f,m,y,b,x,$,k=t=>t;const w="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",C={maximumFractionDigits:0};class M extends((0,d.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(t,e,s){return{type:"energy-carbon-consumed-gauge"}}getCardSize(){return 4}setConfig(t){t.collection_key&&(0,u.s8)(t.collection_key),this._config=t}hassSubscribe(){var t;return[(0,u.tb)(this.hass,{key:null===(t=this._config)||void 0===t?void 0:t.collection_key}).subscribe(t=>{this._data=t})]}shouldUpdate(t){var e;return(0,p.xP)(this,t)||t.size>1||!t.has("hass")||!(null===(e=this._data)||void 0===e||!e.co2SignalEntity)&&this.hass.states[this._data.co2SignalEntity]!==t.get("hass").states[this._data.co2SignalEntity]}render(){var t;if(!this._config||!this.hass)return n.s6;if(!this._data)return(0,n.qy)(f||(f=k`${0}`),this.hass.localize("ui.panel.lovelace.cards.energy.loading"));if(!this._data.co2SignalEntity)return n.s6;if(!this.hass.states[this._data.co2SignalEntity])return(0,n.qy)(m||(m=k`<hui-warning .hass="${0}"> ${0} </hui-warning>`),this.hass,(0,g.j)(this.hass,this._data.co2SignalEntity));const{summedData:e,compareSummedData:s}=(0,u.gv)(this._data),i=null!==(t=e.total.from_grid)&&void 0!==t?t:0;let a;if(this._data.fossilEnergyConsumption){var o,h;const t=this._data.fossilEnergyConsumption?Object.values(this._data.fossilEnergyConsumption).reduce((t,e)=>t+e,0):0,s=null!==(o=e.total.solar)&&void 0!==o?o:0,n=null!==(h=e.total.to_grid)&&void 0!==h?h:0,r=i+Math.max(0,s-n);r&&(a=(0,l.L)(100*(1-t/r)))}return(0,n.qy)(y||(y=k` <ha-card> ${0} </ha-card> `),void 0!==a?(0,n.qy)(b||(b=k` <ha-gauge min="0" max="100" .value="${0}" .formatOptions="${0}" .locale="${0}" label="%" 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> `),a,C,this.hass.locale,(0,r.W)({"--gauge-color":this._computeSeverity(a)}),w,this.hass.localize("ui.panel.lovelace.cards.energy.carbon_consumed_gauge.card_indicates_energy_used"),this.hass.localize("ui.panel.lovelace.cards.energy.carbon_consumed_gauge.low_carbon_energy_consumed")):(0,n.qy)(x||(x=k`${0}`),this.hass.localize("ui.panel.lovelace.cards.energy.carbon_consumed_gauge.low_carbon_energy_not_calculated")))}_computeSeverity(t){return t<10?v.severityMap.red:t<30?v.severityMap.yellow:t>75?v.severityMap.green:v.severityMap.normal}constructor(...t){super(...t),this.hassSubscribeRequiredHostProps=["_config"]}}M.styles=(0,n.AH)($||($=k`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}.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})],M.prototype,"hass",void 0),(0,a.Cg)([(0,o.wk)()],M.prototype,"_config",void 0),(0,a.Cg)([(0,o.wk)()],M.prototype,"_data",void 0),M=(0,a.Cg)([(0,o.EM)("hui-energy-carbon-consumed-gauge-card")],M),i()}catch(f){i(f)}})},91874:function(t,e,s){s.a(t,async function(t,i){try{s.r(e),s.d(e,{DEFAULT_MAX:function(){return A},DEFAULT_MIN:function(){return E},severityMap:function(){return N}});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),p=s(19037),_=s(13632),f=s(22064),m=s(97176),y=s(784),b=s(85979),x=t([g,b]);[g,b]=x.then?(await x)():x;let $,k,w,C,M,S=t=>t;const E=0,A=100,N={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(t,e,s){return{type:"gauge",entity:(0,_.B)(t,1,e,s,["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:E,max:A},t)}render(){var t,e;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,b.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===(t=i.find(t=>"value"===t.type))||void 0===t?void 0:t.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!==(e=(0,u.h)(this.hass,s,this._config))&&void 0!==e?e:"";return(0,n.qy)(C||(C=S` <ha-card class="${0}" @action="${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,p.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"),s=t.get("_config");e&&s&&e.themes===this.hass.themes&&s.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 i=0;i<e.length;i++){var s;const a=e[i];if(a&&t>=a.from&&(i+1===e.length||t<(null===(s=e[i+1])||void 0===s?void 0:s.from)))return a.color}return N.normal}const i=this._config.severity;if(!i)return N.normal;const a=Object.keys(i).map(t=>[t,i[t]]);for(const n of a)if(null==N[n[0]]||isNaN(n[1]))return N.normal;return a.sort((t,e)=>t[1]-e[1]),t>=a[0][1]&&t<a[1][1]?N[a[0][0]]:t>=a[1][1]&&t<a[2][1]?N[a[1][0]]:t>=a[2][1]?N[a[2][0]]:N.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:N.normal}];return Object.keys(e).map(t=>({level:e[t],stroke:N[t]}))}_handleAction(t){(0,f.$)(this,this.hass,this._config,t.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(t,e,s){s.d(e,{NN:function(){return a},S8:function(){return i},gN:function(){return n}});const i=(t,e,s)=>isNaN(t)||isNaN(e)||isNaN(s)?0:t>s?s:t<e?e:t,a=(t,e,s)=>100*(t-e)/(s-e),n=t=>Math.round(10*t)/10},56434:function(t,e,s){s.d(e,{e:function(){return a}});var i=s(81977);function a(t,e,s){return(0,i.P)(t,12*e,s)}}}]);