iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
10 lines • 16.1 kB
JavaScript
export const __webpack_ids__=["84464"];export const __webpack_modules__={82062:function(e,t,i){i.a(e,(async function(e,t){try{var s=i(44249),a=i(72621),n=(i(9359),i(70104),i(57243)),o=i(15093),r=i(69634),l=i(50602),d=i(45061),c=i(76320),u=i(10916),h=e([l]);l=(h.then?(await h)():h)[0];const _=(e,t,i)=>180*(0,u.Ff)((0,u.Fv)(e,t,i),t,i)/100;(0,s.Z)([(0,o.Mo)("ha-gauge")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[(0,o.Cb)({type:Number})],key:"min",value:()=>0},{kind:"field",decorators:[(0,o.Cb)({type:Number})],key:"max",value:()=>100},{kind:"field",decorators:[(0,o.Cb)({type:Number})],key:"value",value:()=>0},{kind:"field",decorators:[(0,o.Cb)({attribute:!1})],key:"formatOptions",value:void 0},{kind:"field",decorators:[(0,o.Cb)({attribute:!1,type:String})],key:"valueText",value:void 0},{kind:"field",decorators:[(0,o.Cb)({attribute:!1})],key:"locale",value:void 0},{kind:"field",decorators:[(0,o.Cb)({type:Boolean})],key:"needle",value:()=>!1},{kind:"field",decorators:[(0,o.Cb)({type:Array})],key:"levels",value:void 0},{kind:"field",decorators:[(0,o.Cb)()],key:"label",value:()=>""},{kind:"field",decorators:[(0,o.SB)()],key:"_angle",value:()=>0},{kind:"field",decorators:[(0,o.SB)()],key:"_updated",value:()=>!1},{kind:"field",decorators:[(0,o.SB)()],key:"_segment_label",value:()=>""},{kind:"method",key:"firstUpdated",value:function(e){(0,a.Z)(i,"firstUpdated",this,3)([e]),(0,c.T)((()=>{this._updated=!0,this._angle=_(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg()}))}},{kind:"method",key:"updated",value:function(e){(0,a.Z)(i,"updated",this,3)([e]),this._updated&&(e.has("value")||e.has("valueText")||e.has("label")||e.has("_segment_label"))&&(this._angle=_(this.value,this.min,this.max),this._segment_label=this._getSegmentLabel(),this._rescaleSvg())}},{kind:"method",key:"render",value:function(){return n.YP` <svg viewBox="-50 -50 100 50" class="gauge"> ${this.needle&&this.levels?"":n.YP`<path class="dial" d="M -40 0 A 40 40 0 0 1 40 0"></path>`} ${this.levels?this.levels.sort(((e,t)=>e.level-t.level)).map(((e,t)=>{let i;if(0===t&&e.level!==this.min){const e=_(this.min,this.min,this.max);i=n.YP`<path stroke="var(--info-color)" class="level" d="M
${0-40*Math.cos(e*Math.PI/180)}
${0-40*Math.sin(e*Math.PI/180)}
A 40 40 0 0 1 40 0
"></path>`}const s=_(e.level,this.min,this.max);return n.YP`${i}<path stroke="${e.stroke}" class="level" d="M
${0-40*Math.cos(s*Math.PI/180)}
${0-40*Math.sin(s*Math.PI/180)}
A 40 40 0 0 1 40 0
"></path>`})):""} ${this.needle?n.YP`<path class="needle" d="M -25 -2.5 L -47.5 0 L -25 2.5 z" style="${(0,r.V)({transform:`rotate(${this._angle}deg)`})}"> </path>`:n.YP`<path class="value" d="M -40 0 A 40 40 0 1 0 40 0" style="${(0,r.V)({transform:`rotate(${this._angle}deg)`})}"></path>`} </svg> <svg class="text"> <text class="value-text"> ${this._segment_label?this._segment_label:this.valueText||(0,l.uf)(this.value,this.locale,this.formatOptions)}${this._segment_label?"":"%"===this.label?(0,d.K)(this.locale)+"%":` ${this.label}`} </text> </svg>`}},{kind:"method",key:"_rescaleSvg",value:function(){const e=this.shadowRoot.querySelector(".text"),t=e.querySelector("text").getBBox();e.setAttribute("viewBox",`${t.x} ${t.y} ${t.width} ${t.height}`)}},{kind:"method",key:"_getSegmentLabel",value:function(){if(this.levels){this.levels.sort(((e,t)=>e.level-t.level));for(let e=this.levels.length-1;e>=0;e--)if(this.value>=this.levels[e].level)return this.levels[e].label}return""}},{kind:"field",static:!0,key:"styles",value:()=>n.iv`:host{position:relative}.dial{fill:none;stroke:var(--primary-background-color);stroke-width:15}.value{fill:none;stroke-width:15;stroke:var(--gauge-color);transition:all 1s ease 0s}.needle{fill:var(--primary-text-color);transition:all 1s ease 0s}.level{fill:none;stroke-width:15}.gauge{display:block}.text{position:absolute;max-height:40%;max-width:55%;left:50%;bottom:-6%;transform:translate(-50%,0%)}.value-text{font-size:50px;fill:var(--primary-text-color);text-anchor:middle;direction:ltr}`}]}}),n.oi);t()}catch(e){t(e)}}))},17705:function(e,t,i){i.d(t,{Cj:()=>h,F7:()=>a,Hs:()=>S,Kd:()=>b,Kj:()=>f,Nw:()=>m,PA:()=>n,Py:()=>l,Qm:()=>$,Z0:()=>p,_Y:()=>c,_m:()=>o,dL:()=>d,dO:()=>x,hN:()=>_,h_:()=>u,j2:()=>k,q6:()=>g,uR:()=>r});i(9359),i(52924);var s=i(47194);let a=function(e){return e[e.NONE=0]="NONE",e[e.ARITHMETIC=1]="ARITHMETIC",e[e.CIRCULAR=2]="CIRCULAR",e}({});const n=99387==i.j?["entity_not_recorded","entity_no_longer_recorded","state_class_removed","units_changed","mean_type_changed","no_state"]:null,o=e=>e.sendMessagePromise({type:"recorder/info"}),r=(e,t)=>e.callWS({type:"recorder/list_statistic_ids",statistic_type:t}),l=(e,t)=>e.callWS({type:"recorder/get_statistics_metadata",statistic_ids:t}),d=(e,t,i,s,a="hour",n,o)=>e.callWS({type:"recorder/statistics_during_period",start_time:t.toISOString(),end_time:i?.toISOString(),statistic_ids:s,period:a,units:n,types:o}),c=(e,t,i,s)=>e.callWS({type:"recorder/statistic_during_period",statistic_id:t,units:s,fixed_period:i.fixed_period?{start_time:i.fixed_period.start instanceof Date?i.fixed_period.start.toISOString():i.fixed_period.start,end_time:i.fixed_period.end instanceof Date?i.fixed_period.end.toISOString():i.fixed_period.end}:void 0,calendar:i.calendar,rolling_window:i.rolling_window}),u=e=>e.callWS({type:"recorder/validate_statistics"}),h=(e,t,i)=>e.callWS({type:"recorder/update_statistics_metadata",statistic_id:t,unit_of_measurement:i}),_=(e,t)=>e.callWS({type:"recorder/clear_statistics",statistic_ids:t}),f=e=>{let t=null;if(!e)return null;for(const i of e)null!==i.change&&void 0!==i.change&&(null===t?t=i.change:t+=i.change);return t},g=(e,t)=>{let i=null;for(const s of t){if(!(s in e))continue;const t=f(e[s]);null!==t&&(null===i?i=t:i+=t)}return i},m=(e,t)=>e.some((e=>void 0!==e[t]&&null!==e[t])),v=["mean","min","max"],y=["sum","state","change"],p=(e,t)=>!(!v.includes(t)||e.mean_type===a.NONE)||!(!y.includes(t)||!e.has_sum),k=(e,t,i,s,a)=>{const n=new Date(i).toISOString();return e.callWS({type:"recorder/adjust_sum_statistics",statistic_id:t,start_time:n,adjustment:s,adjustment_unit_of_measurement:a})},b=(e,t,i)=>{const a=e.states[t];return a?(0,s.C)(a):i?.name||t},x=(e,t,i)=>{let s;return t&&(s=e.states[t]?.attributes.unit_of_measurement),void 0===s?i?.statistics_unit_of_measurement:s},S=e=>e.includes(":"),$=e=>e.callWS({type:"recorder/update_statistics_issues"})},6736:function(e,t,i){i.d(t,{f:()=>o});var s=i(44249),a=i(72621),n=(i(9359),i(52924),i(15093));const o=e=>(0,s.Z)(null,(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[(0,n.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",key:"hassSubscribeRequiredHostProps",value:void 0},{kind:"field",key:"__unsubs",value:void 0},{kind:"method",key:"connectedCallback",value:function(){(0,a.Z)(i,"connectedCallback",this,3)([]),this._checkSubscribed()}},{kind:"method",key:"disconnectedCallback",value:function(){if((0,a.Z)(i,"disconnectedCallback",this,3)([]),this.__unsubs){for(;this.__unsubs.length;){const e=this.__unsubs.pop();e instanceof Promise?e.then((e=>e())):e()}this.__unsubs=void 0}}},{kind:"method",key:"updated",value:function(e){if((0,a.Z)(i,"updated",this,3)([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()}},{kind:"method",key:"hassSubscribe",value:function(){return[]}},{kind:"method",key:"_checkSubscribed",value:function(){void 0===this.__unsubs&&this.isConnected&&void 0!==this.hass&&!this.hassSubscribeRequiredHostProps?.some((e=>void 0===this[e]))&&(this.__unsubs=this.hassSubscribe())}}]}}),e)},33637:function(e,t,i){i.a(e,(async function(e,s){try{i.r(t);var a=i(44249),n=(i(9359),i(70104),i(57243)),o=i(15093),r=i(69634),l=(i(54977),i(82062)),d=(i(37583),i(1118)),c=i(17705),u=i(6736),h=i(10188),_=i(93331),f=e([l,d,h]);[l,d,h]=f.then?(await f)():f;const g="M13,9H11V7H13M13,17H11V11H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z",m={maximumFractionDigits:0};(0,a.Z)([(0,o.Mo)("hui-energy-solar-consumed-gauge-card")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[(0,o.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,o.SB)()],key:"_data",value:void 0},{kind:"field",key:"hassSubscribeRequiredHostProps",value:()=>["_config"]},{kind:"method",key:"hassSubscribe",value:function(){return[(0,d.UB)(this.hass,{key:this._config?.collection_key}).subscribe((e=>{this._data=e}))]}},{kind:"method",key:"getCardSize",value:function(){return 4}},{kind:"method",key:"setConfig",value:function(e){this._config=e}},{kind:"method",key:"shouldUpdate",value:function(e){return(0,_.SN)(this,e)||e.size>1||!e.has("hass")}},{kind:"method",key:"render",value:function(){if(!this._config||!this.hass)return n.Ld;if(!this._data)return n.dy`${this.hass.localize("ui.panel.lovelace.cards.energy.loading")}`;const e=this._data.prefs,t=(0,d.Jj)(e);if(!t.solar)return n.Ld;const i=(0,c.q6)(this._data.stats,t.solar.map((e=>e.stat_energy_from)))||0,s=(0,c.q6)(this._data.stats,t.grid[0].flow_to.map((e=>e.stat_energy_to)));let a;if(null!==s&&i){a=Math.max(0,i-s)/i*100}return n.dy` <ha-card> ${void 0!==a?n.dy` <ha-gauge min="0" max="100" .value="${a}" label="%" .formatOptions="${m}" .locale="${this.hass.locale}" style="${(0,r.V)({"--gauge-color":this._computeSeverity(a)})}"></ha-gauge> <ha-tooltip placement="left" hoist> <span slot="content"> ${this.hass.localize("ui.panel.lovelace.cards.energy.solar_consumed_gauge.card_indicates_solar_energy_used")} <br><br> ${this.hass.localize("ui.panel.lovelace.cards.energy.solar_consumed_gauge.card_indicates_solar_energy_used_charge_home_bat")} </span> <ha-svg-icon .path="${g}"></ha-svg-icon> </ha-tooltip> <div class="name"> ${this.hass.localize("ui.panel.lovelace.cards.energy.solar_consumed_gauge.self_consumed_solar_energy")} </div> `:0===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")} </ha-card> `}},{kind:"method",key:"_computeSeverity",value:function(e){return e>75?h.severityMap.green:e<50?h.severityMap.yellow:h.severityMap.normal}},{kind:"field",static:!0,key:"styles",value:()=>n.iv`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:15px;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,u.f)(n.oi));s()}catch(e){s(e)}}))},10188:function(e,t,i){i.a(e,(async function(e,s){try{i.r(t),i.d(t,{DEFAULT_MAX:()=>w,DEFAULT_MIN:()=>$,severityMap:()=>C});var a=i(44249),n=i(72621),o=(i(9359),i(70104),i(57243)),r=i(15093),l=i(20552),d=i(35359),c=i(69634),u=i(82393),h=i(47194),_=i(31064),f=i(50602),g=(i(54977),i(82062)),m=i(96194),v=i(3967),y=i(69223),p=i(1617),k=i(5684),b=i(93331),x=i(62577),S=e([g,f]);[g,f]=S.then?(await S)():S;const $=0,w=100,C={red:"var(--error-color)",green:"var(--success-color)",yellow:"var(--warning-color)",normal:"var(--info-color)"};(0,a.Z)([(0,r.Mo)("hui-gauge-card")],(function(e,t){class s extends t{constructor(...t){super(...t),e(this)}}return{F:s,d:[{kind:"method",static:!0,key:"getConfigElement",value:async function(){return await i.e("96212").then(i.bind(i,32137)),document.createElement("hui-gauge-card-editor")}},{kind:"method",static:!0,key:"getStubConfig",value:function(e,t,i){return{type:"gauge",entity:(0,y.j)(e,1,t,i,["counter","input_number","number","sensor"],(e=>!isNaN(Number(e.state))))[0]||""}}},{kind:"field",decorators:[(0,r.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,r.SB)()],key:"_config",value:void 0},{kind:"method",key:"getCardSize",value:function(){return 4}},{kind:"method",key:"setConfig",value:function(e){if(!e.entity)throw new Error("Entity must be specified");if(!(0,_.T)(e.entity))throw new Error("Invalid entity");this._config={min:$,max:w,...e}}},{kind:"method",key:"render",value:function(){if(!this._config||!this.hass)return o.Ld;const e=this.hass.states[this._config.entity];if(!e)return o.dy` <hui-warning> ${(0,x.i)(this.hass,this._config.entity)} </hui-warning> `;const t=Number(e.state);if(e.state===m.nZ)return o.dy` <hui-warning>${this.hass.localize("ui.panel.lovelace.warning.entity_unavailable",{entity:this._config.entity})}</hui-warning> `;if(isNaN(t))return o.dy` <hui-warning>${this.hass.localize("ui.panel.lovelace.warning.entity_non_numeric",{entity:this._config.entity})}</hui-warning> `;const i=this._config.name??(0,h.C)(e);return o.dy` <ha-card class="${(0,d.$)({action:(0,k.q)(this._config)})}" @action="${this._handleAction}" .actionHandler="${(0,v.K)({hasHold:(0,k._)(this._config.hold_action),hasDoubleClick:(0,k._)(this._config.double_tap_action)})}" tabindex="${(0,l.o)(!this._config.tap_action||(0,k._)(this._config.tap_action)?"0":void 0)}"> <ha-gauge .min="${this._config.min}" .max="${this._config.max}" .value="${e.state}" .formatOptions="${(0,f.l4)(e,this.hass.entities[e.entity_id])}" .locale="${this.hass.locale}" .label="${this._config.unit||this.hass?.states[this._config.entity].attributes.unit_of_measurement||""}" style="${(0,c.V)({"--gauge-color":this._computeSeverity(t)})}" .needle="${this._config.needle}" .levels="${this._config.needle?this._severityLevels():void 0}"></ha-gauge> <div class="name" .title="${i}">${i}</div> </ha-card> `}},{kind:"method",key:"shouldUpdate",value:function(e){return(0,b.G2)(this,e)}},{kind:"method",key:"updated",value:function(e){if((0,n.Z)(s,"updated",this,3)([e]),!this._config||!this.hass)return;const t=e.get("hass"),i=e.get("_config");t&&i&&t.themes===this.hass.themes&&i.theme===this._config.theme||(0,u.R)(this,this.hass.themes,this._config.theme)}},{kind:"method",key:"_computeSeverity",value:function(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++){const s=t[i];if(s&&e>=s.from&&(i+1===t.length||e<t[i+1]?.from))return s.color}return C.normal}const i=this._config.severity;if(!i)return C.normal;const s=Object.keys(i).map((e=>[e,i[e]]));for(const e of s)if(null==C[e[0]]||isNaN(e[1]))return C.normal;return s.sort(((e,t)=>e[1]-t[1])),e>=s[0][1]&&e<s[1][1]?C[s[0][0]]:e>=s[1][1]&&e<s[2][1]?C[s[1][0]]:e>=s[2][1]?C[s[2][0]]:C.normal}},{kind:"method",key:"_severityLevels",value:function(){const e=this._config.segments;if(e)return e.map((e=>({level:e?.from,stroke:e?.color,label:e?.label})));const t=this._config.severity;if(!t)return[{level:0,stroke:C.normal}];return Object.keys(t).map((e=>({level:t[e],stroke:C[e]})))}},{kind:"method",key:"_handleAction",value:function(e){(0,p.G)(this,this.hass,this._config,e.detail.action)}},{kind:"field",static:!0,key:"styles",value:()=>o.iv`ha-card{height:100%;overflow:hidden;padding:16px;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}ha-gauge{width:100%;max-width:250px}.name{text-align:center;line-height:initial;color:var(--primary-text-color);width:100%;font-size:15px;margin-top:8px}`}]}}),o.oi);s()}catch(e){s(e)}}))},10916:function(e,t,i){i.d(t,{Ff:()=>a,Fv:()=>s,IU:()=>n});const s=(e,t,i)=>isNaN(e)||isNaN(t)||isNaN(i)?0:e>i?i:e<t?t:e,a=(e,t,i)=>100*(e-t)/(i-t),n=e=>Math.round(10*e)/10}};
//# sourceMappingURL=84464.d7ba2f64e2634c29.js.map