iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 12 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[36810],{45010:function(t,e,i){i.d(e,{U:function(){return n}});i(74423),i(18111),i(22489),i(61701),i(53921),i(62953);function n(t,e){const i=e.filter(e=>e in t).map(e=>[e,t[e]]),n=Object.entries(t).filter(([t])=>!e.includes(t));return Object.fromEntries([...i,...n])}},58548:function(t,e,i){i.d(e,{A:function(){return s}});i(16280),i(27495),i(25440);const n=t=>{const e=parseFloat(t);if(isNaN(e))throw new Error(`${t} is not a number`);return e};function s(t){if(!t)return null;try{if(t.endsWith("%"))return{w:100,h:n(t.slice(0,-1))};const e=t.replace(":","x").split("x");return 0===e.length?null:1===e.length?{w:n(e[0]),h:1}:{w:n(e[0]),h:n(e[1])}}catch(e){}return null}},17022:function(t,e,i){i.d(e,{A1:function(){return n},CY:function(){return o},Fn:function(){return s},Jz:function(){return l},St:function(){return r},VA:function(){return d},WI:function(){return h},iY:function(){return c},xw:function(){return a}});i(16280),i(3362);const n=(t,e)=>t.callWS({type:"media_source/resolve_media",media_content_id:e}),s=(t,e)=>t.callWS({type:"media_source/browse_media",media_content_id:e}),a="__MANUAL_ENTRY__",o=t=>t.startsWith(a),r=t=>t.startsWith("media-source://"),l=t=>t.startsWith("media-source://media_source"),c=t=>t.startsWith("media-source://image_upload"),d=async(t,e,i)=>{const n=new FormData;n.append("media_content_id",e),n.append("file",i);const s=await t.fetchWithAuth("/api/media_source/local_source/upload",{method:"POST",body:n});if(413===s.status)throw new Error(`Uploaded file is too large (${i.name})`);if(200!==s.status)throw new Error("Unknown error");return s.json()},h=async(t,e)=>t.callWS({type:"media_source/local_source/remove",media_content_id:e})},30592:function(t,e,i){i.a(t,async function(t,e){try{i(18111),i(61701),i(3362),i(88454),i(29452),i(62953);var n=i(40445),s=i(5124),a=i(67576),o=i(75751),r=i(1087),l=i(81816),c=i(15638),d=i(82474),h=i(26300),u=(i(85938),t([d,h]));[d,h]=u.then?(await u)():u;let m,g,p,_,y,f,b,v=t=>t;const x="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z",$="M21 11H3V9H21V11M21 13H3V15H21V13Z",C="M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z";class E extends s.WF{_getKey(t){return this._entityKeys.has(t)||this._entityKeys.set(t,Math.random().toString()),this._entityKeys.get(t)}_renderItem(t,e){const i=this.hass.states[t.entity],n=i&&(0,l.es)(i,this.hass.entities,this.hass.devices),a=(0,c.qC)(this.hass.language,this.hass.translationMetadata.translations),o=i&&this.hass.formatEntityName(i,n?{type:"device"}:{type:"entity"})||t.entity,r=i&&this.hass.formatEntityName(i,n?[{type:"area"}]:[{type:"area"},{type:"device"}],{separator:a?" ◂ ":" ▸ "});return(0,s.qy)(m||(m=v` <ha-md-list-item class="item"> <ha-svg-icon class="handle" .path="${0}" slot="start"></ha-svg-icon> <div slot="headline" class="label">${0}</div> ${0} <ha-icon-button slot="end" .item="${0}" .index="${0}" .label="${0}" .path="${0}" ="${0}"></ha-icon-button> <ha-icon-button slot="end" .index="${0}" .label="${0}" .path="${0}" ="${0}"></ha-icon-button> </ha-md-list-item> `),$,o,r?(0,s.qy)(g||(g=v`<div slot="supporting-text" class="description"> ${0} </div>`),r):s.s6,t,e,this.hass.localize("ui.common.edit"),C,this._editItem,e,this.hass.localize("ui.common.delete"),x,this._deleteItem)}_editItem(t){const e=t.currentTarget.index;(0,r.r)(this,"edit-detail-element",{subElementConfig:{index:e,type:"row",elementConfig:this.entities[e]}})}_deleteItem(t){const e=t.target.index,i=this.entities.slice(0,e).concat(this.entities.slice(e+1));(0,r.r)(this,"entities-changed",{entities:i})}render(){return this.entities?(0,s.qy)(p||(p=v` <h3> ${0} </h3> ${0} <ha-entity-picker .hass="${0}" .entityFilter="${0}" -changed="${0}" add-button></ha-entity-picker> `),this.label||`${this.hass.localize("ui.panel.lovelace.editor.card.generic.entities")}${this.required?` (${this.hass.localize("ui.panel.lovelace.editor.card.config.required")})`:""}`,this.canEdit?(0,s.qy)(_||(_=v` <div class="items-container"> <ha-sortable handle-selector=".handle" draggable-selector=".item" -moved="${0}"> <ha-md-list> ${0} </ha-md-list> </ha-sortable> </div> `),this._entityMoved,this.entities.map((t,e)=>this._renderItem(t,e))):(0,s.qy)(y||(y=v`<ha-sortable handle-selector=".handle" -moved="${0}"> <div class="entities"> ${0} </div> </ha-sortable>`),this._entityMoved,(0,o.u)(this.entities,t=>this._getKey(t),(t,e)=>(0,s.qy)(f||(f=v` <div class="entity" data-entity-id="${0}"> <div class="handle"> <ha-svg-icon .path="${0}"></ha-svg-icon> </div> <ha-entity-picker .hass="${0}" .value="${0}" .index="${0}" .entityFilter="${0}" -changed="${0}"></ha-entity-picker> </div> `),t.entity,$,this.hass,t.entity,e,this.entityFilter,this._valueChanged))),this.hass,this.entityFilter,this._addEntity):s.s6}async _addEntity(t){const e=t.detail.value;if(""===e)return;const i=this.entities.concat({entity:e});t.target.value="",(0,r.r)(this,"entities-changed",{entities:i})}_entityMoved(t){t.stopPropagation();const{oldIndex:e,newIndex:i}=t.detail,n=this.entities.concat();n.splice(i,0,n.splice(e,1)[0]),(0,r.r)(this,"entities-changed",{entities:n})}_valueChanged(t){const e=t.detail.value,i=t.target.index,n=this.entities.concat();""===e||void 0===e?n.splice(i,1):n[i]=Object.assign(Object.assign({},n[i]),{},{entity:e}),(0,r.r)(this,"entities-changed",{entities:n})}constructor(...t){super(...t),this.required=!0,this._entityKeys=new WeakMap}}E.styles=(0,s.AH)(b||(b=v`.entity{display:flex;align-items:center}.entity .handle{padding-right:8px;cursor:move;cursor:grab;padding-inline-end:8px;padding-inline-start:initial;direction:var(--direction)}.entity .handle>*{pointer-events:none}.entity ha-entity-picker{flex-grow:1}ha-md-list{gap:8px;padding-top:0;display:flex;flex-direction:column}ha-md-list:has(> *){margin-bottom:var(--ha-space-2)}ha-md-list-item{border:1px solid var(--divider-color);border-radius:8px;--ha-md-list-item-gap:0;--md-list-item-top-space:0;--md-list-item-bottom-space:0;--md-list-item-leading-space:12px;--md-list-item-trailing-space:4px;--md-list-item-two-line-container-height:48px;--md-list-item-one-line-container-height:48px}.handle{cursor:move;padding:8px;margin-inline-start:-8px}label{margin-bottom:8px;display:block}ha-md-list-item .description,ha-md-list-item .label{text-overflow:ellipsis;overflow:hidden;white-space:nowrap}`)),(0,n.Cg)([(0,a.MZ)({attribute:!1})],E.prototype,"hass",void 0),(0,n.Cg)([(0,a.MZ)({attribute:!1})],E.prototype,"entities",void 0),(0,n.Cg)([(0,a.MZ)({attribute:!1})],E.prototype,"entityFilter",void 0),(0,n.Cg)([(0,a.MZ)()],E.prototype,"label",void 0),(0,n.Cg)([(0,a.MZ)({type:Boolean})],E.prototype,"required",void 0),(0,n.Cg)([(0,a.MZ)({attribute:"can-edit",type:Boolean})],E.prototype,"canEdit",void 0),E=(0,n.Cg)([(0,a.EM)("hui-entity-editor")],E),e()}catch(m){e(m)}})},67801:function(t,e,i){i.a(t,async function(t,n){try{i.r(e),i.d(e,{HuiHistoryGraphCardEditor:function(){return O}});var s=i(86518),a=(i(62953),i(40445)),o=i(5124),r=i(67576),l=i(22786),c=i(63533),d=i(1087),h=i(71727),u=i(20058),m=i(52763),g=i(41544),p=i(30592),_=i(81287),y=i(88170),f=i(84698),b=i(20507),v=i(27538),x=t([m,p,_,g,u]);[m,p,_,g,u]=x.then?(await x)():x;const $=["color"];let C,E,w,q=t=>t;const M=(0,c.kp)(f.H,(0,c.Ik)({entities:(0,c.YO)(b.z),title:(0,c.lq)((0,c.Yj)()),hours_to_show:(0,c.lq)((0,c.ai)()),refresh_interval:(0,c.lq)((0,c.ai)()),show_names:(0,c.lq)((0,c.zM)()),logarithmic_scale:(0,c.lq)((0,c.zM)()),expand_legend:(0,c.lq)((0,c.zM)()),min_y_axis:(0,c.lq)((0,c.ai)()),max_y_axis:(0,c.lq)((0,c.ai)()),fit_y_data:(0,c.lq)((0,c.zM)())}));class O extends o.WF{setConfig(t){(0,c.vA)(t,M),this._config=t}render(){if(!this.hass||!this._config)return o.s6;if(this._subElementEditorConfig){const t=this._subElementEditorConfig.elementConfig.entity;return(0,o.qy)(C||(C=q` <hui-sub-element-editor .hass="${0}" .config="${0}" .form="${0}" -back="${0}" -changed="${0}"> </hui-sub-element-editor> `),this.hass,this._subElementEditorConfig,this._subForm(this.hass.localize,t),this._goBack,this._handleSubEntityChanged)}const t=this._schema(void 0!==this._config.min_y_axis||void 0!==this._config.max_y_axis),e=this._config.entities?(0,y._)(this._config.entities):[];return(0,o.qy)(E||(E=q` <ha-form .hass="${0}" .data="${0}" .schema="${0}" .computeLabel="${0}" -changed="${0}"></ha-form> <hui-entity-editor .hass="${0}" .entities="${0}" can-edit -changed="${0}" -detail-element="${0}"></hui-entity-editor> `),this.hass,this._config,t,this._computeLabelCallback,this._valueChanged,this.hass,e,this._entitiesChanged,this._editDetailElement)}_goBack(){this._subElementEditorConfig=void 0}_editDetailElement(t){this._subElementEditorConfig=t.detail.subElementConfig}_handleSubEntityChanged(t){t.stopPropagation();let e=t.detail.config;const i=e.entity;this._shouldDisableColorOption(i)&&(e=this._deleteColorOption(e));const n=this._subElementEditorConfig.index,s=[...this._config.entities];s[n]=e;let a=this._config;a=Object.assign(Object.assign({},a),{},{entities:s}),a=this._orderProperties(a),this._config=a,this._subElementEditorConfig=Object.assign(Object.assign({},this._subElementEditorConfig),{},{elementConfig:Object.assign({},this._config.entities[n])}),(0,d.r)(this,"config-changed",{config:a})}_valueChanged(t){const e=this._orderProperties(t.detail.value);(0,d.r)(this,"config-changed",{config:e})}_entitiesChanged(t){let e=this._config;e=Object.assign(Object.assign({},e),{},{entities:t.detail.entities}),e=this._orderProperties(e),(0,d.r)(this,"config-changed",{config:e})}_deleteColorOption(t){const{color:e}=t;return(0,s.A)(t,$)}_orderProperties(t){return(0,v.i)(t,M)}constructor(...t){super(...t),this._schema=(0,l.A)(t=>[{name:"title",selector:{text:{}}},{name:"",type:"grid",schema:[{name:"hours_to_show",default:g.DEFAULT_HOURS_TO_SHOW,selector:{number:{min:0,step:"any",mode:"box"}}},{name:"show_names",default:!0,required:!1,selector:{boolean:{}}},{name:"logarithmic_scale",required:!1,selector:{boolean:{}}},{name:"expand_legend",required:!1,selector:{boolean:{}}}]},{name:"",type:"grid",schema:[{name:"min_y_axis",required:!1,selector:{number:{mode:"box",step:"any"}}},{name:"max_y_axis",required:!1,selector:{number:{mode:"box",step:"any"}}}]},...t?[{name:"fit_y_data",required:!1,selector:{boolean:{}}}]:[]]),this._subForm=(0,l.A)((t,e)=>({schema:[{name:"entity",selector:{entity:{}},required:!0},{name:"name",selector:{entity_name:{}},context:{entity:"entity"}},{name:"color",disabled:this._shouldDisableColorOption(e),selector:{ui_color:{}}}],computeLabel:e=>{if("color"===e.name)return t(`ui.panel.lovelace.editor.card.generic.${e.name}`)}})),this._shouldDisableColorOption=t=>{const e=(0,h.m)(t),i="counter"===e||"number"===e||"input_number"===e,n=this.hass.states[t],s=null==n?void 0:n.attributes;return!(0,u.ty)(s)&&!i},this._computeLabelCallback=t=>{switch(t.name){case"show_names":case"logarithmic_scale":case"expand_legend":case"min_y_axis":case"max_y_axis":case"fit_y_data":return this.hass.localize(`ui.panel.lovelace.editor.card.history-graph.${t.name}`);default:return this.hass.localize(`ui.panel.lovelace.editor.card.generic.${t.name}`)}}}}O.styles=(0,o.AH)(w||(w=q`ha-form{margin-bottom:24px}`)),(0,a.Cg)([(0,r.MZ)({attribute:!1})],O.prototype,"hass",void 0),(0,a.Cg)([(0,r.wk)()],O.prototype,"_config",void 0),(0,a.Cg)([(0,r.wk)()],O.prototype,"_subElementEditorConfig",void 0),O=(0,a.Cg)([(0,r.EM)("hui-history-graph-card-editor")],O),n()}catch($){n($)}})},27538:function(t,e,i){i.d(e,{i:function(){return s}});i(18111),i(61701);var n=i(45010);const s=(t,e)=>{const i=Object.keys(e.schema),s=["entity","name","color"];let a=Object.assign({},(0,n.U)(t,i));const o=t.entities.map(t=>"string"!=typeof t?(0,n.U)(t,s):t);return a=Object.assign(Object.assign({},a),{entities:o}),a}}}]);