UNPKG

iobroker.lovelace

Version:

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

1 lines 6.54 kB
export const __rspack_esm_id=72556;export const __rspack_esm_ids=[72556];export const __webpack_modules__={12615(s,t,e){e.a(s,async function(s,i){try{e.r(t);e(18111),e(61701);var r=e(62826),o=e(5124),a=e(22441),n=e(1087),c=e(18350),p=(e(93444),e(65829)),h=e(91485),_=e(36312),d=e(38962),l=e(72554),u=(e(67094),e(31420)),g=e(30884),y=e(95350),b=e(14503),k=s([c,p,h,d,l,u]);[c,p,h,d,l,u]=k.then?(await k)():k;const f={encryption_key_type:"config",custom_encryption_key:""},m=["confirm","encryption","progress"];class v extends o.WF{async showDialog(s){this._params=s,this._formData=f,this._userPassword=void 0,this._usedUserInput=!1,this._error=void 0,this._state=void 0,this._stage=void 0;const t=Object.keys(this._params.backup.agents),e=(0,u.EB)(t),i=this._params.backup.agents[e]?.protected;i?(this._backupEncryptionKey=await this._fetchEncryptionKey(),this._backupEncryptionKey?this._step=m[0]:this._step=m[1]):this._step=m[0],this._open=!0}closeDialog(){return this._open=!1,!0}_dialogClosed(){this._formData=void 0,this._params=void 0,this._backupEncryptionKey=void 0,this._userPassword=void 0,this._usedUserInput=!1,this._error=void 0,this._state=void 0,this._stage=void 0,this._step=void 0,this._unsubscribe(),this._open=!1,(0,n.r)(this,"dialog-closed",{dialog:this.localName})}async _fetchEncryptionKey(){try{const{config:s}=await(0,u.Xm)(this.hass);return s.create_backup.password||void 0}catch(s){return void console.error(s)}}render(){if(!this._step||!this._params||!this._formData)return o.s6;const s=this.hass.localize("ui.panel.config.backup.dialogs.restore.title");return o.qy` <ha-dialog .open="${this._open}" header-title="${s}" @closed="${this._dialogClosed}"> <div class="content"> ${this._error?o.qy`<ha-alert alert-type="error">${this._error}</ha-alert>`:"confirm"===this._step?this._renderConfirm():"encryption"===this._step?this._renderEncryption():this._renderProgress()} </div> ${this._error?o.qy` <ha-dialog-footer slot="footer"> <ha-button slot="primaryAction" @click="${this.closeDialog}"> ${this.hass.localize("ui.common.close")} </ha-button> </ha-dialog-footer> `:"confirm"===this._step||"encryption"===this._step?this._renderConfirmActions():o.s6} </ha-dialog> `}_renderConfirm(){return o.qy` <p> ${this.hass.localize("ui.panel.config.backup.dialogs.restore.confirm.description")} </p> `}_renderEncryptionIntro(){return this._usedUserInput?o.qy` ${this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.incorrect_key")} `:this._backupEncryptionKey?o.qy` ${this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.different_key")} ${this._params.selectedData.homeassistant_included?o.qy` <ha-alert alert-type="warning"> ${this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.warning")} </ha-alert> `:o.s6} `:o.qy` ${this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.description")} `}_renderEncryption(){return o.qy` ${this._renderEncryptionIntro()} <ha-input type="password" password-toggle autofocus @input="${this._passwordChanged}" .label="${this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.input_label")}" .value="${this._userPassword||""}"></ha-input> `}_renderConfirmActions(){return o.qy` <ha-dialog-footer slot="footer"> <ha-button slot="secondaryAction" appearance="plain" @click="${this.closeDialog}"> ${this.hass.localize("ui.common.cancel")} </ha-button> <ha-button slot="primaryAction" @click="${this._restoreBackup}" variant="danger"> ${this.hass.localize("ui.panel.config.backup.dialogs.restore.actions.restore")} </ha-button> </ha-dialog-footer> `}_renderProgress(){return o.qy`<div class="centered"> <ha-spinner></ha-spinner> <p> ${this.hass.connected?this._restoreState():this.hass.localize("ui.panel.config.backup.dialogs.restore.progress.restarting")} </p> </div>`}_passwordChanged(s){this._userPassword=s.target.value}async _restoreBackup(){this._unsubscribe(),this._state=void 0,this._stage=void 0,this._error=void 0;try{this._step="progress",this._subscribeBackupEvents(),await this._doRestoreBackup(this._userPassword||this._backupEncryptionKey)}catch(s){await this._unsubscribe(),"password_incorrect"===s.code?(this._error=void 0,this._userPassword&&(this._usedUserInput=!0),this._step="encryption"):this._error=s.message}}_subscribeBackupEvents(){this._unsub=(0,g.A)(this.hass,s=>{"agent_id"in s||("idle"===s.manager_state&&"in_progress"===this._state&&this.closeDialog(),"restore_backup"===s.manager_state&&(this._state=s.state,"completed"===s.state&&this.closeDialog(),"failed"===s.state&&(this._error=this.hass.localize("ui.panel.config.backup.dialogs.restore.restore_failed")),"in_progress"===s.state&&(this._stage=s.stage)))},async()=>!!(0,_.x)(this.hass.config,"backup")||(await(0,y.Ud)(this.hass,"backup")).integration_loaded)}_unsubscribe(){if(this._unsub){const s=this._unsub.then(s=>s());return this._unsub=void 0,s}}_restoreState(){return this._stage?this.hass.localize(`ui.panel.config.backup.overview.progress.description.restore_backup.${this._stage}`):this.hass.localize("ui.panel.config.backup.dialogs.restore.progress.restoring")}async _doRestoreBackup(s){if(!this._params)return;const t=Object.keys(this._params.backup.agents),e=(0,u.EB)(t),{addons:i,database_included:r,homeassistant_included:o,folders:a}=this._params.selectedData,n={backup_id:this._params.backup.backup_id,agent_id:e,password:s,restore_database:r,restore_homeassistant:o};(0,_.x)(this.hass.config,"hassio")&&(n.restore_addons=i.map(s=>s.slug),n.restore_folders=a),await(0,u.dH)(this.hass,n)}static get styles(){return[b.RF,b.nA,o.AH`.content p{margin:0 0 16px}.centered{display:flex;flex-direction:column;align-items:center}ha-spinner{margin-bottom:16px}ha-alert[alert-type=warning]{display:block;margin-top:16px}`]}constructor(...s){super(...s),this._open=!1,this._usedUserInput=!1}}(0,r.Cg)([(0,a.MZ)({attribute:!1})],v.prototype,"hass",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_step",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_params",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_formData",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_open",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_backupEncryptionKey",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_userPassword",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_usedUserInput",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_error",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_state",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_stage",void 0),(0,r.Cg)([(0,a.wk)()],v.prototype,"_unsub",void 0),v=(0,r.Cg)([(0,a.EM)("ha-dialog-restore-backup")],v),i()}catch(s){i(s)}})}};