UNPKG

iobroker.lovelace

Version:

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

1 lines 4.93 kB
export const __rspack_esm_id=90303;export const __rspack_esm_ids=[90303];export const __webpack_modules__={46754(t,e,a){a.a(t,async function(t,i){try{a.r(e),a.d(e,{HuiStatisticCardEditor:()=>k});a(18111),a(7588);var s=a(62826),n=a(5124),o=a(22441),c=a(22786),l=a(63533),r=a(1087),h=a(52763),_=a(23528),d=a(30345),p=a(84698),m=a(44155),y=a(89029),u=t([h,y]);[h,y]=u.then?(await u)():u;const g=(0,l.kp)(p.H,(0,l.Ik)({entity:(0,l.lq)((0,l.Yj)()),name:(0,l.lq)(m.q),icon:(0,l.lq)((0,l.Yj)()),unit:(0,l.lq)((0,l.Yj)()),stat_type:(0,l.lq)((0,l.Yj)()),period:(0,l.lq)((0,l.bz)()),theme:(0,l.lq)((0,l.Yj)()),footer:(0,l.lq)(d.zb),energy_date_selection:(0,l.lq)((0,l.zM)()),collection_key:(0,l.lq)((0,l.Yj)())})),f=["mean","min","max","change"],q={mean:"mean",min:"min",max:"max",change:"sum"};class k extends n.WF{setConfig(t){(0,l.vA)(t,g),t.period===y.PERIOD_ENERGY&&(t={energy_date_selection:!0,...t,period:y.STATISTIC_CARD_DEFAULT_PERIOD}),this._config=t,this._fetchMetadata()}firstUpdated(){this._fetchMetadata().then(()=>{!this._config?.stat_type&&this._config?.entity&&(0,r.r)(this,"config-changed",{config:{...this._config,stat_type:this._metadata?.has_sum?"change":"mean"}})})}render(){if(!this.hass||!this._config)return n.s6;const t=this._config,e=this._schema(this.hass.localize,!!this._config.energy_date_selection,this._metadata);return n.qy` <ha-form .hass="${this.hass}" .data="${t}" .schema="${e}" .computeHelper="${this._computeHelperCallback}" .computeLabel="${this._computeLabelCallback}" @value-changed="${this._valueChanged}"></ha-form> `}async _fetchMetadata(){this.hass&&this._config&&(this._metadata=(await(0,_.Wr)(this.hass,[this._config.entity]))[0])}async _valueChanged(t){const e={...t.detail.value};if(Object.keys(e).forEach(t=>""===e[t]&&delete e[t]),e.stat_type&&e.entity&&e.entity!==this._metadata?.statistic_id){const t=(await(0,_.Wr)(this.hass,[e.entity]))?.[0];t&&!t.has_sum&&"change"===e.stat_type&&(e.stat_type="mean"),t&&t.mean_type===_.ED.NONE&&"change"!==e.stat_type&&(e.stat_type="change")}if(!e.stat_type&&e.entity){const t=(await(0,_.Wr)(this.hass,[e.entity]))?.[0];e.stat_type=t?.has_sum?"change":"mean"}(0,r.r)(this,"config-changed",{config:e})}constructor(...t){super(...t),this._schema=(0,c.A)((t,e,a)=>[{name:"entity",required:!0,selector:{statistic:{}}},{name:"stat_type",required:!0,selector:{select:{multiple:!1,options:f.map(e=>({value:e,label:t(`ui.panel.lovelace.editor.card.statistic.stat_type_labels.${e}`),disabled:!a||!(0,_.nN)(a,q[e])}))}}},...e?[]:[{name:"period",required:!0,selector:{period:{options:["today","yesterday","this_week","last_week","this_month","last_month","this_year","last_year"]}}}],{name:"",type:"grid",schema:[...e?[{type:"string",name:"collection_key",required:!1}]:[],{name:"energy_date_selection",required:!1,selector:{boolean:{}}}]},{name:"name",selector:{entity_name:{}},context:{entity:"entity"}},{type:"grid",name:"",schema:[{name:"icon",selector:{icon:{}},context:{icon_entity:"entity"}},{name:"unit",selector:{text:{}}},{name:"theme",selector:{theme:{}}}]}]),this._computeHelperCallback=t=>{if("collection_key"===t.name)return this.hass.localize("ui.panel.lovelace.editor.card.generic.collection_key_description")},this._computeLabelCallback=t=>{switch(t.name){case"period":return this.hass.localize("ui.panel.lovelace.editor.card.statistic.period");case"theme":return`${this.hass.localize("ui.panel.lovelace.editor.card.generic.theme")} (${this.hass.localize("ui.panel.lovelace.editor.card.config.optional")})`;default:return this.hass.localize(`ui.panel.lovelace.editor.card.generic.${t.name}`)}}}}(0,s.Cg)([(0,o.MZ)({attribute:!1})],k.prototype,"hass",void 0),(0,s.Cg)([(0,o.wk)()],k.prototype,"_config",void 0),(0,s.Cg)([(0,o.wk)()],k.prototype,"_metadata",void 0),k=(0,s.Cg)([(0,o.EM)("hui-statistic-card-editor")],k),i()}catch(t){i(t)}})},84698(t,e,a){a.d(e,{H:()=>s});var i=a(63533);const s=(0,i.Ik)({type:(0,i.Yj)(),view_layout:(0,i.bz)(),layout_options:(0,i.bz)(),grid_options:(0,i.bz)(),visibility:(0,i.bz)(),disabled:(0,i.lq)((0,i.zM)())})},55904(t,e,a){a.d(e,{J:()=>n});var i=a(63533),s=a(91408);const n=(0,i.Ik)({entity:(0,i.Yj)(),name:(0,i.lq)((0,i.Yj)()),icon:(0,i.lq)((0,i.Yj)()),image:(0,i.lq)((0,i.Yj)()),show_name:(0,i.lq)((0,i.zM)()),show_icon:(0,i.lq)((0,i.zM)()),tap_action:(0,i.lq)(s.kn),hold_action:(0,i.lq)(s.kn),double_tap_action:(0,i.lq)(s.kn)})},30345(t,e,a){a.d(e,{oe:()=>l,zb:()=>r});var i=a(63533),s=a(91408),n=a(55904);const o=(0,i.Ik)({type:(0,i.Yj)(),image:(0,i.Yj)(),tap_action:(0,i.lq)(s.kn),hold_action:(0,i.lq)(s.kn),double_tap_action:(0,i.lq)(s.kn),alt_text:(0,i.lq)((0,i.Yj)())}),c=(0,i.Ik)({type:(0,i.Yj)(),entities:(0,i.YO)(n.J)}),l=(0,i.Ik)({type:(0,i.Yj)(),entity:(0,i.Yj)(),detail:(0,i.lq)((0,i.ai)()),hours_to_show:(0,i.lq)((0,i.ai)())}),r=(0,i.OR)(t=>{if(t&&"object"==typeof t&&"type"in t)switch(t.type){case"buttons":return c;case"graph":return l;case"picture":return o}return(0,i.KC)([c,l,o])})}};