iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 14 kB
JavaScript
export const __rspack_esm_id=77735;export const __rspack_esm_ids=[77735];export const __webpack_modules__={5127(t,e,s){s.a(t,async function(t,e){try{s(18111),s(61701);var i=s(62826),a=s(5124),o=s(22441),n=s(89784),r=s(20058),l=s(67258),h=s(12587),c=s(36240),u=t([r]);r=(u.then?(await u)():u)[0];const d=(t,e,s)=>180*(0,c.NN)((0,c.S8)(t,e,s),e,s)/100;class g 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=d(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=d(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg())}render(){const t=40,e=Math.PI*t,s=d(this.value,this.min,this.max),i=this._updated?e*(1-s/180):e;return a.JW` <svg viewBox="-50 -50 100 55" class="gauge"> <path class="levels-base" d="M -40 0 A 40 40 0 0 1 40 0"/> ${this._sortedLevels?.map((e,s,i)=>{const o=e.level,n=s+1<i.length?i[s+1].level:this.max,r=d(o,this.min,this.max),l=d(n,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),g=0===s,_=s===i.length-1;if(g)return a.JW` <path class="level" stroke="${e.stroke}" style="stroke-linecap:butt" d="M ${c} ${u} A ${t} ${t} 0 ${h} 1 40 0"/> `;if(_){const s=l-.5,i=-40*Math.cos(s*Math.PI/180),o=-40*Math.sin(s*Math.PI/180);return a.JW` <path class="level" stroke="${e.stroke}" style="stroke-linecap:butt" d="M ${c} ${u} A ${t} ${t} 0 ${h} 1 40 0"/> <path class="level" stroke="${e.stroke}" style="stroke-linecap:butt" d="M ${i} ${o} A ${t} ${t} 0 0 1 40 0"/> `}return a.JW` <path class="level" stroke="${e.stroke}" style="stroke-linecap:butt" d="M ${c} ${u} A ${t} ${t} 0 ${h} 1 40 0"></path> `})} ${this.needle?a.JW` <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,n.W)({transform:`rotate(${this._angle}deg)`})}"/> `:a.JW` <path class="value" d="M -40 0 A 40 40 0 0 1 40 0" stroke-dasharray="${e}" style="${(0,n.W)({strokeDashoffset:`${i}`})}"/> `} </svg> <svg class="text"> <text class="value-text" x="0" y="-5" dominant-baseline="middle" text-anchor="middle"> ${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}`} </text> </svg> `}_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}}g.styles=a.AH`: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,o.MZ)({type:Number})],g.prototype,"min",void 0),(0,i.Cg)([(0,o.MZ)({type:Number})],g.prototype,"max",void 0),(0,i.Cg)([(0,o.MZ)({type:Number})],g.prototype,"value",void 0),(0,i.Cg)([(0,o.MZ)({attribute:!1})],g.prototype,"formatOptions",void 0),(0,i.Cg)([(0,o.MZ)({attribute:!1})],g.prototype,"valueText",void 0),(0,i.Cg)([(0,o.MZ)({attribute:!1})],g.prototype,"locale",void 0),(0,i.Cg)([(0,o.MZ)({type:Boolean})],g.prototype,"needle",void 0),(0,i.Cg)([(0,o.MZ)({type:Array})],g.prototype,"levels",void 0),(0,i.Cg)([(0,o.MZ)()],g.prototype,"label",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_angle",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_updated",void 0),(0,i.Cg)([(0,o.wk)()],g.prototype,"_segment_label",void 0),g=(0,i.Cg)([(0,o.EM)("ha-gauge")],g),e()}catch(t){e(t)}})},54706(t,e,s){s.d(e,{E:()=>o});s(74423),s(18111),s(13579);var i=s(62826),a=s(22441);const o=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(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&!this.hassSubscribeRequiredHostProps?.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(t,e,s){s.a(t,async function(t,i){try{s.r(e);s(18111),s(18237);var a=s(62826),o=s(5124),n=s(22441),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),_=s(91874),p=s(784),v=t([h,c,g,u,_]);[h,c,g,u,_]=v.then?(await v)():v;const m="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",f={maximumFractionDigits:0};class y extends((0,d.E)(o.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(){return[(0,u.tb)(this.hass,{key:this._config?.collection_key}).subscribe(t=>{this._data=t})]}shouldUpdate(t){return(0,p.xP)(this,t)||t.size>1||!t.has("hass")||!!this._data?.co2SignalEntity&&this.hass.states[this._data.co2SignalEntity]!==t.get("hass").states[this._data.co2SignalEntity]}render(){if(!this._config||!this.hass)return o.s6;if(!this._data)return o.qy`${this.hass.localize("ui.panel.lovelace.cards.energy.loading")}`;if(!this._data.co2SignalEntity)return o.s6;if(!this.hass.states[this._data.co2SignalEntity])return o.qy`<hui-warning .hass="${this.hass}"> ${(0,g.j)(this.hass,this._data.co2SignalEntity)} </hui-warning>`;const{summedData:t,compareSummedData:e}=(0,u.gv)(this._data),s=t.total.from_grid??0;let i;if(this._data.fossilEnergyConsumption){const e=this._data.fossilEnergyConsumption?Object.values(this._data.fossilEnergyConsumption).reduce((t,e)=>t+e,0):0,a=t.total.solar??0,o=t.total.to_grid??0,n=s+Math.max(0,a-o);n&&(i=(0,l.L)(100*(1-e/n)))}return o.qy` <ha-card> ${void 0!==i?o.qy` <ha-gauge min="0" max="100" .value="${i}" .formatOptions="${f}" .locale="${this.hass.locale}" label="%" style="${(0,r.W)({"--gauge-color":this._computeSeverity(i)})}"></ha-gauge> <ha-svg-icon id="info" .path="${m}"></ha-svg-icon> <ha-tooltip for="info" placement="left"> ${this.hass.localize("ui.panel.lovelace.cards.energy.carbon_consumed_gauge.card_indicates_energy_used")} </ha-tooltip> <div class="name"> ${this.hass.localize("ui.panel.lovelace.cards.energy.carbon_consumed_gauge.low_carbon_energy_consumed")} </div> `:o.qy`${this.hass.localize("ui.panel.lovelace.cards.energy.carbon_consumed_gauge.low_carbon_energy_not_calculated")}`} </ha-card> `}_computeSeverity(t){return t<10?_.severityMap.red:t<30?_.severityMap.yellow:t>75?_.severityMap.green:_.severityMap.normal}constructor(...t){super(...t),this.hassSubscribeRequiredHostProps=["_config"]}}y.styles=o.AH`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,n.MZ)({attribute:!1})],y.prototype,"hass",void 0),(0,a.Cg)([(0,n.wk)()],y.prototype,"_config",void 0),(0,a.Cg)([(0,n.wk)()],y.prototype,"_data",void 0),y=(0,a.Cg)([(0,n.EM)("hui-energy-carbon-consumed-gauge-card")],y),i()}catch(t){i(t)}})},91874(t,e,s){s.a(t,async function(t,i){try{s.r(e),s.d(e,{DEFAULT_MAX:()=>k,DEFAULT_MIN:()=>$,severityMap:()=>w});s(18111),s(20116),s(61701);var a=s(62826),o=s(5124),n=s(22441),r=s(6412),l=s(63672),h=s(89784),c=s(42372),u=s(78536),d=s(78649),g=(s(76776),s(5127)),_=s(22675),p=s(19037),v=s(13632),m=s(22064),f=s(97176),y=s(784),b=s(85979),x=t([g,b]);[g,b]=x.then?(await x)():x;const $=0,k=100,w={red:"var(--error-color)",green:"var(--success-color)",yellow:"var(--warning-color)",normal:"var(--info-color)"};class C extends o.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,v.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={min:$,max:k,...t}}render(){if(!this._config||!this.hass)return o.s6;const t=this.hass.states[this._config.entity];if(!t)return o.qy` <hui-warning .hass="${this.hass}"> ${(0,b.j)(this.hass,this._config.entity)} </hui-warning> `;if(t.state===_.Hh)return o.qy` <hui-warning>${this.hass.localize("ui.panel.lovelace.warning.entity_unavailable",{entity:this._config.entity})}</hui-warning> `;let e;e=this._config.attribute?this.hass.formatEntityAttributeValueToParts(t,this._config.attribute):this.hass.formatEntityStateToParts(t);const s=e.find(t=>"value"===t.type)?.value,i=this._config.attribute?t.attributes[this._config.attribute]:t.state;if(isNaN(i))return o.qy` <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})}</hui-warning> `;const a=this.hass.formatEntityName(t,this._config.name),n=(0,u.h)(this.hass,t,this._config)??"";return o.qy` <ha-card class="${(0,r.H)({action:(0,f.A)(this._config)})}" ="${this._handleAction}" .actionHandler="${(0,p.T)({hasHold:(0,f.h)(this._config.hold_action),hasDoubleClick:(0,f.h)(this._config.double_tap_action)})}" tabindex="${(0,l.J)(!this._config.tap_action||(0,f.h)(this._config.tap_action)?"0":void 0)}"> <ha-gauge .min="${this._config.min}" .max="${this._config.max}" .value="${i}" .valueText="${s}" .locale="${this.hass.locale}" .label="${n}" style="${(0,h.W)({"--gauge-color":this._computeSeverity(Number(i))})}" .needle="${this._config.needle}" .levels="${this._config.needle?this._severityLevels():void 0}"></ha-gauge> <p class="title" .title="${a}">${a}</p> </ha-card> `}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 s=0;s<e.length;s++){const i=e[s];if(i&&t>=i.from&&(s+1===e.length||t<e[s+1]?.from))return i.color}return w.normal}const s=this._config.severity;if(!s)return w.normal;const i=Object.keys(s).map(t=>[t,s[t]]);for(const t of i)if(null==w[t[0]]||isNaN(t[1]))return w.normal;return i.sort((t,e)=>t[1]-e[1]),t>=i[0][1]&&t<i[1][1]?w[i[0][0]]:t>=i[1][1]&&t<i[2][1]?w[i[1][0]]:t>=i[2][1]?w[i[2][0]]:w.normal}_severityLevels(){const t=this._config.segments;if(t)return t.map(t=>({level:t?.from,stroke:t?.color,label:t?.label}));const e=this._config.severity;if(!e)return[{level:0,stroke:w.normal}];return Object.keys(e).map(t=>({level:e[t],stroke:w[t]}))}_handleAction(t){(0,m.$)(this,this.hass,this._config,t.detail.action)}}C.styles=o.AH`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,n.MZ)({attribute:!1})],C.prototype,"hass",void 0),(0,a.Cg)([(0,n.wk)()],C.prototype,"_config",void 0),C=(0,a.Cg)([(0,n.EM)("hui-gauge-card")],C),i()}catch(t){i(t)}})},36240(t,e,s){s.d(e,{NN:()=>a,S8:()=>i,gN:()=>o});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),o=t=>Math.round(10*t)/10},56434(t,e,s){s.d(e,{e:()=>a});var i=s(81977);function a(t,e,s){return(0,i.P)(t,12*e,s)}}};