iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 7.05 kB
JavaScript
export const __rspack_esm_id=98983;export const __rspack_esm_ids=[98983];export const __webpack_modules__={35930(t,e,o){o.a(t,async function(t,i){try{o.r(e);var s=o(62826),a=o(5124),r=o(22441),n=o(1087),c=o(38962),h=o(18350),p=o(72554),g=(o(93444),o(59241)),l=o(14503),d=o(16536),_=t([c,h,p,d]);[c,h,p,d]=_.then?(await _)():_;class y extends a.WF{showDialog(t){this._params=t,this._scope=t.scope,this._category=t.entityReg.categories[t.scope],this._error=void 0,this._open=!0}closeDialog(){this._open=!1}_dialogClosed(){this._error="",this._params=void 0,(0,n.r)(this,"dialog-closed",{dialog:this.localName})}render(){if(!this._params)return a.s6;const t=this._params.entityReg.categories[this._params.scope];return a.qy` <ha-dialog .open="${this._open}" header-title="${t?this.hass.localize("ui.panel.config.category.assign.edit"):this.hass.localize("ui.panel.config.category.assign.assign")}" ="${this._dialogClosed}"> ${this._error?a.qy`<ha-alert alert-type="error">${this._error}</ha-alert>`:""} <div class="form"> <ha-category-picker .hass="${this.hass}" .scope="${this._scope}" .label="${this.hass.localize("ui.components.category-picker.category")}" .value="${this._category}" -changed="${this._categoryChanged}" autofocus></ha-category-picker> </div> <ha-dialog-footer slot="footer"> <ha-button slot="secondaryAction" appearance="plain" ="${this.closeDialog}"> ${this.hass.localize("ui.common.cancel")} </ha-button> <ha-button slot="primaryAction" ="${this._updateEntry}" .disabled="${!!this._submitting}"> ${this.hass.localize("ui.common.save")} </ha-button> </ha-dialog-footer> </ha-dialog> `}_categoryChanged(t){t.detail.value||(this._category=void 0),this._category=t.detail.value}async _updateEntry(){this._submitting=!0,this._error=void 0;try{await(0,g.G_)(this.hass,this._params.entityReg.entity_id,{categories:{[this._scope]:this._category||null}}),this.closeDialog()}catch(t){this._error=t.message||this.hass.localize("ui.panel.config.category.assign.unknown_error")}finally{this._submitting=!1}}static get styles(){return[l.nA,a.AH`ha-icon-picker{display:block;margin-bottom:16px}`]}constructor(...t){super(...t),this._open=!1}}(0,s.Cg)([(0,r.MZ)({attribute:!1})],y.prototype,"hass",void 0),(0,s.Cg)([(0,r.wk)()],y.prototype,"_scope",void 0),(0,s.Cg)([(0,r.wk)()],y.prototype,"_category",void 0),(0,s.Cg)([(0,r.wk)()],y.prototype,"_error",void 0),(0,s.Cg)([(0,r.wk)()],y.prototype,"_params",void 0),(0,s.Cg)([(0,r.wk)()],y.prototype,"_submitting",void 0),(0,s.Cg)([(0,r.wk)()],y.prototype,"_open",void 0),y=(0,s.Cg)([(0,r.EM)("dialog-assign-category")],y),i()}catch(t){i(t)}})},16536(t,e,o){o.a(t,async function(t,e){try{o(74423),o(18111),o(22489),o(61701),o(13579),o(45367),o(92731),o(17642),o(58004),o(33853),o(45876),o(32475),o(15024),o(31698);var i=o(62826),s=o(5124),a=o(22441),r=o(22786),n=o(1087),c=o(38508),h=(o(67094),o(76570)),p=o(54706),g=o(90986),l=t([c]);c=(l.then?(await l)():l)[0];const d="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z",_="M5.5,7A1.5,1.5 0 0,1 4,5.5A1.5,1.5 0 0,1 5.5,4A1.5,1.5 0 0,1 7,5.5A1.5,1.5 0 0,1 5.5,7M21.41,11.58L12.41,2.58C12.05,2.22 11.55,2 11,2H4C2.89,2 2,2.89 2,4V11C2,11.55 2.22,12.05 2.59,12.41L11.58,21.41C11.95,21.77 12.45,22 13,22C13.55,22 14.05,21.77 14.41,21.41L21.41,14.41C21.78,14.05 22,13.55 22,13C22,12.44 21.77,11.94 21.41,11.58Z",y="___ADD_NEW___";class u extends((0,p.E)(s.WF)){willUpdate(t){this._pendingCategoryId&&t.has("_categories")&&this._categories?.some(t=>t.category_id===this._pendingCategoryId)&&(this._setValue(this._pendingCategoryId),this._pendingCategoryId=void 0)}async open(){await this.updateComplete,await(this._picker?.open())}hassSubscribe(){return[(0,h.Ar)(this.hass.connection,this.scope,t=>{this._categories=t})]}render(){const t=this._computeValueRenderer(this._categories);return s.qy` <ha-generic-picker .hass="${this.hass}" .autofocus="${this.autofocus}" .label="${this.label}" .placeholder="${this.placeholder}" .value="${this.value}" .notFoundLabel="${this._notFoundLabel}" .emptyLabel="${this.hass.localize("ui.components.category-picker.no_categories")}" .getItems="${this._getItems}" .getAdditionalItems="${this._getAdditionalItems}" .valueRenderer="${t}" .unknownItemText="${this.hass.localize("ui.components.category-picker.unknown")}" -changed="${this._valueChanged}"> </ha-generic-picker> `}_valueChanged(t){t.stopPropagation();const e=t.detail.value;if(e){if(e.startsWith(y)){this.hass.loadFragmentTranslation("config");const t=e.substring(y.length);return void(0,g.S)(this,{scope:this.scope,suggestedName:t,createEntry:async t=>{const e=await(0,h.s_)(this.hass,this.scope,t);return this._categories?.some(t=>t.category_id===e.category_id)?this._setValue(e.category_id):this._pendingCategoryId=e.category_id,e}})}this._setValue(e)}else this._setValue(void 0)}_setValue(t){this.value=t,setTimeout(()=>{(0,n.r)(this,"value-changed",{value:t}),(0,n.r)(this,"change")},0)}constructor(...t){super(...t),this.noAdd=!1,this.disabled=!1,this.required=!1,this.hassSubscribeRequiredHostProps=["scope"],this._categoryMap=(0,r.A)(t=>t?new Map(t.map(t=>[t.category_id,t])):new Map),this._computeValueRenderer=(0,r.A)(t=>e=>{const o=this._categoryMap(t).get(e);return o?s.qy` ${o.icon?s.qy`<ha-icon slot="start" .icon="${o.icon}"></ha-icon>`:s.qy`<ha-svg-icon slot="start" .path="${_}"></ha-svg-icon>`} <span slot="headline">${o.name}</span> `:s.qy` <ha-svg-icon slot="start" .path="${_}"></ha-svg-icon> <span slot="headline">${e}</span> `}),this._getCategories=(0,r.A)(t=>{if(!t)return;return t.map(t=>({id:t.category_id,primary:t.name,icon:t.icon||void 0,icon_path:t.icon?void 0:_,sorting_label:t.name}))}),this._getItems=()=>this._getCategories(this._categories),this._allCategoryNames=(0,r.A)(t=>t?[...new Set(t.map(t=>t.name.toLowerCase()).filter(Boolean))]:[]),this._getAdditionalItems=t=>{if(this.noAdd)return[];const e=this._allCategoryNames(this._categories);return t&&!e.includes(t.toLowerCase())?[{id:y+t,primary:this.hass.localize("ui.components.category-picker.add_new_suggestion",{name:t}),icon_path:d}]:[{id:y,primary:this.hass.localize("ui.components.category-picker.add_new"),icon_path:d}]},this._notFoundLabel=t=>this.hass.localize("ui.components.category-picker.no_match",{term:s.qy`<b>‘${t}’</b>`})}}(0,i.Cg)([(0,a.MZ)({attribute:!1})],u.prototype,"hass",void 0),(0,i.Cg)([(0,a.MZ)()],u.prototype,"scope",void 0),(0,i.Cg)([(0,a.MZ)()],u.prototype,"label",void 0),(0,i.Cg)([(0,a.MZ)()],u.prototype,"value",void 0),(0,i.Cg)([(0,a.MZ)()],u.prototype,"helper",void 0),(0,i.Cg)([(0,a.MZ)()],u.prototype,"placeholder",void 0),(0,i.Cg)([(0,a.MZ)({type:Boolean,attribute:"no-add"})],u.prototype,"noAdd",void 0),(0,i.Cg)([(0,a.MZ)({type:Boolean})],u.prototype,"disabled",void 0),(0,i.Cg)([(0,a.MZ)({type:Boolean})],u.prototype,"required",void 0),(0,i.Cg)([(0,a.wk)()],u.prototype,"_categories",void 0),(0,i.Cg)([(0,a.P)("ha-generic-picker")],u.prototype,"_picker",void 0),(0,i.Cg)([(0,a.wk)()],u.prototype,"_pendingCategoryId",void 0),u=(0,i.Cg)([(0,a.EM)("ha-category-picker")],u),e()}catch(t){e(t)}})}};