iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 6.86 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[72556],{12615:function(s,t,e){e.a(s,async function(s,i){try{e.r(t);e(18111),e(61701),e(3362),e(62953);var r=e(40445),o=e(5124),a=e(67576),n=e(1087),c=e(18350),p=(e(93444),e(65829)),h=e(91485),d=e(36312),_=e(38962),l=e(72554),u=(e(67094),e(31420)),g=e(30884),y=e(95350),b=e(14503),k=s([c,p,h,_,l,u]);[c,p,h,_,l,u]=k.then?(await k)():k;let f,m,v,w,$,C,E,z,D,q,P,x,A=s=>s;const B={encryption_key_type:"config",custom_encryption_key:""},I=["confirm","encryption","progress"];class K extends o.WF{async showDialog(s){var t;this._params=s,this._formData=B,this._userPassword=void 0,this._usedUserInput=!1,this._error=void 0,this._state=void 0,this._stage=void 0;const e=Object.keys(this._params.backup.agents),i=(0,u.EB)(e);(null===(t=this._params.backup.agents[i])||void 0===t?void 0:t.protected)?(this._backupEncryptionKey=await this._fetchEncryptionKey(),this._backupEncryptionKey?this._step=I[0]:this._step=I[1]):this._step=I[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(0,o.qy)(f||(f=A` <ha-dialog .open="${0}" header-title="${0}" ="${0}"> <div class="content"> ${0} </div> ${0} </ha-dialog> `),this._open,s,this._dialogClosed,this._error?(0,o.qy)(m||(m=A`<ha-alert alert-type="error">${0}</ha-alert>`),this._error):"confirm"===this._step?this._renderConfirm():"encryption"===this._step?this._renderEncryption():this._renderProgress(),this._error?(0,o.qy)(v||(v=A` <ha-dialog-footer slot="footer"> <ha-button slot="primaryAction" ="${0}"> ${0} </ha-button> </ha-dialog-footer> `),this.closeDialog,this.hass.localize("ui.common.close")):"confirm"===this._step||"encryption"===this._step?this._renderConfirmActions():o.s6)}_renderConfirm(){return(0,o.qy)(w||(w=A` <p> ${0} </p> `),this.hass.localize("ui.panel.config.backup.dialogs.restore.confirm.description"))}_renderEncryptionIntro(){return this._usedUserInput?(0,o.qy)($||($=A` ${0} `),this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.incorrect_key")):this._backupEncryptionKey?(0,o.qy)(C||(C=A` ${0} ${0} `),this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.different_key"),this._params.selectedData.homeassistant_included?(0,o.qy)(E||(E=A` <ha-alert alert-type="warning"> ${0} </ha-alert> `),this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.warning")):o.s6):(0,o.qy)(z||(z=A` ${0} `),this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.description"))}_renderEncryption(){return(0,o.qy)(D||(D=A` ${0} <ha-input type="password" password-toggle autofocus ="${0}" .label="${0}" .value="${0}"></ha-input> `),this._renderEncryptionIntro(),this._passwordChanged,this.hass.localize("ui.panel.config.backup.dialogs.restore.encryption.input_label"),this._userPassword||"")}_renderConfirmActions(){return(0,o.qy)(q||(q=A` <ha-dialog-footer slot="footer"> <ha-button slot="secondaryAction" appearance="plain" ="${0}"> ${0} </ha-button> <ha-button slot="primaryAction" ="${0}" variant="danger"> ${0} </ha-button> </ha-dialog-footer> `),this.closeDialog,this.hass.localize("ui.common.cancel"),this._restoreBackup,this.hass.localize("ui.panel.config.backup.dialogs.restore.actions.restore"))}_renderProgress(){return(0,o.qy)(P||(P=A`<div class="centered"> <ha-spinner></ha-spinner> <p> ${0} </p> </div>`),this.hass.connected?this._restoreState():this.hass.localize("ui.panel.config.backup.dialogs.restore.progress.restarting"))}_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,d.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,d.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,(0,o.AH)(x||(x=A`.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})],K.prototype,"hass",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_step",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_params",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_formData",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_open",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_backupEncryptionKey",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_userPassword",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_usedUserInput",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_error",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_state",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_stage",void 0),(0,r.Cg)([(0,a.wk)()],K.prototype,"_unsub",void 0),K=(0,r.Cg)([(0,a.EM)("ha-dialog-restore-backup")],K),i()}catch(f){i(f)}})}}]);