UNPKG

iobroker.lovelace

Version:

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

3 lines 19.3 kB
/*! For license information please see 37008.0b9a9de9734c0a19.js.LICENSE.txt */ export const __webpack_ids__=["37008"];export const __webpack_modules__={12582:function(e,t,i){i.d(t,{Z:()=>n});i(9359),i(31526),i(70104);function n(e){if(!e||"object"!=typeof e)return e;if("[object Date]"==Object.prototype.toString.call(e))return new Date(e.getTime());if(Array.isArray(e))return e.map(n);var t={};return Object.keys(e).forEach((function(i){t[i]=n(e[i])})),t}},92824:function(e,t,i){var n=i(44249),o=i(72621),s=i(60930),a=i(9714),l=i(57243),r=i(15093),d=i(22381),c=i(76320);i(23334);(0,n.Z)([(0,r.Mo)("ha-select")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[(0,r.Cb)({type:Boolean})],key:"icon",value:()=>!1},{kind:"field",decorators:[(0,r.Cb)({type:Boolean,reflect:!0})],key:"clearable",value:()=>!1},{kind:"field",decorators:[(0,r.Cb)({attribute:"inline-arrow",type:Boolean})],key:"inlineArrow",value:()=>!1},{kind:"field",decorators:[(0,r.Cb)()],key:"options",value:void 0},{kind:"method",key:"render",value:function(){return l.dy` ${(0,o.Z)(i,"render",this,3)([])} ${this.clearable&&!this.required&&!this.disabled&&this.value?l.dy`<ha-icon-button label="clear" @click="${this._clearValue}" .path="${"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"}"></ha-icon-button>`:l.Ld} `}},{kind:"method",key:"renderLeadingIcon",value:function(){return this.icon?l.dy`<span class="mdc-select__icon"><slot name="icon"></slot></span>`:l.Ld}},{kind:"method",key:"connectedCallback",value:function(){(0,o.Z)(i,"connectedCallback",this,3)([]),window.addEventListener("translations-updated",this._translationsUpdated)}},{kind:"method",key:"firstUpdated",value:async function(){(0,o.Z)(i,"firstUpdated",this,3)([]),this.inlineArrow&&this.shadowRoot?.querySelector(".mdc-select__selected-text-container")?.classList.add("inline-arrow")}},{kind:"method",key:"updated",value:function(e){if((0,o.Z)(i,"updated",this,3)([e]),e.has("inlineArrow")){const e=this.shadowRoot?.querySelector(".mdc-select__selected-text-container");this.inlineArrow?e?.classList.add("inline-arrow"):e?.classList.remove("inline-arrow")}e.get("options")&&(this.layoutOptions(),this.selectByValue(this.value))}},{kind:"method",key:"disconnectedCallback",value:function(){(0,o.Z)(i,"disconnectedCallback",this,3)([]),window.removeEventListener("translations-updated",this._translationsUpdated)}},{kind:"method",key:"_clearValue",value:function(){!this.disabled&&this.value&&(this.valueSetDirectly=!0,this.select(-1),this.mdcFoundation.handleChange())}},{kind:"field",key:"_translationsUpdated",value(){return(0,d.D)((async()=>{await(0,c.y)(),this.layoutOptions()}),500)}},{kind:"field",static:!0,key:"styles",value:()=>[a.W,l.iv`:host([clearable]){position:relative}.mdc-select:not(.mdc-select--disabled) .mdc-select__icon{color:var(--secondary-text-color)}.mdc-select__anchor{width:var(--ha-select-min-width,200px)}.mdc-select--filled .mdc-select__anchor{height:var(--ha-select-height,56px)}.mdc-select--filled .mdc-floating-label{inset-inline-start:12px;inset-inline-end:initial;direction:var(--direction)}.mdc-select--filled.mdc-select--with-leading-icon .mdc-floating-label{inset-inline-start:48px;inset-inline-end:initial;direction:var(--direction)}.mdc-select .mdc-select__anchor{padding-inline-start:12px;padding-inline-end:0px;direction:var(--direction)}.mdc-select__anchor .mdc-floating-label--float-above{transform-origin:var(--float-start)}.mdc-select__selected-text-container{padding-inline-end:var(--select-selected-text-padding-end,0px)}:host([clearable]) .mdc-select__selected-text-container{padding-inline-end:var(--select-selected-text-padding-end,12px)}ha-icon-button{position:absolute;top:10px;right:28px;--mdc-icon-button-size:36px;--mdc-icon-size:20px;color:var(--secondary-text-color);inset-inline-start:initial;inset-inline-end:28px;direction:var(--direction)}.inline-arrow{flex-grow:0}`]}]}}),s.K)},75625:function(e,t,i){i.a(e,(async function(e,n){try{i.d(t,{L:()=>a});var o=i(25508),s=e([o]);o=(s.then?(await s)():s)[0];const a=async(e,t,i,n)=>{let s={type:t};"conditional"!==t&&(s.style={left:"50%",top:"50%"});const a=await(0,o.Q)(t);if(a&&a.getStubConfig){const t=await a.getStubConfig(e,i,n);s={...s,...t}}return s};n()}catch(e){n(e)}}))},32012:function(e,t,i){i.d(t,{e:()=>n});class n extends Error{constructor(e,t,i){super(e),this.warnings=void 0,this.errors=void 0,this.name="GUISupportError",this.warnings=t,this.errors=i}}},43299:function(e,t,i){i.a(e,(async function(e,n){try{i.d(t,{O:()=>p});var o=i(44249),s=i(72621),a=(i(9359),i(31526),i(70104),i(57243)),l=i(15093),r=i(67064),d=i(36522),c=i(22381),h=i(41680),u=i(48045),m=(i(99426),i(17170)),f=(i(64889),i(32012)),g=e([m]);m=(g.then?(await g)():g)[0];let p=(0,o.Z)(null,(function(e,t){class n extends t{constructor(...t){super(...t),e(this)}}return{F:n,d:[{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"lovelace",value:void 0},{kind:"field",decorators:[(0,l.Cb)({attribute:!1})],key:"context",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_configElement",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_subElementEditorConfig",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_guiMode",value:()=>!0},{kind:"field",decorators:[(0,l.SB)()],key:"_errors",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_pendingYamlError",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_yamlError",value:()=>!1},{kind:"field",decorators:[(0,l.SB)()],key:"_warnings",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_guiSupported",value:void 0},{kind:"field",decorators:[(0,l.SB)()],key:"_loading",value:()=>!1},{kind:"field",decorators:[(0,l.IO)("ha-yaml-editor")],key:"_yamlEditor",value:void 0},{kind:"get",key:"value",value:function(){return this._config}},{kind:"set",key:"value",value:function(e){this._config&&(0,u.v)(e,this._config)||(this._config=e,this._errors=void 0,this._setConfig())}},{kind:"method",key:"_setConfig",value:function(){if(!this._errors)try{this._updateConfigElement()}catch(e){this._errors=[e.message]}this.updateComplete.then((()=>{(0,d.B)(this,"config-changed",{config:this.value,error:this._errors?.join(", "),guiModeAvailable:!(this.hasWarning||this.hasError||!1===this._guiSupported)})}))}},{kind:"get",key:"hasWarning",value:function(){return void 0!==this._warnings&&this._warnings.length>0}},{kind:"get",key:"hasError",value:function(){return void 0!==this._errors&&this._errors.length>0}},{kind:"get",key:"GUImode",value:function(){return this._guiMode}},{kind:"set",key:"GUImode",value:function(e){this._guiMode=e,this.updateComplete.then((()=>{(0,d.B)(this,"GUImode-changed",{guiMode:e,guiModeAvailable:!(this.hasWarning||this.hasError||!1===this._guiSupported)})}))}},{kind:"method",key:"toggleMode",value:function(){this.GUImode=!this.GUImode}},{kind:"method",key:"focusYamlEditor",value:function(){this._configElement?.focusYamlEditor&&this._configElement.focusYamlEditor(),this._yamlEditor&&this._yamlEditor.focus()}},{kind:"method",key:"getConfigElement",value:async function(){}},{kind:"method",key:"getConfigForm",value:async function(){}},{kind:"method",key:"renderConfigElement",value:function(){return a.dy`${this._configElement}`}},{kind:"method",key:"_renderSubElement",value:function(){return a.dy` <hui-sub-element-editor .hass="${this.hass}" .config="${this._subElementEditorConfig}" @go-back="${this._goBack}" @config-changed="${this._subElementChanged}"> </hui-sub-element-editor> `}},{kind:"method",key:"_subElementChanged",value:function(e){e.stopPropagation();const t=e.detail.config;this._subElementEditorConfig={...this._subElementEditorConfig,elementConfig:t},this._subElementEditorConfig.saveElementConfig?.(t)}},{kind:"method",key:"_goBack",value:function(e){e.stopPropagation(),this._subElementEditorConfig=void 0}},{kind:"method",key:"_editSubElement",value:async function(e){e.stopPropagation(),await Promise.all([i.e("91552"),i.e("78456"),i.e("56898"),i.e("35671"),i.e("92139"),i.e("32146"),i.e("37602"),i.e("18865"),i.e("88975"),i.e("79931"),i.e("44251"),i.e("65005"),i.e("60487"),i.e("3371"),i.e("38326"),i.e("10745"),i.e("16912"),i.e("92368"),i.e("95444"),i.e("8754"),i.e("54291"),i.e("76986")]).then(i.bind(i,50357)),this._subElementEditorConfig={type:e.detail.type,elementConfig:e.detail.config,context:e.detail.context,saveElementConfig:e.detail.saveConfig}}},{kind:"method",key:"render",value:function(){return a.dy` <div class="wrapper"> ${this.GUImode?a.dy` <div class="gui-editor" @edit-sub-element="${this._editSubElement}"> ${this._loading?a.dy` <ha-spinner class="center margin-bot"></ha-spinner> `:(0,r.F)(this._subElementEditorConfig?this._renderSubElement():this.renderConfigElement())} </div> `:a.dy` <div class="yaml-editor"> <ha-yaml-editor .defaultValue="${this._config}" autofocus .hass="${this.hass}" @value-changed="${this._handleYAMLChanged}" @blur="${this._onBlurYaml}" @keydown="${this._ignoreKeydown}" dir="ltr"></ha-yaml-editor> </div> `} ${!1===this._guiSupported&&!1===this._loading?a.dy` <ha-alert alert-type="info" .title="${this.hass.localize("ui.errors.config.visual_editor_not_supported")}"> ${this.hass.localize("ui.errors.config.visual_editor_not_supported_reason_type")} <br> ${this.hass.localize("ui.errors.config.edit_in_yaml_supported")} </ha-alert> `:a.Ld} ${this.hasError?a.dy` <ha-alert alert-type="error" .title="${this.hass.localize("ui.errors.config.configuration_error")}"> <ul> ${this._errors.map((e=>a.dy`<li>${e}</li>`))} </ul> </ha-alert> `:a.Ld} ${this.hasWarning?a.dy` <ha-alert alert-type="warning" .title="${this.hass.localize("ui.errors.config.visual_editor_not_supported")}"> <ul> ${this._warnings.map((e=>a.dy`<li>${e}</li>`))} </ul> ${this.hass.localize("ui.errors.config.edit_in_yaml_supported")} </ha-alert> `:a.Ld} </div> `}},{kind:"method",key:"updated",value:function(e){(0,s.Z)(n,"updated",this,3)([e]),this._configElement&&e.has("hass")&&(this._configElement.hass=this.hass),this._configElement&&"lovelace"in this._configElement&&e.has("lovelace")&&(this._configElement.lovelace=this.lovelace),this._configElement&&e.has("context")&&(this._configElement.context=this.context)}},{kind:"method",key:"_handleUIConfigChanged",value:function(e){if(e.stopPropagation(),!this.GUImode)return;const t=e.detail.config;Object.keys(t).forEach((e=>{void 0===t[e]&&delete t[e]})),this.value=t}},{kind:"method",key:"_handleYAMLChanged",value:function(e){e.stopPropagation();const t=e.detail.value;e.detail.isValid?(this._config=t,this._errors=void 0,this._pendingYamlError=void 0,this._yamlError=!1,this._debounceYamlError.cancel(),this._setConfig()):this._yamlError?this._errors=[e.detail.errorMsg]:(this._pendingYamlError=e.detail.errorMsg,this._debounceYamlError())}},{kind:"field",key:"_debounceYamlError",value(){return(0,c.D)((()=>{this._pendingYamlError&&(this._yamlError=!0,this._errors=[this._pendingYamlError],this._pendingYamlError=void 0,this._setConfig())}),2e3)}},{kind:"method",key:"_onBlurYaml",value:function(){this._debounceYamlError.cancel(),this._pendingYamlError&&(this._yamlError=!0,this._errors=[this._pendingYamlError],this._pendingYamlError=void 0,this._setConfig())}},{kind:"method",key:"unloadConfigElement",value:async function(){this._configElement=void 0,this._guiSupported=void 0}},{kind:"method",key:"loadConfigElement",value:async function(){if(this._configElement)return;let e=await this.getConfigElement();if(!e){const t=await this.getConfigForm();if(t){await i.e("10106").then(i.bind(i,66374)),e=document.createElement("hui-form-editor");const{schema:n,assertConfig:o,computeLabel:s,computeHelper:a}=t;e.schema=n,s&&(e.computeLabel=s),a&&(e.computeHelper=a),o&&(e.assertConfig=o)}}e?(e.hass=this.hass,"lovelace"in e&&(e.lovelace=this.lovelace),e.context=this.context,e.addEventListener("config-changed",(e=>this._handleUIConfigChanged(e))),this._guiSupported=!0):this._guiSupported=!1,this._configElement=e}},{kind:"method",key:"_updateConfigElement",value:async function(){if(this.value)try{if(this._errors=void 0,this._warnings=void 0,await this.loadConfigElement(),this._configElement)try{this._configElement.setConfig(this.value)}catch(e){const t=(0,h.p)(this.hass,e);throw new f.e("Config is not supported",t.warnings,t.errors)}else this._guiSupported=!1,this.GUImode=!1}catch(e){e instanceof f.e?(this._warnings=e.warnings??[e.message],this._errors=e.errors||void 0):this._errors=[e.message],this.GUImode=!1}finally{this._loading=!1}}},{kind:"method",key:"_ignoreKeydown",value:function(e){e.stopPropagation()}},{kind:"field",static:!0,key:"styles",value:()=>a.iv`:host{display:flex}.wrapper{width:100%}.gui-editor,.yaml-editor{padding:8px 0px}ha-code-editor{--code-mirror-max-height:calc(100vh - 245px)}ha-spinner{display:block;margin:auto}`}]}}),a.oi);n()}catch(e){n(e)}}))},13420:function(e,t,i){i.a(e,(async function(e,t){try{var n=i(44249),o=(i(9359),i(70104),i(12582)),s=i(57243),a=i(15093),l=i(36522),r=i(49976),d=(i(23334),i(37583),i(92824),i(76131)),c=i(75625),h=e([c]);c=(h.then?(await h)():h)[0];const u="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",m="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",f="M11,17H4A2,2 0 0,1 2,15V3A2,2 0 0,1 4,1H16V3H4V15H11V13L15,16L11,19V17M19,21V7H8V13H6V7A2,2 0 0,1 8,5H19A2,2 0 0,1 21,7V21A2,2 0 0,1 19,23H8A2,2 0 0,1 6,21V19H8V21H19Z",g=["state-badge","state-icon","state-label","action-button","icon","image","conditional"];(0,n.Z)([(0,a.Mo)("hui-picture-elements-card-row-editor")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[(0,a.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,a.Cb)({attribute:!1})],key:"elements",value:void 0},{kind:"field",decorators:[(0,a.IO)("ha-select")],key:"_select",value:void 0},{kind:"method",key:"render",value:function(){return this.elements&&this.hass?s.dy` <h3> ${this.hass.localize("ui.panel.lovelace.editor.card.picture-elements.elements")} </h3> <div class="elements"> ${this.elements.map(((e,t)=>s.dy` <div class="element"> ${e.type?s.dy` <div class="element-row"> <div> <span> ${this.hass?.localize(`ui.panel.lovelace.editor.card.picture-elements.element_types.${e.type}`)||e.type} </span> <span class="secondary">${this._getSecondaryDescription(e)}</span> </div> </div> `:s.Ld} <ha-icon-button .label="${this.hass.localize("ui.common.delete")}" .path="${u}" class="remove-icon" .index="${t}" @click="${this._removeRow}"></ha-icon-button> <ha-icon-button .label="${this.hass.localize("ui.common.edit")}" .path="${m}" class="edit-icon" .index="${t}" @click="${this._editRow}"></ha-icon-button> <ha-icon-button .label="${this.hass.localize("ui.common.duplicate")}" .path="${f}" class="duplicate-icon" .index="${t}" @click="${this._duplicateRow}"></ha-icon-button> </div> `))} <ha-select fixedMenuPosition naturalMenuWidth .label="${this.hass.localize("ui.panel.lovelace.editor.card.picture-elements.new_element")}" .value="${""}" @closed="${r.U}" @selected="${this._addElement}"> ${g.map((e=>s.dy` <mwc-list-item .value="${e}">${this.hass?.localize(`ui.panel.lovelace.editor.card.picture-elements.element_types.${e}`)}</mwc-list-item> `))} </ha-select> </div> `:s.Ld}},{kind:"method",key:"_getSecondaryDescription",value:function(e){switch(e.type){case"icon":return e.title??e.icon??"";case"state-badge":case"state-icon":case"state-label":return e.title??e.entity??"";case"action-button":case"service-button":return e.title??e.action??e.service??"";case"image":return e.title??e.image??e.camera_image??"";case"conditional":return e.title??`${(e.elements||[]).length.toString()} ${this.hass?.localize("ui.panel.lovelace.editor.card.picture-elements.elements")}`}return e.title??"Unknown type"}},{kind:"method",key:"_addElement",value:async function(e){const t=e.target.value;if(""===t)return;const i=this.elements.concat(await(0,c.L)(this.hass,t,Object.keys(this.hass.entities),[]));(0,l.B)(this,"elements-changed",{elements:i}),this._select.select(-1)}},{kind:"method",key:"_removeRow",value:function(e){const t=e.currentTarget.index,i=this.elements?.[t];i&&(0,d.showConfirmationDialog)(this,{text:this.hass.localize("ui.panel.lovelace.editor.card.picture-elements.confirm_delete_element",{type:this.hass.localize(`ui.panel.lovelace.editor.card.picture-elements.element_types.${i.type}`)||i.type}),confirmText:this.hass.localize("ui.common.delete"),destructive:!0,confirm:()=>{const e=this.elements.concat();e.splice(t,1),(0,l.B)(this,"elements-changed",{elements:e})}})}},{kind:"method",key:"_editRow",value:function(e){const t=e.currentTarget.index;(0,l.B)(this,"edit-detail-element",{subElementConfig:{index:t,type:"element",elementConfig:this.elements[t]}})}},{kind:"method",key:"_duplicateRow",value:function(e){const t=e.currentTarget.index,i=[...this.elements,(0,o.Z)(this.elements[t])];(0,l.B)(this,"elements-changed",{elements:i})}},{kind:"field",static:!0,key:"styles",value:()=>s.iv`.element{display:flex;align-items:center}.element-row{height:60px;font-size:16px;display:flex;align-items:center;justify-content:space-between;flex-grow:1}.element-row div{display:flex;flex-direction:column}.duplicate-icon,.edit-icon,.remove-icon{--mdc-icon-button-size:36px;color:var(--secondary-text-color)}.secondary{font-size:12px;color:var(--secondary-text-color)}ha-select{width:100%}`}]}}),s.oi);t()}catch(e){t(e)}}))},6973:function(e,t,i){i.a(e,(async function(e,n){try{i.d(t,{k:()=>d});var o=i(44249),s=i(72621),a=i(15093),l=i(43299),r=e([l]);l=(r.then?(await r)():r)[0];let d=(0,o.Z)(null,(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[(0,a.SB)()],key:"_configElementType",value:void 0},{kind:"get",key:"configElementType",value:function(){return this.value?this.value.type:void 0}},{kind:"method",key:"loadConfigElement",value:async function(){if(this._configElementType!==this.configElementType){if(this.unloadConfigElement(),!this.configElementType)throw new Error(this.hass.localize("ui.errors.config.no_type_provided"));this._configElementType=this.configElementType}return(0,s.Z)(i,"loadConfigElement",this,3)([])}}]}}),l.O);n()}catch(e){n(e)}}))},67064:function(e,t,i){i.d(t,{F:()=>l});var n=i(2841),o=i(45779),s=i(53232);const a=e=>(0,s.dZ)(e)?e._$litType$.h:e.strings,l=(0,o.XM)(class extends o.Xe{constructor(e){super(e),this.tt=new WeakMap}render(e){return[e]}update(e,[t]){const i=(0,s.hN)(this.et)?a(this.et):null,o=(0,s.hN)(t)?a(t):null;if(null!==i&&(null===o||i!==o)){const t=(0,s.i9)(e).pop();let o=this.tt.get(i);if(void 0===o){const e=document.createDocumentFragment();o=(0,n.sY)(n.Ld,e),o.setConnected(!1),this.tt.set(i,o)}(0,s.hl)(o,[t]),(0,s._Y)(o,void 0,t)}if(null!==o){if(null===i||i!==o){const t=this.tt.get(o);if(void 0!==t){const i=(0,s.i9)(t).pop();(0,s.E_)(e),(0,s._Y)(e,void 0,i),(0,s.hl)(e,[i])}}this.et=t}else this.et=void 0;return this.render(t)}})}}; //# sourceMappingURL=37008.0b9a9de9734c0a19.js.map